From 541eadcb1d93c3eafcf0bbb874b099940e6781e3 Mon Sep 17 00:00:00 2001 From: A248 Date: Fri, 18 Aug 2023 18:48:16 -0500 Subject: [PATCH] Fix failing test and add some more --- .../core/selector/SelectionBaseSQLTest.java | 12 +-- .../it/test/select/SelectionIT.java | 73 ++++++++++++++++++- 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/bans-core/src/test/java/space/arim/libertybans/core/selector/SelectionBaseSQLTest.java b/bans-core/src/test/java/space/arim/libertybans/core/selector/SelectionBaseSQLTest.java index f3dcaa603..ef468351b 100644 --- a/bans-core/src/test/java/space/arim/libertybans/core/selector/SelectionBaseSQLTest.java +++ b/bans-core/src/test/java/space/arim/libertybans/core/selector/SelectionBaseSQLTest.java @@ -68,9 +68,9 @@ public void optimizedApplicabilityQuery(AddressStrictness strictness) { private String expectedSql(AddressStrictness strictness) { return switch (strictness) { case LENIENT -> """ -select "libertybans_simple_bans"."victim_type", \ -"libertybans_simple_bans"."victim_uuid", "libertybans_simple_bans"."victim_address", \ -"libertybans_simple_bans"."operator", "libertybans_simple_bans"."reason", "libertybans_simple_bans"."scope", \ +select "libertybans_simple_bans"."victim_type", "libertybans_simple_bans"."victim_uuid", \ +"libertybans_simple_bans"."victim_address", "libertybans_simple_bans"."operator", \ +"libertybans_simple_bans"."reason", "libertybans_simple_bans"."scope_type", "libertybans_simple_bans"."scope", \ "libertybans_simple_bans"."start", "libertybans_simple_bans"."end", "libertybans_simple_bans"."track", \ "libertybans_simple_bans"."id" \ from "libertybans_simple_bans" where \ @@ -86,7 +86,7 @@ private String expectedSql(AddressStrictness strictness) { select "libertybans_applicable_bans"."victim_type", \ "libertybans_applicable_bans"."victim_uuid", "libertybans_applicable_bans"."victim_address", \ "libertybans_applicable_bans"."operator", "libertybans_applicable_bans"."reason", \ -"libertybans_applicable_bans"."scope", "libertybans_applicable_bans"."start", \ +"libertybans_applicable_bans"."scope_type", "libertybans_applicable_bans"."scope", "libertybans_applicable_bans"."start", \ "libertybans_applicable_bans"."end", "libertybans_applicable_bans"."track", "libertybans_applicable_bans"."id" \ from "libertybans_applicable_bans" where \ (("libertybans_applicable_bans"."end" = 0 or "libertybans_applicable_bans"."end" > cast(? as bigint)) \ @@ -98,7 +98,7 @@ private String expectedSql(AddressStrictness strictness) { select "libertybans_applicable_bans"."victim_type", \ "libertybans_applicable_bans"."victim_uuid", "libertybans_applicable_bans"."victim_address", \ "libertybans_applicable_bans"."operator", "libertybans_applicable_bans"."reason", \ -"libertybans_applicable_bans"."scope", "libertybans_applicable_bans"."start", \ +"libertybans_applicable_bans"."scope_type", "libertybans_applicable_bans"."scope", "libertybans_applicable_bans"."start", \ "libertybans_applicable_bans"."end", "libertybans_applicable_bans"."track", "libertybans_applicable_bans"."id" \ from "libertybans_applicable_bans" \ join "libertybans_strict_links" on "libertybans_applicable_bans"."uuid" = "libertybans_strict_links"."uuid1" \ @@ -112,7 +112,7 @@ private String expectedSql(AddressStrictness strictness) { select "libertybans_applicable_bans"."victim_type", \ "libertybans_applicable_bans"."victim_uuid", "libertybans_applicable_bans"."victim_address", \ "libertybans_applicable_bans"."operator", "libertybans_applicable_bans"."reason", \ -"libertybans_applicable_bans"."scope", "libertybans_applicable_bans"."start", \ +"libertybans_applicable_bans"."scope_type", "libertybans_applicable_bans"."scope", "libertybans_applicable_bans"."start", \ "libertybans_applicable_bans"."end", "libertybans_applicable_bans"."track", "libertybans_applicable_bans"."id" \ from "libertybans_applicable_bans" \ join "libertybans_strict_links" on "libertybans_applicable_bans"."uuid" = "libertybans_strict_links"."uuid1" \ diff --git a/bans-core/src/test/java/space/arim/libertybans/it/test/select/SelectionIT.java b/bans-core/src/test/java/space/arim/libertybans/it/test/select/SelectionIT.java index 0035817d8..cb4c44357 100644 --- a/bans-core/src/test/java/space/arim/libertybans/it/test/select/SelectionIT.java +++ b/bans-core/src/test/java/space/arim/libertybans/it/test/select/SelectionIT.java @@ -33,6 +33,7 @@ import space.arim.libertybans.api.punish.Punishment; import space.arim.libertybans.api.punish.PunishmentDrafter; import space.arim.libertybans.api.scope.ScopeManager; +import space.arim.libertybans.api.scope.ServerScope; import space.arim.libertybans.api.select.PunishmentSelector; import space.arim.libertybans.api.select.SelectionOrderBuilder; import space.arim.libertybans.api.select.SelectionPredicate; @@ -57,6 +58,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static space.arim.libertybans.api.select.SelectionPredicate.matchingNone; @ExtendWith(InjectionInvocationContextProvider.class) @ExtendWith({RandomPunishmentTypeResolver.class, RandomOperatorResolver.class, RandomVictimResolver.class}) @@ -247,7 +249,7 @@ public void selectVictimsBySelfOrType() { assertEquals( List.of(banAddress1, muteAddress2), getPunishments(selector.selectionBuilder().victimTypes( - SelectionPredicate.matchingNone(Victim.VictimType.PLAYER) + matchingNone(Victim.VictimType.PLAYER) )), "Should be identical to previous assertion"); assertEquals( @@ -261,7 +263,7 @@ public void selectVictimsBySelfOrType() { getPunishments(selector.selectionBuilder().victims(SelectionPredicate.matchingAnyOf(uuid2, address1)))); assertEquals( List.of(warnUuid2, banAddress1), - getPunishments(selector.selectionBuilder().victims(SelectionPredicate.matchingNone(uuid1, address2))), + getPunishments(selector.selectionBuilder().victims(matchingNone(uuid1, address2))), "Should be identical to previous assertion (in context)"); } @@ -330,4 +332,71 @@ public void selectByTrackOrItsInexistence() { ))); } + @TestTemplate + public void selectScopes(@DontInject Victim victim1, @DontInject Victim victim2, @DontInject Victim victim3) { + ServerScope globalScope = scopeManager.globalScope(); + ServerScope kitpvpScope = scopeManager.specificScope("kitpvp"); + ServerScope tntpvpScope = scopeManager.specificScope("tntpvp"); + ServerScope pvpScope = scopeManager.category("pvp"); + ServerScope creativeServerScope = scopeManager.specificScope("creative"); + ServerScope creativeCategoryScope = scopeManager.category("creative"); + + Punishment banGlobal = getPunishment( + draftBuilder(PunishmentType.BAN, victim1, "global ban")); + + Punishment muteKitpvp = getPunishment( + draftBuilder(PunishmentType.MUTE, victim1, "mute on kitpvp").scope(kitpvpScope)); + Punishment warnKitpvp = getPunishment( + draftBuilder(PunishmentType.WARN, victim2, "warn on kitpvp").scope(kitpvpScope)); + Punishment warnTntpvp = getPunishment( + draftBuilder(PunishmentType.WARN, victim2, "warn on tntpvp").scope(tntpvpScope)); + Punishment banPvp = getPunishment( + draftBuilder(PunishmentType.BAN, victim2, "banned on pvp servers").scope(pvpScope)); + + Punishment muteCreativeServer = getPunishment( + draftBuilder(PunishmentType.MUTE, victim2, "mute on creative server").scope(creativeServerScope)); + Punishment muteCreativeCategory = getPunishment( + draftBuilder(PunishmentType.MUTE, victim3, "mute on creative category").scope(creativeCategoryScope)); + + assertEmpty(selector.selectionBuilder().selectAll().scope(scopeManager.specificScope("nonexistent"))); + assertEmpty(selector.selectionBuilder().selectAll().scope(scopeManager.category("nonexistent"))); + + assertEquals( + List.of(banGlobal, muteKitpvp, warnKitpvp, warnTntpvp, banPvp, muteCreativeServer, muteCreativeCategory), + getPunishments(selector.selectionBuilder()) + ); + assertEquals( + List.of(banGlobal, muteKitpvp), + getPunishments(selector.selectionBuilder().victim(victim1)) + ); + assertEquals( + List.of(muteKitpvp, warnKitpvp, warnTntpvp, banPvp, muteCreativeServer, muteCreativeCategory), + getPunishments(selector.selectionBuilder().scopes(matchingNone(globalScope))) + ); + assertEquals( + List.of(banGlobal), + getPunishments(selector.selectionBuilder().scope(globalScope)) + ); + assertEquals( + List.of(muteKitpvp, warnKitpvp), + getPunishments(selector.selectionBuilder().scope(kitpvpScope)) + ); + assertEquals( + List.of(warnTntpvp), + getPunishments(selector.selectionBuilder().scope(tntpvpScope)) + ); + assertEquals( + List.of(banPvp), + getPunishments(selector.selectionBuilder().scope(pvpScope)) + ); + assertEquals( + List.of(muteCreativeServer), + getPunishments(selector.selectionBuilder().scope(creativeServerScope)) + ); + assertEquals( + List.of(muteCreativeCategory), + getPunishments(selector.selectionBuilder().scope(creativeCategoryScope)) + ); + } + }