From fd51b178273b056a7b0c7f89be854d75aaef1ef2 Mon Sep 17 00:00:00 2001 From: Ben Hook <5009589+benhook1013@users.noreply.github.com> Date: Sat, 24 Oct 2026 05:12:53 +1300 Subject: [PATCH] test(game-session): share explicit gameplay identity scenarios --- ...ommunicationWebSocketCrossServiceTest.java | 26 +-- ...mmandHistoryRepositoryIntegrationTest.java | 9 +- .../text/ActionStateCommandHandlerTest.java | 4 +- ...dActionTextCommandDispatchHandlerTest.java | 4 +- .../text/ContainerCommandHandlerTest.java | 5 +- .../text/EquipmentCommandHandlerTest.java | 5 +- .../command/text/HelpCommandHandlerTest.java | 21 +-- .../HelpTextCommandDispatchHandlerTest.java | 5 +- .../text/HistoryCommandHandlerTest.java | 25 ++- ...HistoryTextCommandDispatchHandlerTest.java | 8 +- .../text/InventoryCommandHandlerTest.java | 5 +- .../command/text/ItemCommandHandlerTest.java | 5 +- .../text/StatusCommandHandlerTest.java | 5 +- .../TextCommandInterpreterCapabilityTest.java | 9 +- .../command/text/WhoCommandHandlerTest.java | 29 ++-- .../text/WorldsCommandHandlerTest.java | 17 +- .../WorldsTextCommandDispatchHandlerTest.java | 13 +- ...iveCommandHistorySettingsResolverTest.java | 7 +- ...ctiveReconnectionSettingsResolverTest.java | 11 +- .../config/EffectiveSettingsResolverTest.java | 4 +- .../EffectiveSettingsControllerTest.java | 5 +- ...unicationRecipientDeliveryServiceTest.java | 47 ++--- .../GameplayPresenceActivityResolverTest.java | 80 +-------- ...erCommandHistoryRetentionSweepJobTest.java | 40 +++-- ...layerCommandHistoryStorageServiceTest.java | 31 ++-- .../PlayerOutputDeliveryServiceTest.java | 3 +- ...leGameplayCommandExecutionServiceTest.java | 60 ++----- .../impl/GameAuthoredHelpReaderImplTest.java | 4 +- .../test/ChatTestFixturesTest.java | 58 +++++++ .../test/GameplayCommandTestFixturesTest.java | 162 ++++++++++++++++++ .../GameSessionWebSocketHandlerTest.java | 31 +--- .../WebSocketOutputProjectorTest.java | 5 +- .../gamesession/test/ChatTestFixtures.java | 41 ++++- .../test/GameplayCommandTestFixtures.java | 89 ++++++++++ .../test/GameplayHistoryTestFixtures.java | 33 ++++ .../test/GameplayPresenceTestFixtures.java | 48 ++++++ 36 files changed, 606 insertions(+), 348 deletions(-) create mode 100644 services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/test/ChatTestFixturesTest.java create mode 100644 services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/test/GameplayCommandTestFixturesTest.java create mode 100644 services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/GameplayCommandTestFixtures.java create mode 100644 services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/GameplayHistoryTestFixtures.java create mode 100644 services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/GameplayPresenceTestFixtures.java diff --git a/services/game-session-service/src/test/java/crossservice/net/firedevops/firemud/gamesession/CommunicationWebSocketCrossServiceTest.java b/services/game-session-service/src/test/java/crossservice/net/firedevops/firemud/gamesession/CommunicationWebSocketCrossServiceTest.java index a54e968317..d3c258a44b 100644 --- a/services/game-session-service/src/test/java/crossservice/net/firedevops/firemud/gamesession/CommunicationWebSocketCrossServiceTest.java +++ b/services/game-session-service/src/test/java/crossservice/net/firedevops/firemud/gamesession/CommunicationWebSocketCrossServiceTest.java @@ -36,9 +36,9 @@ class CommunicationWebSocketCrossServiceTest { private static final Duration COMMAND_WAIT = Duration.ofSeconds(45); private static final long TENANT_ID = 1L; - private static final long ACCOUNT_ID = Long.parseLong(ChatTestFixtures.PLAYER_EMBERLINE); - private static final long SORA_ACCOUNT_ID = Long.parseLong(ChatTestFixtures.PLAYER_SORA); - private static final long NYX_ACCOUNT_ID = Long.parseLong(ChatTestFixtures.PLAYER_NYX); + private static final long ACCOUNT_ID = ChatTestFixtures.EMBERLINE_ACCOUNT_ROW_ID; + private static final long SORA_ACCOUNT_ID = ChatTestFixtures.SORA_ACCOUNT_ROW_ID; + private static final long NYX_ACCOUNT_ID = ChatTestFixtures.NYX_ACCOUNT_ROW_ID; private static final long DEMO_WORLD_INSTANCE_ID = 1L; private static final String READY_LOOK_TEXT = "Candle-lit Antechamber"; @@ -664,9 +664,9 @@ private long prepareGameInstance() { DEMO_WORLD_INSTANCE_ID, ACCOUNT_ID, 7L, - ACCOUNT_ID, - Long.parseLong(ChatTestFixtures.PLAYER_SORA), - Long.parseLong(ChatTestFixtures.PLAYER_NYX)); + ChatTestFixtures.EMBERLINE_CHARACTER_ID, + ChatTestFixtures.SORA_CHARACTER_ID, + ChatTestFixtures.NYX_CHARACTER_ID); } private static String truncateGuardState(JdbcTemplate jdbc, BaselineTruncateGuard guard) { @@ -719,19 +719,7 @@ private static SQLException mostSpecificSqlException(Throwable failure) { private void seedLiveTargetSession() { STACK.seedLiveSession( - 90210L, - TENANT_ID, - Long.parseLong(ChatTestFixtures.PLAYER_SORA), - "sora@example.com", - Long.parseLong(ChatTestFixtures.PLAYER_SORA), - "Sora", - DEMO_WORLD_INSTANCE_ID, - ChatTestFixtures.ROOM_ID, - "target-jwt", - "demo", - "production", - 1L, - "SHARED"); + ChatTestFixtures.soraRecipientSession(90210L, TENANT_ID, DEMO_WORLD_INSTANCE_ID)); } private List runCommunicationSequence( diff --git a/services/game-session-service/src/test/java/integration/net/firedevops/firemud/gamesession/repository/PlayerCommandHistoryRepositoryIntegrationTest.java b/services/game-session-service/src/test/java/integration/net/firedevops/firemud/gamesession/repository/PlayerCommandHistoryRepositoryIntegrationTest.java index c44590751a..449ce465c6 100644 --- a/services/game-session-service/src/test/java/integration/net/firedevops/firemud/gamesession/repository/PlayerCommandHistoryRepositoryIntegrationTest.java +++ b/services/game-session-service/src/test/java/integration/net/firedevops/firemud/gamesession/repository/PlayerCommandHistoryRepositoryIntegrationTest.java @@ -11,6 +11,7 @@ import java.util.concurrent.TimeUnit; import net.firedevops.firemud.gamesession.entity.PlayerCommandHistoryEntry; import net.firedevops.firemud.gamesession.service.PlayerCommandHistoryStorageService; +import net.firedevops.firemud.gamesession.test.GameplayHistoryTestFixtures; import net.firedevops.firemud.test.TestContainerImages; import org.flywaydb.core.Flyway; import org.jooq.DSLContext; @@ -214,12 +215,6 @@ private PlayerCommandHistoryStorageService transactionalStorageService( } private PlayerCommandHistoryEntry historyEntry(String commandText, Instant acceptedAt) { - PlayerCommandHistoryEntry entry = new PlayerCommandHistoryEntry(); - entry.setTenantId(22L); - entry.setGameInstanceId(7L); - entry.setCharacterId(13L); - entry.setCommandText(commandText); - entry.setAcceptedAt(acceptedAt); - return entry; + return GameplayHistoryTestFixtures.retainedCommand(commandText, acceptedAt); } } diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/ActionStateCommandHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/ActionStateCommandHandlerTest.java index ed4c0ccc78..0725deb627 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/ActionStateCommandHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/ActionStateCommandHandlerTest.java @@ -13,6 +13,7 @@ import net.firedevops.firemud.entitymanagement.v1.ApplyActorConditionResponse; import net.firedevops.firemud.gamesession.client.GameLogicClient; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -21,8 +22,7 @@ class ActionStateCommandHandlerTest { private final GameLogicClient gameLogicClient = Mockito.mock(GameLogicClient.class); private final ActionStateCommandHandler handler = new ActionStateCommandHandler(gameLogicClient, Clock.fixed(NOW, ZoneOffset.UTC)); - private final SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + private final SessionContext context = GameplayCommandTestFixtures.durableDemo(); @Test void blockAppliesShortLivedBlockingState() { diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/AuthoredActionTextCommandDispatchHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/AuthoredActionTextCommandDispatchHandlerTest.java index c7b2dc90e6..cf6a3a5a6c 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/AuthoredActionTextCommandDispatchHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/AuthoredActionTextCommandDispatchHandlerTest.java @@ -11,6 +11,7 @@ import net.firedevops.firemud.gamesession.service.AuthoredCommandAdmission; import net.firedevops.firemud.gamesession.service.CommandService; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -86,8 +87,7 @@ void rejectsAuthoredActionsWithoutGameplayContext() { } private static SessionContext context() { - return new SessionContext( - 7L, 22L, "41", "emberline@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + return GameplayCommandTestFixtures.authoredDispatchEmberline(); } private static TextCommand authoredAction(String commandId, String rawLine, List args) { diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/ContainerCommandHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/ContainerCommandHandlerTest.java index da1de2c984..60dff4a799 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/ContainerCommandHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/ContainerCommandHandlerTest.java @@ -18,15 +18,14 @@ import net.firedevops.firemud.gamesession.presentation.ItemMutationResultOutput; import net.firedevops.firemud.gamesession.presentation.PlayerOutputKind; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; class ContainerCommandHandlerTest { private final GameLogicClient gameLogicClient = Mockito.mock(GameLogicClient.class); private final ContainerCommandHandler handler = new ContainerCommandHandler(gameLogicClient); - private final SessionContext context = - new SessionContext( - 1L, 22L, "123", "emberline@example.com", 911L, "Emberline", 77L, "R-7", "jwt-token"); + private final SessionContext context = GameplayCommandTestFixtures.inventoryEmberline(); @Test void containerViewReturnsStructuredContents() { diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/EquipmentCommandHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/EquipmentCommandHandlerTest.java index 649c86ac1e..3b5c676a3d 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/EquipmentCommandHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/EquipmentCommandHandlerTest.java @@ -15,6 +15,7 @@ import net.firedevops.firemud.gamesession.presentation.ItemMutationResultOutput; import net.firedevops.firemud.gamesession.presentation.PlayerOutputKind; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import net.firedevops.firemud.shared.v1.ErrorDetail; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -22,9 +23,7 @@ class EquipmentCommandHandlerTest { private final GameLogicClient gameLogicClient = Mockito.mock(GameLogicClient.class); private final EquipmentCommandHandler handler = new EquipmentCommandHandler(gameLogicClient); - private final SessionContext context = - new SessionContext( - 1L, 22L, "123", "emberline@example.com", 911L, "Emberline", 77L, "R-7", "jwt-token"); + private final SessionContext context = GameplayCommandTestFixtures.inventoryEmberline(); @Test void wearWithoutItemReferenceFailsFast() { diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HelpCommandHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HelpCommandHandlerTest.java index 728f673e5f..ae25eae28e 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HelpCommandHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HelpCommandHandlerTest.java @@ -11,6 +11,7 @@ import net.firedevops.firemud.common.settings.ScopedSettingsSnapshot; import net.firedevops.firemud.gamesession.service.GameAuthoredHelpReader; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; class HelpCommandHandlerTest { @@ -223,9 +224,7 @@ void helpIndexHidesHistoryWhenFeatureDisabled() { HelpCommandHandler disabledHandler = new HelpCommandHandler( (context, topic) -> Optional.empty(), null, capabilitiesResolver(false)); - SessionContext context = - new SessionContext( - 42L, 22L, "123", "emberline@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + SessionContext context = GameplayCommandTestFixtures.helpCapabilityEmberline(); TextCommandInterpretationResult result = disabledHandler.handle( @@ -242,9 +241,7 @@ void helpIndexHidesEveryDisabledStandardCapabilityFamily() { (context, topic) -> Optional.empty(), null, CommandCapabilitiesTestSupport.resolver(false, false, false, true)); - SessionContext context = - new SessionContext( - 42L, 22L, "123", "emberline@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + SessionContext context = GameplayCommandTestFixtures.helpCapabilityEmberline(); TextCommandInterpretationResult result = disabledHandler.handle( @@ -262,9 +259,7 @@ void helpHistoryTopicUnavailableWhenFeatureDisabled() { HelpCommandHandler disabledHandler = new HelpCommandHandler( (context, topic) -> Optional.empty(), null, capabilitiesResolver(false)); - SessionContext context = - new SessionContext( - 42L, 22L, "123", "emberline@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + SessionContext context = GameplayCommandTestFixtures.helpCapabilityEmberline(); TextCommandInterpretationResult result = disabledHandler.handle( @@ -280,9 +275,7 @@ void helpHistoryTopicAvailableWhenFeatureEnabled() { HelpCommandHandler enabledHandler = new HelpCommandHandler( (context, topic) -> Optional.empty(), null, capabilitiesResolver(true)); - SessionContext context = - new SessionContext( - 42L, 22L, "123", "emberline@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + SessionContext context = GameplayCommandTestFixtures.helpCapabilityEmberline(); TextCommandInterpretationResult result = enabledHandler.handle( @@ -303,9 +296,7 @@ void publishedGameAuthoredTopicOverridesPlatformTopicForAdmittedSession() { "Temple Etiquette", "Bow before entering the moonlit sanctuary.")) : Optional.empty(); HelpCommandHandler authoredHelpHandler = new HelpCommandHandler(reader, null, null); - SessionContext context = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 7001L, "Emberline", 7L, "R-1", "jwt"); + SessionContext context = GameplayCommandTestFixtures.authoredHelpEmberline(); TextCommandInterpretationResult result = authoredHelpHandler.handle( diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HelpTextCommandDispatchHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HelpTextCommandDispatchHandlerTest.java index 1ad2d47676..d04e27eebb 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HelpTextCommandDispatchHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HelpTextCommandDispatchHandlerTest.java @@ -6,6 +6,7 @@ import java.util.Optional; import net.firedevops.firemud.gamesession.service.ScriptEventPublisher; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -18,9 +19,7 @@ class HelpTextCommandDispatchHandlerTest { @Test void publishesCommandEventForGameplayScopedHelp() { - SessionContext context = - new SessionContext( - 7L, 22L, "41", "emberline@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + SessionContext context = GameplayCommandTestFixtures.authoredDispatchEmberline(); TextCommandInterpretationResult result = handler.handle( diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HistoryCommandHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HistoryCommandHandlerTest.java index 5f5db10d8d..c96f3a73e5 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HistoryCommandHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HistoryCommandHandlerTest.java @@ -12,6 +12,7 @@ import net.firedevops.firemud.gamesession.config.EffectiveCommandHistorySettingsResolver; import net.firedevops.firemud.gamesession.service.PlayerCommandHistoryStorageService; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -39,7 +40,10 @@ void returnsNoRecentCommandsWhenHistoryIsEmpty() { PlayerCommandHistoryStorageService storage = Mockito.mock(PlayerCommandHistoryStorageService.class); HistoryCommandHandler handler = handler(storage, 10, true); - Mockito.when(storage.findRecent(7L, 9L, 7001L, 10)).thenReturn(List.of()); + Mockito.when( + storage.findRecent( + 7L, 9L, GameplayCommandTestFixtures.historyEmberline().characterId(), 10)) + .thenReturn(List.of()); SessionContext context = standardContext(); @@ -55,7 +59,10 @@ void defaultsToConfiguredMaxWhenCountIsOmitted() { PlayerCommandHistoryStorageService storage = Mockito.mock(PlayerCommandHistoryStorageService.class); HistoryCommandHandler handler = handler(storage, 2, true); - Mockito.when(storage.findRecent(7L, 9L, 7001L, 2)).thenReturn(List.of("LOOK", "SAY hi")); + Mockito.when( + storage.findRecent( + 7L, 9L, GameplayCommandTestFixtures.historyEmberline().characterId(), 2)) + .thenReturn(List.of("LOOK", "SAY hi")); SessionContext context = standardContext(); @@ -71,7 +78,9 @@ void usesExplicitCountAndReturnsChronologicalEntries() { PlayerCommandHistoryStorageService storage = Mockito.mock(PlayerCommandHistoryStorageService.class); HistoryCommandHandler handler = handler(storage, 10, true); - Mockito.when(storage.findRecent(7L, 9L, 7001L, 5)) + Mockito.when( + storage.findRecent( + 7L, 9L, GameplayCommandTestFixtures.historyEmberline().characterId(), 5)) .thenReturn(List.of("LOOK", "SAY hello", "INVENTORY")); SessionContext context = standardContext(); @@ -87,7 +96,8 @@ void usesExplicitCountAndReturnsChronologicalEntries() { assertTrue(result.commandResult().accepted()); assertEquals("LOOK\nSAY hello\nINVENTORY", result.outputs().get(0).text()); - Mockito.verify(storage).findRecent(7L, 9L, 7001L, 5); + Mockito.verify(storage) + .findRecent(7L, 9L, GameplayCommandTestFixtures.historyEmberline().characterId(), 5); } @Test @@ -113,7 +123,9 @@ void returnsUnavailableWhenSettingsResolutionFails() { void returnsUnavailableWhenHistoryStorageReadFails() { PlayerCommandHistoryStorageService storage = Mockito.mock(PlayerCommandHistoryStorageService.class); - Mockito.when(storage.findRecent(7L, 9L, 7001L, 10)) + Mockito.when( + storage.findRecent( + 7L, 9L, GameplayCommandTestFixtures.historyEmberline().characterId(), 10)) .thenThrow(new IllegalStateException("storage unavailable")); HistoryCommandHandler handler = handler(storage, 10, true); @@ -192,8 +204,7 @@ void rejectsNonPositiveHistoryCountWithoutReadingStorage() { } private SessionContext standardContext() { - return new SessionContext( - 22L, 7L, "99", "demo@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + return GameplayCommandTestFixtures.historyEmberline(); } private HistoryCommandHandler handler( diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HistoryTextCommandDispatchHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HistoryTextCommandDispatchHandlerTest.java index 8534846196..90375533e2 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HistoryTextCommandDispatchHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/HistoryTextCommandDispatchHandlerTest.java @@ -10,6 +10,7 @@ import net.firedevops.firemud.gamesession.presentation.PlayerOutput; import net.firedevops.firemud.gamesession.service.PlayerCommandHistoryStorageService; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -28,10 +29,11 @@ class HistoryTextCommandDispatchHandlerTest { @Test void dispatchesToHistoryHandler() { - Mockito.when(historyStorageService.findRecent(7L, 9L, 7001L, 2)) + Mockito.when( + historyStorageService.findRecent( + 7L, 9L, GameplayCommandTestFixtures.historyEmberline().characterId(), 2)) .thenReturn(List.of("LOOK", "SAY hi")); - SessionContext context = - new SessionContext(22L, 7L, "99", "demo@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + SessionContext context = GameplayCommandTestFixtures.historyEmberline(); TextCommandInterpretationResult result = handler.handle( diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/InventoryCommandHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/InventoryCommandHandlerTest.java index 005255ed07..16ac79844f 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/InventoryCommandHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/InventoryCommandHandlerTest.java @@ -17,6 +17,7 @@ import net.firedevops.firemud.gamesession.presentation.PlayerOutput; import net.firedevops.firemud.gamesession.presentation.PlayerOutputKind; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import net.firedevops.firemud.shared.v1.ErrorDetail; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -24,9 +25,7 @@ class InventoryCommandHandlerTest { private final GameLogicClient gameLogicClient = Mockito.mock(GameLogicClient.class); private final InventoryCommandHandler handler = new InventoryCommandHandler(gameLogicClient); - private final SessionContext context = - new SessionContext( - 1L, 22L, "123", "emberline@example.com", 911L, "Emberline", 77L, "R-7", "jwt-token"); + private final SessionContext context = GameplayCommandTestFixtures.inventoryEmberline(); @Test void inventoryReturnsStructuredViewFromRuntimeContract() { diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/ItemCommandHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/ItemCommandHandlerTest.java index 1e5331db58..def50acbb4 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/ItemCommandHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/ItemCommandHandlerTest.java @@ -8,6 +8,7 @@ import net.firedevops.firemud.gamesession.dto.CommandEnqueueResult; import net.firedevops.firemud.gamesession.service.ScriptEventPublisher; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -28,9 +29,7 @@ class ItemCommandHandlerTest { containerHandler, meterRegistry, scriptEventPublisher); - private final SessionContext context = - new SessionContext( - 1L, 22L, "123", "emberline@example.com", 911L, "Emberline", 77L, "R-7", "jwt-token"); + private final SessionContext context = GameplayCommandTestFixtures.inventoryEmberline(); @Test void recordsInvocationForSuccessfulItemCommand() { diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/StatusCommandHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/StatusCommandHandlerTest.java index 8e17011d2b..433ce55371 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/StatusCommandHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/StatusCommandHandlerTest.java @@ -12,6 +12,7 @@ import net.firedevops.firemud.gamesession.presentation.ErrorOutput; import net.firedevops.firemud.gamesession.service.ScriptEventPublisher; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -21,9 +22,7 @@ class StatusCommandHandlerTest { Mockito.mock(ScriptEventPublisher.class); private final StatusCommandHandler handler = new StatusCommandHandler(gameLogicClient, scriptEventPublisher); - private final SessionContext context = - new SessionContext( - 1L, 22L, "123", "emberline@example.com", 911L, "Emberline", 77L, "R-7", "jwt-token"); + private final SessionContext context = GameplayCommandTestFixtures.inventoryEmberline(); @Test void statusProjectsEvaluatedResourcesAndVisibleConditionsInStableOrder() { diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/TextCommandInterpreterCapabilityTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/TextCommandInterpreterCapabilityTest.java index fd85cecb77..547b2b316c 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/TextCommandInterpreterCapabilityTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/TextCommandInterpreterCapabilityTest.java @@ -13,6 +13,7 @@ import net.firedevops.firemud.gamesession.presentation.PromptComposer; import net.firedevops.firemud.gamesession.service.SessionAuthenticationService; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -27,9 +28,7 @@ void rejectsDisabledStandardOptionalCommandsBeforeDispatch( SessionAuthenticationService sessionAuthenticationService = Mockito.mock(SessionAuthenticationService.class); TextCommandDispatcher dispatcher = Mockito.mock(TextCommandDispatcher.class); - SessionContext gameplayContext = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 7001L, "Emberline", 7L, "R-1", "jwt"); + SessionContext gameplayContext = GameplayCommandTestFixtures.authoredHelpEmberline(); when(sessionAuthenticationService.resolveSessionContext("41")) .thenReturn(Optional.of(gameplayContext)); TextCommandInterpreter interpreter = @@ -60,9 +59,7 @@ void failsClosedWhenCapabilityResolutionIsUnavailable() { TextCommandDispatcher dispatcher = Mockito.mock(TextCommandDispatcher.class); EffectiveCommandCapabilitiesSettingsResolver capabilitiesResolver = Mockito.mock(EffectiveCommandCapabilitiesSettingsResolver.class); - SessionContext gameplayContext = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 7001L, "Emberline", 7L, "R-1", "jwt"); + SessionContext gameplayContext = GameplayCommandTestFixtures.authoredHelpEmberline(); when(sessionAuthenticationService.resolveSessionContext("41")) .thenReturn(Optional.of(gameplayContext)); when(capabilitiesResolver.isEnabled(PlayerCommandCapability.SOCIAL, 22L, 7L)) diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/WhoCommandHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/WhoCommandHandlerTest.java index b3ed4f874b..ed1dee1597 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/WhoCommandHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/WhoCommandHandlerTest.java @@ -10,8 +10,8 @@ import net.firedevops.firemud.gamesession.service.GameplayPresenceActivityResolver; import net.firedevops.firemud.gamesession.service.GameplayPresenceActivityState; import net.firedevops.firemud.gamesession.service.ScriptEventPublisher; -import net.firedevops.firemud.gamesession.service.SessionContext; import net.firedevops.firemud.gamesession.service.impl.FakeGameplayPresenceService; +import net.firedevops.firemud.gamesession.test.GameplayPresenceTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -33,7 +33,7 @@ void whoShowsBoundedEmptyStateWhenNobodyIsConnected() { TextCommandInterpretationResult result = handler.handle( new TextCommand(TextCommandType.WHO, java.util.List.of(), "who"), - new SessionContext(2L, 22L, "2", "second@example.com", 102L, "Ben", 7L, "R-1", null)); + GameplayPresenceTestFixtures.whoBen("second@example.com")); assertThat(result.commandResult().accepted()).isTrue(); assertThat(render(result)).isEqualTo("Gods [0]: \nPlayers [0]: "); @@ -65,7 +65,7 @@ void whoGroupsElevatedPlayersFirstAndPlayersAfterward() { java.util.Map.of())); gameplayPresenceService.registerConnected( - new SessionContext(1L, 22L, "1", "god@example.com", 101L, "Aster", 7L, "R-1", godJwt)); + GameplayPresenceTestFixtures.whoAster("god@example.com", godJwt)); String moderatorJwt = jwtUtil.generateToken( "4", @@ -74,18 +74,15 @@ void whoGroupsElevatedPlayersFirstAndPlayersAfterward() { "4", "scopedRoles", java.util.Map.of("22", java.util.List.of("moderator")))); + gameplayPresenceService.registerConnected(GameplayPresenceTestFixtures.whoDara(moderatorJwt)); gameplayPresenceService.registerConnected( - new SessionContext( - 4L, 22L, "4", "moderator@example.com", 104L, "Dara", 7L, "R-1", moderatorJwt)); - gameplayPresenceService.registerConnected( - new SessionContext(2L, 22L, "2", "second@example.com", 102L, "Ben", 7L, "R-1", null)); - gameplayPresenceService.registerConnected( - new SessionContext(3L, 22L, "3", "third@example.com", 103L, "Cara", 7L, "R-1", null)); + GameplayPresenceTestFixtures.whoBen("second@example.com")); + gameplayPresenceService.registerConnected(GameplayPresenceTestFixtures.whoCara()); TextCommandInterpretationResult result = handler.handle( new TextCommand(TextCommandType.WHO, java.util.List.of(), "WHO"), - new SessionContext(2L, 22L, "2", "second@example.com", 102L, "Ben", 7L, "R-1", null)); + GameplayPresenceTestFixtures.whoBen("second@example.com")); assertThat(result.commandResult().accepted()).isTrue(); assertThat(render(result)).isEqualTo("Gods [2]: Aster, Dara\nPlayers [2]: Ben, Cara"); @@ -98,15 +95,15 @@ void whoOmitsRemovedPresenceAfterLogoutLikeCleanup() { new WhoCommandHandler(gameplayPresenceService, activityResolver, scriptEventPublisher); gameplayPresenceService.registerConnected( - new SessionContext(1L, 22L, "1", "first@example.com", 101L, "Aster", 7L, "R-1", null)); + GameplayPresenceTestFixtures.whoAster("first@example.com", null)); gameplayPresenceService.registerConnected( - new SessionContext(2L, 22L, "2", "second@example.com", 102L, "Ben", 7L, "R-1", null)); + GameplayPresenceTestFixtures.whoBen("second@example.com")); gameplayPresenceService.removeBySessionId(1L); TextCommandInterpretationResult result = handler.handle( new TextCommand(TextCommandType.WHO, java.util.List.of(), "WHO"), - new SessionContext(2L, 22L, "2", "second@example.com", 102L, "Ben", 7L, "R-1", null)); + GameplayPresenceTestFixtures.whoBen("second@example.com")); assertThat(result.commandResult().accepted()).isTrue(); assertThat(render(result)).isEqualTo("Gods [0]: \nPlayers [1]: Ben"); @@ -121,9 +118,9 @@ void whoAnnotatesExplicitAndAutoAfkPlayers() { new WhoCommandHandler(gameplayPresenceService, resolver, scriptEventPublisher); gameplayPresenceService.registerConnected( - new SessionContext(1L, 22L, "1", "active@example.com", 101L, "Aster", 7L, "R-1", null)); + GameplayPresenceTestFixtures.whoAster("active@example.com", null)); gameplayPresenceService.registerConnected( - new SessionContext(2L, 22L, "2", "idle@example.com", 102L, "Ben", 7L, "R-1", null)); + GameplayPresenceTestFixtures.whoBen("idle@example.com")); when(resolver.resolve(gameplayPresenceService.findConnectedBySessionId(1L).orElseThrow())) .thenReturn(GameplayPresenceActivityState.ACTIVE); when(resolver.resolve(gameplayPresenceService.findConnectedBySessionId(2L).orElseThrow())) @@ -132,7 +129,7 @@ void whoAnnotatesExplicitAndAutoAfkPlayers() { TextCommandInterpretationResult result = handler.handle( new TextCommand(TextCommandType.WHO, java.util.List.of(), "WHO"), - new SessionContext(1L, 22L, "1", "active@example.com", 101L, "Aster", 7L, "R-1", null)); + GameplayPresenceTestFixtures.whoAster("active@example.com", null)); assertThat(result.commandResult().accepted()).isTrue(); assertThat(result.outputs()) diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/WorldsCommandHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/WorldsCommandHandlerTest.java index 82658aba07..8ecd774522 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/WorldsCommandHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/WorldsCommandHandlerTest.java @@ -10,8 +10,8 @@ import net.firedevops.firemud.gamesession.presentation.CharacterBrowseViewOutput; import net.firedevops.firemud.gamesession.presentation.RealmBrowseViewOutput; import net.firedevops.firemud.gamesession.presentation.WorldsViewOutput; -import net.firedevops.firemud.gamesession.service.SessionContext; import net.firedevops.firemud.gamesession.support.TestGameplayWorldCatalogs; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -107,10 +107,7 @@ void browseCharactersReturnsStructuredCharacterList() { .build()); WorldsCommandHandler.CharacterBrowseResult result = - handler.browseCharacters( - new SessionContext(1L, 22L, "123", "demo@example.com", 0L, null, 0L, "jwt"), - "demo", - null); + handler.browseCharacters(GameplayCommandTestFixtures.worldBrowseDemo(), "demo", null); assertThat(result).isInstanceOf(WorldsCommandHandler.CharacterBrowseResult.Success.class); CharacterBrowseViewOutput output = @@ -158,10 +155,7 @@ void browseCharactersUsesIsolatedStateRealmRoster() { .build()); WorldsCommandHandler.CharacterBrowseResult result = - handler.browseCharacters( - new SessionContext(1L, 22L, "123", "demo@example.com", 0L, null, 0L, "jwt"), - "demo", - null); + handler.browseCharacters(GameplayCommandTestFixtures.worldBrowseDemo(), "demo", null); assertThat(result).isInstanceOf(WorldsCommandHandler.CharacterBrowseResult.Success.class); CharacterBrowseViewOutput output = @@ -190,10 +184,7 @@ void browseCharactersFallsBackToUnspecifiedRosterScopeForNullRealmScope() { entityManagementClient); WorldsCommandHandler.CharacterBrowseResult result = - localHandler.browseCharacters( - new SessionContext(1L, 22L, "123", "demo@example.com", 0L, null, 0L, "jwt"), - "demo", - null); + localHandler.browseCharacters(GameplayCommandTestFixtures.worldBrowseDemo(), "demo", null); assertThat(result).isInstanceOf(WorldsCommandHandler.CharacterBrowseResult.Success.class); } diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/WorldsTextCommandDispatchHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/WorldsTextCommandDispatchHandlerTest.java index 680573bef1..2d916a2844 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/WorldsTextCommandDispatchHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/WorldsTextCommandDispatchHandlerTest.java @@ -15,6 +15,7 @@ import net.firedevops.firemud.gamesession.service.ScriptEventPublisher; import net.firedevops.firemud.gamesession.service.SessionContext; import net.firedevops.firemud.gamesession.support.TestGameplayWorldCatalogs; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -34,9 +35,7 @@ class WorldsTextCommandDispatchHandlerTest { @Test void publishesCommandEventForGameplayScopedWorldsBrowse() { - SessionContext context = - new SessionContext( - 7L, 22L, "41", "emberline@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + SessionContext context = GameplayCommandTestFixtures.authoredDispatchEmberline(); TextCommandInterpretationResult result = handler.handle( @@ -65,9 +64,7 @@ void publishesCommandEventForGameplayScopedWorldsBrowse() { @Test void publishesCommandEventForGameplayScopedRealmsBrowse() { gameplayCatalogProperties.setWorlds(List.of(world("demo", 22L, 41L, false))); - SessionContext context = - new SessionContext( - 7L, 22L, "41", "emberline@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + SessionContext context = GameplayCommandTestFixtures.authoredDispatchEmberline(); TextCommandInterpretationResult result = handler.handle( @@ -108,9 +105,7 @@ void publishesCommandEventForGameplayScopedCharsBrowse() { .setPlayableStateScope(PlayableStateScope.PLAYABLE_STATE_SCOPE_SHARED) .build()) .build()); - SessionContext context = - new SessionContext( - 7L, 22L, "123", "emberline@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + SessionContext context = GameplayCommandTestFixtures.helpCapabilityEmberline(7L); TextCommandInterpretationResult result = handler.handle( diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/config/EffectiveCommandHistorySettingsResolverTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/config/EffectiveCommandHistorySettingsResolverTest.java index 8941adc987..b37fe27317 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/config/EffectiveCommandHistorySettingsResolverTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/config/EffectiveCommandHistorySettingsResolverTest.java @@ -8,7 +8,7 @@ import net.firedevops.firemud.common.settings.ScopedSettingsOverrides; import net.firedevops.firemud.common.settings.ScopedSettingsSnapshot; import net.firedevops.firemud.common.settings.SharedSettingsAuthorityReader; -import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -39,10 +39,7 @@ void resolvesTenantThenGameInstanceCommandHistoryOverrides() { new FiremudCommandHistoryProperties(10), authorityReader); EffectiveCommandHistorySettingsResolver.ResolvedValue - resolved = - resolver.resolvedCommandHistory( - new SessionContext( - 1L, 22L, "123", "demo@example.com", 911L, "Ember", 7L, "R-1", null)); + resolved = resolver.resolvedCommandHistory(GameplayCommandTestFixtures.settingsEmber()); assertThat(resolved.effective()).isEqualTo(new FiremudCommandHistoryProperties(20)); assertThat(resolved.sources()) diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/config/EffectiveReconnectionSettingsResolverTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/config/EffectiveReconnectionSettingsResolverTest.java index 07ee466823..c5ceb6545f 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/config/EffectiveReconnectionSettingsResolverTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/config/EffectiveReconnectionSettingsResolverTest.java @@ -8,7 +8,7 @@ import net.firedevops.firemud.common.settings.ScopedSettingsOverrides; import net.firedevops.firemud.common.settings.ScopedSettingsSnapshot; import net.firedevops.firemud.common.settings.SharedSettingsAuthorityReader; -import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -52,8 +52,7 @@ void absentPersistedReconnectionOverrideFallsBackToOperatorDefaults() { authorityReader); FiremudReconnectionProperties effective = - resolver.reconnection( - new SessionContext(1L, 22L, "123", "demo@example.com", 911L, "Ember", 7L, "R-1", null)); + resolver.reconnection(GameplayCommandTestFixtures.settingsEmber()); assertThat(effective.policy().resumeWindowMs()).isEqualTo(45_000L); assertThat(effective.policy().staleResumeFallsThroughToFreshEntry()).isTrue(); @@ -113,8 +112,7 @@ void disregardsInvalidSparseOverrideAndFallsBackToOperatorDefaultsWithDiagnostic authorityReader); EffectiveReconnectionSettingsResolver.ResolvedValue resolved = - resolver.resolvedReconnection( - new SessionContext(1L, 22L, "123", "demo@example.com", 911L, "Ember", 7L, "R-1", null)); + resolver.resolvedReconnection(GameplayCommandTestFixtures.settingsEmber()); assertThat(resolved.effective().buffer().softMaxBytes()).isEqualTo(16_384); assertThat(resolved.effective().buffer().hardMaxBytes()).isEqualTo(65_536); @@ -158,8 +156,7 @@ void invalidGameInstanceOverrideFallsBackToValidTenantLayer() { authorityReader); EffectiveReconnectionSettingsResolver.ResolvedValue resolved = - resolver.resolvedReconnection( - new SessionContext(1L, 22L, "123", "demo@example.com", 911L, "Ember", 7L, "R-1", null)); + resolver.resolvedReconnection(GameplayCommandTestFixtures.settingsEmber()); assertThat(resolved.effective().buffer().softMaxBytes()).isEqualTo(16_384); assertThat(resolved.effective().buffer().hardMaxBytes()).isEqualTo(80_000); diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/config/EffectiveSettingsResolverTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/config/EffectiveSettingsResolverTest.java index 4e6f7cdd59..b1c2dda6d0 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/config/EffectiveSettingsResolverTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/config/EffectiveSettingsResolverTest.java @@ -7,6 +7,7 @@ import net.firedevops.firemud.common.settings.ScopedSettingsSnapshot; import net.firedevops.firemud.common.settings.SharedSettingsAuthorityReader; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -52,8 +53,7 @@ void presentationOverridesMergeTenantThenGameInstance() { authorityReader); PresentationProperties effective = - resolver.presentation( - new SessionContext(1L, 22L, "123", "demo@example.com", 911L, "Ember", 7L, "R-1", null)); + resolver.presentation(GameplayCommandTestFixtures.settingsEmber()); assertThat(effective.defaultLocaleTag()).isEqualTo("fr"); assertThat(effective.defaultColorMode()).isEqualTo(PresentationProperties.ColorMode.BASIC); diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/controller/EffectiveSettingsControllerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/controller/EffectiveSettingsControllerTest.java index 57dd7ffe30..8ef1c1735e 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/controller/EffectiveSettingsControllerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/controller/EffectiveSettingsControllerTest.java @@ -19,6 +19,7 @@ import net.firedevops.firemud.gamesession.config.WorldTopologyProperties; import net.firedevops.firemud.gamesession.service.SessionAuthenticationService; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -53,9 +54,7 @@ void setUp() { @Test void effectiveSettingsUsesNormalizedPersistedSessionContext() { - SessionContext cleared = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 0L, null, 0L, null, "jwt", "en-NZ", 1L); + SessionContext cleared = GameplayCommandTestFixtures.bootstrapDemo(); PresentationProperties presentation = new PresentationProperties(); MovementProperties movement = new MovementProperties(); WorldTopologyProperties worldTopology = new WorldTopologyProperties(); diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/CommunicationRecipientDeliveryServiceTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/CommunicationRecipientDeliveryServiceTest.java index b4ed47b4df..bcfd4918ac 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/CommunicationRecipientDeliveryServiceTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/CommunicationRecipientDeliveryServiceTest.java @@ -19,6 +19,7 @@ import net.firedevops.firemud.gamesession.presentation.CommunicationOutputMapper; import net.firedevops.firemud.gamesession.presentation.PlayerOutput; import net.firedevops.firemud.gamesession.presentation.TextPlayerOutputRenderer; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import net.firedevops.firemud.gamesession.websocket.WebSocketOutputProjector; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -67,9 +68,7 @@ void tearDown() { @Test void deliverDropsStaleRecipientResolvedByGameplayIdentity() { - SessionContext actor = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 123L, "Emberline", 1L, "R-1", "jwt"); + SessionContext actor = GameplayCommandTestFixtures.communicationSenderEmberline(); SessionContext clearedRecipient = new SessionContext( 42L, 22L, "456", "friend@example.com", 0L, null, 0L, null, "jwt", "en-NZ", 1L); @@ -97,9 +96,7 @@ void deliverDropsStaleRecipientResolvedByGameplayIdentity() { @Test void unreadableRecipientDoesNotAbortDeliveryToLaterRecipients() { - SessionContext actor = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 123L, "Emberline", 1L, "R-1", "jwt"); + SessionContext actor = GameplayCommandTestFixtures.communicationSenderEmberline(); SessionContext healthyRecipient = new SessionContext( 43L, 22L, "789", "friend@example.com", 789L, "Sora", 1L, "R-1", "jwt", "en-NZ", 1L); @@ -149,9 +146,7 @@ void unreadableRecipientDoesNotAbortDeliveryToLaterRecipients() { @Test void deliverDropsStaleRecipientResolvedByGameplayName() { - SessionContext actor = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 123L, "Emberline", 1L, "R-1", "jwt"); + SessionContext actor = GameplayCommandTestFixtures.communicationSenderEmberline(); SessionContext clearedRecipient = new SessionContext( 42L, 22L, "456", "friend@example.com", 0L, null, 0L, null, "jwt", "en-NZ", 1L); @@ -179,9 +174,7 @@ void deliverDropsStaleRecipientResolvedByGameplayName() { @Test void deliverDoesNotFallbackToNameWhenRecipientIdIsMalformed() { - SessionContext actor = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 123L, "Emberline", 1L, "R-1", "jwt"); + SessionContext actor = GameplayCommandTestFixtures.communicationSenderEmberline(); CommunicationRecipientView view = CommunicationRecipientView.newBuilder() .setRole(CommunicationRecipientRole.COMMUNICATION_RECIPIENT_ROLE_TARGET) @@ -206,9 +199,7 @@ void deliverDoesNotFallbackToNameWhenRecipientIdIsMalformed() { @Test void deliverDoesNotFallbackToNameWhenRecipientIdIsNonPositive() { - SessionContext actor = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 123L, "Emberline", 1L, "R-1", "jwt"); + SessionContext actor = GameplayCommandTestFixtures.communicationSenderEmberline(); CommunicationRecipientView view = CommunicationRecipientView.newBuilder() .setRole(CommunicationRecipientRole.COMMUNICATION_RECIPIENT_ROLE_TARGET) @@ -231,9 +222,7 @@ void deliverDoesNotFallbackToNameWhenRecipientIdIsNonPositive() { @Test void deliverDoesNotFallbackToNameWhenStructuredRecipientIdDoesNotResolve() { - SessionContext actor = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 123L, "Emberline", 1L, "R-1", "jwt"); + SessionContext actor = GameplayCommandTestFixtures.communicationSenderEmberline(); CommunicationRecipientView view = CommunicationRecipientView.newBuilder() .setRole(CommunicationRecipientRole.COMMUNICATION_RECIPIENT_ROLE_TARGET) @@ -261,12 +250,8 @@ void deliverDoesNotFallbackToNameWhenStructuredRecipientIdDoesNotResolve() { @Test @SuppressWarnings("unchecked") void deliverBuffersStructuredReplayEntryForRecipientCommunication() { - SessionContext actor = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 123L, "Emberline", 1L, "R-1", "jwt"); - SessionContext recipient = - new SessionContext( - 42L, 22L, "456", "friend@example.com", 456L, "Sora", 1L, "R-2", "jwt", "en-NZ", 1L); + SessionContext actor = GameplayCommandTestFixtures.communicationSenderEmberline(); + SessionContext recipient = GameplayCommandTestFixtures.communicationTargetSora(); CommunicationRecipientView view = CommunicationRecipientView.newBuilder() .setRole(CommunicationRecipientRole.COMMUNICATION_RECIPIENT_ROLE_TARGET) @@ -311,12 +296,8 @@ void deliverBuffersStructuredReplayEntryForRecipientCommunication() { @Test void deliverDoesNotBufferNonReplayableRecipientOutput() { - SessionContext actor = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 123L, "Emberline", 1L, "R-1", "jwt"); - SessionContext recipient = - new SessionContext( - 42L, 22L, "456", "friend@example.com", 456L, "Sora", 1L, "R-2", "jwt", "en-NZ", 1L); + SessionContext actor = GameplayCommandTestFixtures.communicationSenderEmberline(); + SessionContext recipient = GameplayCommandTestFixtures.communicationTargetSora(); CommunicationRecipientView view = CommunicationRecipientView.newBuilder() .setRole(CommunicationRecipientRole.COMMUNICATION_RECIPIENT_ROLE_TARGET) @@ -349,10 +330,8 @@ void deliverDoesNotBufferNonReplayableRecipientOutput() { @ValueSource(booleans = {false, true}) void sendFailureRequestsOwnedCloseAndRetainsRegistrationUntilCallback(boolean closeFails) throws Exception { - SessionContext actor = new SessionContext(41L, 22L, "123", 123L, 1L, "R-1", "jwt"); - SessionContext recipient = - new SessionContext( - 42L, 22L, "456", "friend@example.com", 456L, "Sora", 1L, "R-2", "jwt", "en-NZ", 1L); + SessionContext actor = GameplayCommandTestFixtures.unnamedOutputActor(); + SessionContext recipient = GameplayCommandTestFixtures.communicationTargetSora(); var view = CommunicationRecipientView.newBuilder() .setRole(CommunicationRecipientRole.COMMUNICATION_RECIPIENT_ROLE_TARGET) diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/GameplayPresenceActivityResolverTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/GameplayPresenceActivityResolverTest.java index d37ce08304..3c9bcb6f6e 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/GameplayPresenceActivityResolverTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/GameplayPresenceActivityResolverTest.java @@ -4,6 +4,7 @@ import java.util.concurrent.atomic.AtomicLong; import net.firedevops.firemud.gamesession.config.PresenceProperties; +import net.firedevops.firemud.gamesession.test.GameplayPresenceTestFixtures; import org.junit.jupiter.api.Test; class GameplayPresenceActivityResolverTest { @@ -16,21 +17,7 @@ void explicitAfkWinsOverDerivedAutoAfk() { GameplayPresenceActivityResolver resolver = new GameplayPresenceActivityResolver(properties, () -> 500L); - GameplayPresence presence = - new GameplayPresence( - 1L, - 22L, - 7L, - "demo", - "production", - "2", - 102L, - "Ben", - GameplayPresenceRole.PLAYER, - 100L, - 300L, - 250L, - 250L); + GameplayPresence presence = GameplayPresenceTestFixtures.activityBen(100L, 300L, 250L, 250L); assertEquals(GameplayPresenceActivityState.EXPLICIT_AFK, resolver.resolve(presence)); } @@ -44,55 +31,14 @@ void autoAfkIgnoresAcceptedNonGameplayActivity() { GameplayPresenceActivityResolver resolver = new GameplayPresenceActivityResolver(properties, now::get); - GameplayPresence acceptedOnly = - new GameplayPresence( - 1L, - 22L, - 7L, - "demo", - "production", - "2", - 102L, - "Ben", - GameplayPresenceRole.PLAYER, - 50L, - null, - 150L, - null); + GameplayPresence acceptedOnly = GameplayPresenceTestFixtures.activityBen(50L, null, 150L, null); assertEquals(GameplayPresenceActivityState.AUTO_AFK, resolver.resolve(acceptedOnly)); GameplayPresence activeFromMeaningful = - new GameplayPresence( - 1L, - 22L, - 7L, - "demo", - "production", - "2", - 102L, - "Ben", - GameplayPresenceRole.PLAYER, - 50L, - null, - 60L, - 150L); + GameplayPresenceTestFixtures.activityBen(50L, null, 60L, 150L); assertEquals(GameplayPresenceActivityState.ACTIVE, resolver.resolve(activeFromMeaningful)); - GameplayPresence autoAfk = - new GameplayPresence( - 1L, - 22L, - 7L, - "demo", - "production", - "2", - 102L, - "Ben", - GameplayPresenceRole.PLAYER, - 50L, - null, - 60L, - 60L); + GameplayPresence autoAfk = GameplayPresenceTestFixtures.activityBen(50L, null, 60L, 60L); assertEquals(GameplayPresenceActivityState.AUTO_AFK, resolver.resolve(autoAfk)); } @@ -104,21 +50,7 @@ void autoAfkFallsBackToConnectionTimeWhenNoGameplayActivityExists() { GameplayPresenceActivityResolver resolver = new GameplayPresenceActivityResolver(properties, () -> 200L); - GameplayPresence presence = - new GameplayPresence( - 1L, - 22L, - 7L, - "demo", - "production", - "2", - 102L, - "Ben", - GameplayPresenceRole.PLAYER, - 150L, - null, - 190L, - null); + GameplayPresence presence = GameplayPresenceTestFixtures.activityBen(150L, null, 190L, null); assertEquals(GameplayPresenceActivityState.ACTIVE, resolver.resolve(presence)); } diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/PlayerCommandHistoryRetentionSweepJobTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/PlayerCommandHistoryRetentionSweepJobTest.java index 28bd6d2518..74b39c75bd 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/PlayerCommandHistoryRetentionSweepJobTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/PlayerCommandHistoryRetentionSweepJobTest.java @@ -8,6 +8,7 @@ import net.firedevops.firemud.common.config.FiremudCommandHistoryProperties; import net.firedevops.firemud.gamesession.config.EffectiveCommandHistorySettingsResolver; import net.firedevops.firemud.gamesession.repository.PlayerCommandHistoryRepository; +import net.firedevops.firemud.gamesession.test.GameplayHistoryTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -20,7 +21,7 @@ void trimsInactiveScopesToTheirCurrentEffectiveMaximum() { EffectiveCommandHistorySettingsResolver settingsResolver = Mockito.mock(EffectiveCommandHistorySettingsResolver.class); PlayerCommandHistoryRepository.HistoryScope scope = - new PlayerCommandHistoryRepository.HistoryScope(22L, 7L, 13L); + GameplayHistoryTestFixtures.retainedPlayerScope(); when(repository.tryLockRetentionSweep()).thenReturn(true); when(repository.retentionSweepState()) .thenReturn(new PlayerCommandHistoryRepository.RetentionSweepState(null, 0)); @@ -32,7 +33,9 @@ void trimsInactiveScopesToTheirCurrentEffectiveMaximum() { job.trimInactiveHistory(); - verify(storageService).trimToMaxEntries(22L, 7L, 13L, 4); + verify(storageService) + .trimToMaxEntries( + 22L, 7L, GameplayHistoryTestFixtures.retainedPlayerScope().characterId(), 4); verify(repository) .saveRetentionSweepState(new PlayerCommandHistoryRepository.RetentionSweepState(scope, 1)); } @@ -62,9 +65,9 @@ void continuesAfterOneScopeFails() { EffectiveCommandHistorySettingsResolver settingsResolver = Mockito.mock(EffectiveCommandHistorySettingsResolver.class); PlayerCommandHistoryRepository.HistoryScope failingScope = - new PlayerCommandHistoryRepository.HistoryScope(22L, 7L, 13L); + GameplayHistoryTestFixtures.retainedPlayerScope(); PlayerCommandHistoryRepository.HistoryScope succeedingScope = - new PlayerCommandHistoryRepository.HistoryScope(22L, 7L, 14L); + GameplayHistoryTestFixtures.nextRetainedPlayerScope(); when(repository.tryLockRetentionSweep()).thenReturn(true); when(repository.retentionSweepState()) .thenReturn(new PlayerCommandHistoryRepository.RetentionSweepState(null, 0)); @@ -74,14 +77,19 @@ void continuesAfterOneScopeFails() { .thenReturn(new FiremudCommandHistoryProperties(4)); Mockito.doThrow(new IllegalStateException("database unavailable")) .when(storageService) - .trimToMaxEntries(22L, 7L, 13L, 4); + .trimToMaxEntries( + 22L, 7L, GameplayHistoryTestFixtures.retainedPlayerScope().characterId(), 4); PlayerCommandHistoryRetentionSweepJob job = new PlayerCommandHistoryRetentionSweepJob(repository, storageService, settingsResolver); job.trimInactiveHistory(); - verify(storageService).trimToMaxEntries(22L, 7L, 13L, 4); - verify(storageService).trimToMaxEntries(22L, 7L, 14L, 4); + verify(storageService) + .trimToMaxEntries( + 22L, 7L, GameplayHistoryTestFixtures.retainedPlayerScope().characterId(), 4); + verify(storageService) + .trimToMaxEntries( + 22L, 7L, GameplayHistoryTestFixtures.nextRetainedPlayerScope().characterId(), 4); } @Test @@ -92,11 +100,11 @@ void reusesSettingsWithinOneTenantGameBatchAndAdvancesTheDurableCursor() { EffectiveCommandHistorySettingsResolver settingsResolver = Mockito.mock(EffectiveCommandHistorySettingsResolver.class); PlayerCommandHistoryRepository.HistoryScope cursor = - new PlayerCommandHistoryRepository.HistoryScope(21L, 7L, 12L); + GameplayHistoryTestFixtures.retentionCursor(); PlayerCommandHistoryRepository.HistoryScope first = - new PlayerCommandHistoryRepository.HistoryScope(22L, 7L, 13L); + GameplayHistoryTestFixtures.retainedPlayerScope(); PlayerCommandHistoryRepository.HistoryScope second = - new PlayerCommandHistoryRepository.HistoryScope(22L, 7L, 14L); + GameplayHistoryTestFixtures.nextRetainedPlayerScope(); when(repository.tryLockRetentionSweep()).thenReturn(true); when(repository.retentionSweepState()) .thenReturn(new PlayerCommandHistoryRepository.RetentionSweepState(cursor, 3)); @@ -109,8 +117,12 @@ void reusesSettingsWithinOneTenantGameBatchAndAdvancesTheDurableCursor() { job.trimInactiveHistory(); verify(settingsResolver).commandHistory(22L, 7L); - verify(storageService).trimToMaxEntries(22L, 7L, 13L, 4); - verify(storageService).trimToMaxEntries(22L, 7L, 14L, 4); + verify(storageService) + .trimToMaxEntries( + 22L, 7L, GameplayHistoryTestFixtures.retainedPlayerScope().characterId(), 4); + verify(storageService) + .trimToMaxEntries( + 22L, 7L, GameplayHistoryTestFixtures.nextRetainedPlayerScope().characterId(), 4); verify(repository) .saveRetentionSweepState(new PlayerCommandHistoryRepository.RetentionSweepState(second, 4)); } @@ -128,7 +140,7 @@ void clearsTheDurableCursorAfterReachingTheEndOfTheSweep() { when(repository.retentionSweepState()) .thenReturn( new PlayerCommandHistoryRepository.RetentionSweepState( - new PlayerCommandHistoryRepository.HistoryScope(22L, 7L, 13L), 3)); + GameplayHistoryTestFixtures.retainedPlayerScope(), 3)); when(repository.findDistinctScopesAfter(Mockito.any(), Mockito.anyInt())).thenReturn(List.of()); job.trimInactiveHistory(); @@ -146,7 +158,7 @@ void wrapsTheDurableSweepStateAfterTheBoundedForwardPass() { EffectiveCommandHistorySettingsResolver settingsResolver = Mockito.mock(EffectiveCommandHistorySettingsResolver.class); PlayerCommandHistoryRepository.HistoryScope scope = - new PlayerCommandHistoryRepository.HistoryScope(22L, 7L, 13L); + GameplayHistoryTestFixtures.retainedPlayerScope(); when(repository.tryLockRetentionSweep()).thenReturn(true); when(repository.retentionSweepState()) .thenReturn(new PlayerCommandHistoryRepository.RetentionSweepState(scope, 19)); diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/PlayerCommandHistoryStorageServiceTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/PlayerCommandHistoryStorageServiceTest.java index 7757ff3948..daf99d3cfc 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/PlayerCommandHistoryStorageServiceTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/PlayerCommandHistoryStorageServiceTest.java @@ -11,6 +11,7 @@ import java.util.List; import net.firedevops.firemud.gamesession.entity.PlayerCommandHistoryEntry; import net.firedevops.firemud.gamesession.repository.PlayerCommandHistoryRepository; +import net.firedevops.firemud.gamesession.test.GameplayHistoryTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; @@ -18,7 +19,8 @@ class PlayerCommandHistoryStorageServiceTest { private static final long TENANT_ID = 22L; private static final long GAME_INSTANCE_ID = 7L; - private static final long CHARACTER_ID = 13L; + private static final PlayerCommandHistoryRepository.HistoryScope SCOPE = + GameplayHistoryTestFixtures.retainedPlayerScope(); private static final Instant ACCEPTED_AT = Instant.parse("2026-07-12T01:00:00Z"); private final PlayerCommandHistoryRepository repository = @@ -29,56 +31,53 @@ class PlayerCommandHistoryStorageServiceTest { @Test void appendPersistsAndTrimsToConfiguredMaximum() { - when(repository.countByScope(TENANT_ID, GAME_INSTANCE_ID, CHARACTER_ID)).thenReturn(3); + when(repository.countByScope(TENANT_ID, GAME_INSTANCE_ID, SCOPE.characterId())).thenReturn(3); - service.append(TENANT_ID, GAME_INSTANCE_ID, CHARACTER_ID, "say hi", 1); + service.append(TENANT_ID, GAME_INSTANCE_ID, SCOPE.characterId(), "say hi", 1); - verify(repository).lockScope(TENANT_ID, GAME_INSTANCE_ID, CHARACTER_ID); + verify(repository).lockScope(TENANT_ID, GAME_INSTANCE_ID, SCOPE.characterId()); ArgumentCaptor entryCaptor = ArgumentCaptor.captor(); verify(repository).save(entryCaptor.capture()); PlayerCommandHistoryEntry saved = entryCaptor.getValue(); assertThat(saved.getTenantId()).isEqualTo(TENANT_ID); assertThat(saved.getGameInstanceId()).isEqualTo(GAME_INSTANCE_ID); - assertThat(saved.getCharacterId()).isEqualTo(CHARACTER_ID); + assertThat(saved.getCharacterId()).isEqualTo(SCOPE.characterId()); assertThat(saved.getCommandText()).isEqualTo("say hi"); assertThat(saved.getAcceptedAt()).isEqualTo(ACCEPTED_AT); - verify(repository).deleteOldestByScope(TENANT_ID, GAME_INSTANCE_ID, CHARACTER_ID, 2); + verify(repository).deleteOldestByScope(TENANT_ID, GAME_INSTANCE_ID, SCOPE.characterId(), 2); } @Test void findRecentReturnsNewestEntriesInOldestToNewestOrder() { - when(repository.findByScope(TENANT_ID, GAME_INSTANCE_ID, CHARACTER_ID)) + when(repository.findByScope(TENANT_ID, GAME_INSTANCE_ID, SCOPE.characterId())) .thenReturn( List.of( historyEntry(1L, "old"), historyEntry(2L, "middle"), historyEntry(3L, "newest"))); - assertThat(service.findRecent(TENANT_ID, GAME_INSTANCE_ID, CHARACTER_ID, 2)) + assertThat(service.findRecent(TENANT_ID, GAME_INSTANCE_ID, SCOPE.characterId(), 2)) .containsExactly("middle", "newest"); - verify(repository).lockScope(TENANT_ID, GAME_INSTANCE_ID, CHARACTER_ID); + verify(repository).lockScope(TENANT_ID, GAME_INSTANCE_ID, SCOPE.characterId()); verify(repository, never()).deleteByIds(Mockito.anyCollection()); } @Test void appendSkipsPersistenceForNullCommandTextOrNonPositiveMaximum() { - service.append(TENANT_ID, GAME_INSTANCE_ID, CHARACTER_ID, null, 5); - service.append(TENANT_ID, GAME_INSTANCE_ID, CHARACTER_ID, "say hi", 0); + service.append(TENANT_ID, GAME_INSTANCE_ID, SCOPE.characterId(), null, 5); + service.append(TENANT_ID, GAME_INSTANCE_ID, SCOPE.characterId(), "say hi", 0); Mockito.verifyNoInteractions(repository); } @Test void findRecentReturnsEmptyWithoutReadingForNonPositiveMaximum() { - assertThat(service.findRecent(TENANT_ID, GAME_INSTANCE_ID, CHARACTER_ID, 0)).isEmpty(); + assertThat(service.findRecent(TENANT_ID, GAME_INSTANCE_ID, SCOPE.characterId(), 0)).isEmpty(); Mockito.verifyNoInteractions(repository); } private PlayerCommandHistoryEntry existingEntry(Long id) { - PlayerCommandHistoryEntry entry = new PlayerCommandHistoryEntry(); + PlayerCommandHistoryEntry entry = GameplayHistoryTestFixtures.retainedCommand(null, null); entry.setId(id); - entry.setTenantId(TENANT_ID); - entry.setGameInstanceId(GAME_INSTANCE_ID); - entry.setCharacterId(CHARACTER_ID); return entry; } diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/PlayerOutputDeliveryServiceTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/PlayerOutputDeliveryServiceTest.java index 4556a8d7a5..7634950bdd 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/PlayerOutputDeliveryServiceTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/PlayerOutputDeliveryServiceTest.java @@ -20,6 +20,7 @@ import net.firedevops.firemud.gamesession.presentation.PlayerOutput; import net.firedevops.firemud.gamesession.presentation.PromptBurstCoordinator; import net.firedevops.firemud.gamesession.presentation.PromptComposer; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import net.firedevops.firemud.gamesession.websocket.WebSocketOutputProjector; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -36,7 +37,7 @@ void sendFailureRequestsOwnedCloseAndRetainsRegistrationUntilCallback(boolean cl var projector = mock(WebSocketOutputProjector.class); var bursts = mock(PromptBurstCoordinator.class); var session = mock(WebSocketSession.class); - var context = new SessionContext(41L, 22L, "123", 123L, 1L, "R-1", "jwt"); + var context = GameplayCommandTestFixtures.unnamedOutputActor(); var output = PlayerOutput.notice("hello"); var presentation = new PresentationProperties(); when(registry.find(41L)).thenReturn(Optional.of(session)); diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/impl/DefaultDurableGameplayCommandExecutionServiceTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/impl/DefaultDurableGameplayCommandExecutionServiceTest.java index b1512de3ce..a65ee65fe9 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/impl/DefaultDurableGameplayCommandExecutionServiceTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/impl/DefaultDurableGameplayCommandExecutionServiceTest.java @@ -38,6 +38,7 @@ import net.firedevops.firemud.gamesession.service.ScriptEventPublisher; import net.firedevops.firemud.gamesession.service.SessionAuthenticationService; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -166,8 +167,7 @@ void executeDoesNotInferActionStateFromCombatMetadata() { @Test void executeReturnsReplayNoOpForIdempotentMoveReplay() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); SessionContext moved = new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-2", "jwt-token"); GameplayCommand command = gameplayCommand("MOVE", "north"); @@ -202,8 +202,7 @@ void executeReturnsReplayNoOpForIdempotentMoveReplay() { @Test void executePublishesMovementLifecycleEventsAfterFirstApply() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); SessionContext moved = new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-2", "jwt-token"); GameplayCommand command = gameplayCommand("MOVE", "north"); @@ -227,8 +226,7 @@ void executePublishesMovementLifecycleEventsAfterFirstApply() { @Test void executeAppliesDurableItemMutationAndDeliversOutput() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("GET", "GET torch"); TickEffect effect = tickEffect("tfx-2", "cmd-2"); TextCommand parsed = @@ -262,8 +260,7 @@ void executeAppliesDurableItemMutationAndDeliversOutput() { @Test void executeRejectsDurableItemMutationAndDeliversOutput() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("PUT", "PUT ration INTO torch"); TickEffect effect = tickEffect("tfx-3", "cmd-3"); TextCommand parsed = @@ -308,8 +305,7 @@ void executeRejectsDurableItemMutationAndDeliversOutput() { @Test void executeAppliesDurableCommunicationAndDeliversOutput() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("SAY", "SAY Hello there"); TickEffect effect = tickEffect("tfx-4", "cmd-4"); TextCommand parsed = @@ -368,8 +364,7 @@ void executeNormalizesStaleSessionContextBeforeDurableGameplayHandling() { @Test void executeResolvesAutomationCommandByGameplayIdentityWhenSessionIdIsUnset() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("SAY", "SAY Hello there"); command.setSessionId(0L); command.setTenantId(22L); @@ -444,8 +439,7 @@ void executeRejectsSessionlessCommandWhenTargetEntityIdIsNonPositive() { @Test void executeAppliesDurableAfkAndDeliversOutput() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("BRB", "BRB"); TickEffect effect = tickEffect("tfx-5", "cmd-5"); TextCommand parsed = @@ -479,8 +473,7 @@ void executeAppliesDurableAfkAndDeliversOutput() { @Test void executeAppliesDurableBlockAndStoresReplay() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("GUARD", "GUARD"); TickEffect effect = tickEffect("tfx-6", "cmd-6"); TextCommand parsed = @@ -508,8 +501,7 @@ void executeAppliesDurableBlockAndStoresReplay() { @Test void executeReplaysStoredCommunicationWithoutInvokingHandler() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("SAY", "SAY Hello there"); TickEffect effect = tickEffect("tfx-6", "cmd-6"); TextCommand parsed = @@ -536,8 +528,7 @@ void executeReplaysStoredCommunicationWithoutInvokingHandler() { @Test void executeReplaysStoredRejectedAfkWithoutInvokingHandler() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("AFK", "AFK"); TickEffect effect = tickEffect("tfx-7", "cmd-7"); TextCommand parsed = @@ -571,8 +562,7 @@ void executeReplaysStoredRejectedAfkWithoutInvokingHandler() { @Test void executeReplaysStoredBlockWithoutInvokingHandler() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("BLOCK", "BLOCK"); TickEffect effect = tickEffect("tfx-7b", "cmd-7b"); TextCommand parsed = new TextCommand(TextCommandType.BLOCK, java.util.List.of(), "BLOCK"); @@ -599,8 +589,7 @@ void executeReplaysStoredBlockWithoutInvokingHandler() { @Test void executeAppliesPersistedAuthoredActionSnapshotWithoutLiveMetadata() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("wave", "wave captain"); command.setAdmittedReleaseBundleId(300L); command.setAdmittedVersionId(41L); @@ -641,8 +630,7 @@ void executeAppliesPersistedAuthoredActionSnapshotWithoutLiveMetadata() { @Test void executeReplaysPersistedAuthoredActionWithoutApplyingItsSnapshotAgain() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("wave", "wave captain"); command.setAdmittedReleaseBundleId(300L); command.setAdmittedVersionId(41L); @@ -756,8 +744,7 @@ void executeRejectsAuthoredActionWhenTheSessionSwitchedGameplayIdentity() { @Test void executeRejectsMalformedAuthoredSnapshotBeforeReplayOrScriptPublication() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("wave", "wave captain"); command.setAdmittedReleaseBundleId(300L); command.setAdmittedVersionId(41L); @@ -780,8 +767,7 @@ void executeRejectsMalformedAuthoredSnapshotBeforeReplayOrScriptPublication() { @Test void executeRejectsAuthoredSnapshotWithAnInvalidModifierBeforeReplay() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("wave", "wave captain"); command.setAdmittedReleaseBundleId(300L); command.setAdmittedVersionId(41L); @@ -822,8 +808,7 @@ void executeRejectsAuthoredSnapshotWithAnInvalidModifierBeforeReplay() { @Test void executeRejectsAuthoredSnapshotAboveTheSharedDurationLimitBeforeReplay() { - SessionContext context = - new SessionContext(42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + SessionContext context = GameplayCommandTestFixtures.durableDemo(); GameplayCommand command = gameplayCommand("wave", "wave captain"); command.setAdmittedReleaseBundleId(300L); command.setAdmittedVersionId(41L); @@ -874,16 +859,7 @@ private String authoredActionEffectsJson() { } private GameplayCommand gameplayCommand(String commandName, String commandText) { - GameplayCommand command = new GameplayCommand(); - command.setCommandId("cmd-1"); - command.setTenantId(22L); - command.setGameInstanceId(5L); - command.setSessionId(42L); - command.setCharacterId(91L); - command.setCommandName(commandName); - command.setCommandText(commandText); - command.setSanitizedCommandText(commandText); - return command; + return GameplayCommandTestFixtures.durableDemoCommand(commandName, commandText); } private TickEffect tickEffect(String effectId, String commandId) { diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/impl/GameAuthoredHelpReaderImplTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/impl/GameAuthoredHelpReaderImplTest.java index e1ac92cd34..ead71feb17 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/impl/GameAuthoredHelpReaderImplTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/service/impl/GameAuthoredHelpReaderImplTest.java @@ -8,6 +8,7 @@ import net.firedevops.firemud.gamesession.repository.GameInstanceRepository; import net.firedevops.firemud.gamesession.service.GameAuthoredHelpReader; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -55,7 +56,6 @@ private void whenInstance(long gameInstanceId, GameInstance instance) { } private SessionContext gameplayContext() { - return new SessionContext( - 41L, 22L, "123", "demo@example.com", 7001L, "Emberline", 7L, "R-1", "jwt"); + return GameplayCommandTestFixtures.authoredHelpEmberline(); } } diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/test/ChatTestFixturesTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/test/ChatTestFixturesTest.java new file mode 100644 index 0000000000..c7eb8a0c57 --- /dev/null +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/test/ChatTestFixturesTest.java @@ -0,0 +1,58 @@ +package net.firedevops.firemud.gamesession.test; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class ChatTestFixturesTest { + @Test + void rosterAndRoomViewsRetainThePublishedNumericFixtureBindings() { + assertThat(ChatTestFixtures.EMBERLINE_ACCOUNT_ROW_ID).isEqualTo(7L); + assertThat(ChatTestFixtures.SORA_ACCOUNT_ROW_ID).isEqualTo(8L); + assertThat(ChatTestFixtures.NYX_ACCOUNT_ROW_ID).isEqualTo(9L); + assertThat(ChatTestFixtures.EMBERLINE_CHARACTER_ID).isEqualTo(7L); + assertThat(ChatTestFixtures.SORA_CHARACTER_ID).isEqualTo(8L); + assertThat(ChatTestFixtures.NYX_CHARACTER_ID).isEqualTo(9L); + assertThat(ChatTestFixtures.characterByName("Emberline").getAccountId()).isEqualTo("7"); + assertThat(ChatTestFixtures.characterByName("Sora").getAccountId()).isEqualTo("8"); + assertThat(ChatTestFixtures.characterByName("Nyx").getAccountId()).isEqualTo("9"); + assertThat(ChatTestFixtures.sampleEntities().getEntitiesList()) + .extracting(entity -> entity.getEntityId()) + .containsExactly("7", "8", "9", "NPC-001"); + } + + @Test + void recipientSessionUsesTheSameSubjectAsTheCharacterRosterAndRoomView() { + var context = ChatTestFixtures.soraRecipientSession(90210L, 1L, 3L); + var character = ChatTestFixtures.characterByName("Sora"); + var roomSora = ChatTestFixtures.sampleEntities().getEntities(1); + + assertThat(context.sessionId()).isEqualTo(90210L); + assertThat(context.tenantId()).isEqualTo(1L); + assertThat(context.accountId()).isEqualTo("8"); + assertThat(context.accountId()).isEqualTo(character.getAccountId()); + assertThat(context.characterId()).isEqualTo(8L); + assertThat(Long.toString(context.characterId())).isEqualTo(character.getId()); + assertThat(roomSora.getEntityId()).isEqualTo(character.getId()); + assertThat(context.characterName()).isEqualTo(roomSora.getDisplayName()); + assertThat(context.gameInstanceId()).isEqualTo(3L); + assertThat(context.bootstrapGameInstanceId()).isEqualTo(3L); + assertThat(context.roomInstanceId()).isEqualTo("R-1021"); + assertThat(context.worldSlug()).isEqualTo("demo"); + assertThat(context.realmSlug()).isEqualTo("production"); + assertThat(context.pointerVersion()).isEqualTo(1L); + assertThat(context.playableStateScope()).isEqualTo("SHARED"); + } + + @Test + void scenarioOverridesDoNotChangeTheNextRosterOrRecipient() { + var changed = + ChatTestFixtures.characterByName("Sora").toBuilder().setAccountId("81").setId("82").build(); + + assertThat(changed.getAccountId()).isEqualTo("81"); + assertThat(changed.getId()).isEqualTo("82"); + assertThat(ChatTestFixtures.characterByName("Sora").getAccountId()).isEqualTo("8"); + assertThat(ChatTestFixtures.characterByName("Sora").getId()).isEqualTo("8"); + assertThat(ChatTestFixtures.soraRecipientSession(90210L, 1L, 3L).characterId()).isEqualTo(8L); + } +} diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/test/GameplayCommandTestFixturesTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/test/GameplayCommandTestFixturesTest.java new file mode 100644 index 0000000000..9d1546f803 --- /dev/null +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/test/GameplayCommandTestFixturesTest.java @@ -0,0 +1,162 @@ +package net.firedevops.firemud.gamesession.test; + +import static org.assertj.core.api.Assertions.assertThat; + +import net.firedevops.firemud.gamesession.service.SessionContext; +import org.junit.jupiter.api.Test; + +class GameplayCommandTestFixturesTest { + @Test + void inventoryScenarioRetainsItsIndependentSubjectAndRuntimeTarget() { + SessionContext context = GameplayCommandTestFixtures.inventoryEmberline(); + + assertThat(context.sessionId()).isEqualTo(1L); + assertThat(context.tenantId()).isEqualTo(22L); + assertThat(context.accountId()).isEqualTo("123"); + assertThat(context.characterId()).isEqualTo(911L); + assertThat(context.gameInstanceId()).isEqualTo(77L); + assertThat(context.roomInstanceId()).isEqualTo("R-7"); + assertThat(context.characterName()).isEqualTo("Emberline"); + } + + @Test + void authoredDispatchAndHistoryKeepTheirDistinctSubjects() { + SessionContext dispatch = GameplayCommandTestFixtures.authoredDispatchEmberline(); + SessionContext history = GameplayCommandTestFixtures.historyEmberline(); + + assertThat(dispatch.accountId()).isEqualTo("41"); + assertThat(dispatch.sessionId()).isEqualTo(7L); + assertThat(dispatch.tenantId()).isEqualTo(22L); + assertThat(history.accountId()).isEqualTo("99"); + assertThat(history.sessionId()).isEqualTo(22L); + assertThat(history.tenantId()).isEqualTo(7L); + assertThat(dispatch.characterId()).isEqualTo(7001L); + assertThat(history.characterId()).isEqualTo(7001L); + assertThat(dispatch.gameInstanceId()).isEqualTo(9L); + assertThat(history.gameInstanceId()).isEqualTo(9L); + } + + @Test + void durableCommandAndLiveContextShareTheExactActorBinding() { + SessionContext context = GameplayCommandTestFixtures.durableDemo(); + var command = GameplayCommandTestFixtures.durableDemoCommand("MOVE", "north"); + + assertThat(context.accountId()).isEqualTo("7"); + assertThat(context.characterId()).isEqualTo(91L); + assertThat(context.sessionId()).isEqualTo(42L); + assertThat(context.tenantId()).isEqualTo(22L); + assertThat(context.gameInstanceId()).isEqualTo(5L); + assertThat(command.getCharacterId()).isEqualTo(context.characterId()); + assertThat(command.getSessionId()).isEqualTo(context.sessionId()); + assertThat(command.getTenantId()).isEqualTo(context.tenantId()); + assertThat(command.getGameInstanceId()).isEqualTo(context.gameInstanceId()); + assertThat(command.getCommandId()).isEqualTo("cmd-1"); + assertThat(command.getCommandName()).isEqualTo("MOVE"); + assertThat(command.getCommandText()).isEqualTo("north"); + assertThat(command.getSanitizedCommandText()).isEqualTo("north"); + } + + @Test + void negativeCaseMutationDoesNotAlterTheNextDurableCommand() { + var changed = GameplayCommandTestFixtures.durableDemoCommand("LOOK", "LOOK"); + changed.setCharacterId(null); + changed.setSessionId(43L); + + var fresh = GameplayCommandTestFixtures.durableDemoCommand("LOOK", "LOOK"); + + assertThat(fresh.getCharacterId()).isEqualTo(91L); + assertThat(fresh.getSessionId()).isEqualTo(42L); + assertThat(GameplayCommandTestFixtures.durableDemo().characterId()).isEqualTo(91L); + } + + @Test + void helpSettingsAndOutputScenariosRetainTheirDifferentBindings() { + SessionContext help = GameplayCommandTestFixtures.authoredHelpEmberline(); + SessionContext capability = GameplayCommandTestFixtures.helpCapabilityEmberline(); + SessionContext settings = GameplayCommandTestFixtures.settingsEmber(); + SessionContext output = GameplayCommandTestFixtures.unnamedOutputActor(); + + assertThat(help.sessionId()).isEqualTo(41L); + assertThat(help.characterId()).isEqualTo(7001L); + assertThat(help.gameInstanceId()).isEqualTo(7L); + assertThat(capability.sessionId()).isEqualTo(42L); + assertThat(capability.characterId()).isEqualTo(7001L); + assertThat(capability.gameInstanceId()).isEqualTo(9L); + assertThat(settings.characterId()).isEqualTo(911L); + assertThat(settings.characterName()).isEqualTo("Ember"); + assertThat(settings.jwt()).isNull(); + assertThat(output.characterId()).isEqualTo(123L); + assertThat(output.characterName()).isNull(); + assertThat(output.gameInstanceId()).isEqualTo(1L); + } + + @Test + void communicationTargetsAndBootstrapContextsKeepTheirOriginalShapes() { + SessionContext sender = GameplayCommandTestFixtures.communicationSenderEmberline(); + SessionContext target = GameplayCommandTestFixtures.communicationTargetSora(); + SessionContext bootstrap = GameplayCommandTestFixtures.bootstrapDemo(); + SessionContext browse = GameplayCommandTestFixtures.worldBrowseDemo(); + SessionContext played = GameplayCommandTestFixtures.webSocketEmberline(); + + assertThat(sender.accountId()).isEqualTo("123"); + assertThat(sender.characterId()).isEqualTo(123L); + assertThat(sender.roomInstanceId()).isEqualTo("R-1"); + assertThat(target.accountId()).isEqualTo("456"); + assertThat(target.characterId()).isEqualTo(456L); + assertThat(target.roomInstanceId()).isEqualTo("R-2"); + assertThat(target.localeTag()).isEqualTo("en-NZ"); + assertThat(bootstrap.sessionId()).isEqualTo(41L); + assertThat(bootstrap.characterId()).isZero(); + assertThat(bootstrap.gameInstanceId()).isZero(); + assertThat(bootstrap.bootstrapGameInstanceId()).isEqualTo(1L); + assertThat(browse.characterId()).isZero(); + assertThat(browse.loginName()).isEqualTo("demo@example.com"); + assertThat(played.characterId()).isEqualTo(7001L); + assertThat(played.localeTag()).isEqualTo("en-NZ"); + assertThat(played.bootstrapGameInstanceId()).isEqualTo(1L); + } + + @Test + void whoAndActivitySubjectsKeepDistinctSessionAndActorCoordinates() { + SessionContext ben = GameplayPresenceTestFixtures.whoBen("idle@example.com"); + SessionContext aster = GameplayPresenceTestFixtures.whoAster("god@example.com", "admin-jwt"); + SessionContext cara = GameplayPresenceTestFixtures.whoCara(); + SessionContext dara = GameplayPresenceTestFixtures.whoDara("moderator-jwt"); + var activity = GameplayPresenceTestFixtures.activityBen(100L, 300L, 250L, 200L); + + assertThat(ben.sessionId()).isEqualTo(2L); + assertThat(ben.characterId()).isEqualTo(102L); + assertThat(ben.loginName()).isEqualTo("idle@example.com"); + assertThat(aster.characterId()).isEqualTo(101L); + assertThat(aster.jwt()).isEqualTo("admin-jwt"); + assertThat(cara.characterId()).isEqualTo(103L); + assertThat(dara.characterId()).isEqualTo(104L); + assertThat(dara.jwt()).isEqualTo("moderator-jwt"); + assertThat(activity.sessionId()).isEqualTo(1L); + assertThat(activity.accountId()).isEqualTo("2"); + assertThat(activity.characterId()).isEqualTo(102L); + assertThat(activity.connectedAtEpochMs()).isEqualTo(100L); + assertThat(activity.explicitAfkSinceEpochMs()).isEqualTo(300L); + assertThat(activity.lastAcceptedCommandAtEpochMs()).isEqualTo(250L); + assertThat(activity.lastMeaningfulActivityAtEpochMs()).isEqualTo(200L); + } + + @Test + void retainedHistoryScopesAndEntriesKeepCursorAndOtherActorsSeparate() { + var scope = GameplayHistoryTestFixtures.retainedPlayerScope(); + var next = GameplayHistoryTestFixtures.nextRetainedPlayerScope(); + var cursor = GameplayHistoryTestFixtures.retentionCursor(); + var entry = GameplayHistoryTestFixtures.retainedCommand("LOOK", null); + + assertThat(scope.tenantId()).isEqualTo(22L); + assertThat(scope.gameInstanceId()).isEqualTo(7L); + assertThat(scope.characterId()).isEqualTo(13L); + assertThat(next.characterId()).isEqualTo(14L); + assertThat(cursor.tenantId()).isEqualTo(21L); + assertThat(cursor.characterId()).isEqualTo(12L); + assertThat(entry.getTenantId()).isEqualTo(scope.tenantId()); + assertThat(entry.getGameInstanceId()).isEqualTo(scope.gameInstanceId()); + assertThat(entry.getCharacterId()).isEqualTo(scope.characterId()); + assertThat(entry.getCommandText()).isEqualTo("LOOK"); + } +} diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/websocket/GameSessionWebSocketHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/websocket/GameSessionWebSocketHandlerTest.java index 1b7861d0de..98ef32ffcd 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/websocket/GameSessionWebSocketHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/websocket/GameSessionWebSocketHandlerTest.java @@ -39,6 +39,7 @@ import net.firedevops.firemud.gamesession.service.SessionContext; import net.firedevops.firemud.gamesession.service.SessionContextService; import net.firedevops.firemud.gamesession.service.SessionContextUnavailableException; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -851,9 +852,7 @@ void afterConnectionEstablishedClearsGenericBootstrapRoutingWhenRuntimeAuthority void handleMessageDoesNotAppendScreenBufferForNormalizedLoggedInShell() throws Exception { TextCommand command = new TextCommand(TextCommandType.LOOK, List.of(), "LOOK"); PlayerOutput output = PlayerOutput.message("Recent room line"); - SessionContext clearedShell = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 0L, null, 0L, null, "jwt", "en-NZ", 1L); + SessionContext clearedShell = GameplayCommandTestFixtures.bootstrapDemo(); when(parser.parse("LOOK")).thenReturn(command); when(interpreter.interpret("41", command, false)) .thenReturn( @@ -921,9 +920,7 @@ void handleMessageDoesNotAppendScreenBufferForPartialGameplayIdentityShell() thr void handleMessageForcesPromptBurstByUiActionMetadata() throws Exception { TextCommand command = new TextCommand(TextCommandType.WHO, List.of(), "WHO"); PlayerOutput output = PlayerOutput.message("Presence: online in Demo World / Live Realm"); - SessionContext context = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 7001L, "Emberline", 7L, "R-1", "jwt", "en-NZ", 1L); + SessionContext context = GameplayCommandTestFixtures.webSocketEmberline(); when(parser.parse("WHO")).thenReturn(command); when(interpreter.interpret("41", command, false)) .thenReturn( @@ -958,9 +955,7 @@ void handleMessageForcesPromptBurstByUiActionMetadata() throws Exception { void handleMessageForcesPromptBurstForGameplayEntryMetadata() throws Exception { TextCommand command = new TextCommand(TextCommandType.PLAY, List.of("demo"), "PLAY demo"); PlayerOutput output = PlayerOutput.message("Entering Demo World"); - SessionContext context = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 7001L, "Emberline", 7L, "R-1", "jwt", "en-NZ", 1L); + SessionContext context = GameplayCommandTestFixtures.webSocketEmberline(); when(parser.parse("PLAY demo")).thenReturn(command); when(interpreter.interpret("41", command, false)) .thenReturn( @@ -1002,9 +997,7 @@ void handleMessageDoesNotForcePromptBurstForPlayTypeWithoutGameplayEntryMetadata "custom-play", null); PlayerOutput output = PlayerOutput.message("Custom session response"); - SessionContext context = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 7001L, "Emberline", 7L, "R-1", "jwt", "en-NZ", 1L); + SessionContext context = GameplayCommandTestFixtures.webSocketEmberline(); when(parser.parse("CUSTOM-PLAY demo")).thenReturn(command); when(interpreter.interpret("41", command, false)) .thenReturn( @@ -1039,9 +1032,7 @@ void handleMessageKeepsNonUiCommunicationUnderNormalPromptBurstPolicy() throws E new TextCommand(TextCommandType.SAY, List.of("hello travelers"), "SAY hello travelers"); PlayerOutput output = PlayerOutput.message("You say, \"hello travelers\""); WebSocketSession decoratedSession = Mockito.mock(WebSocketSession.class); - SessionContext context = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 7001L, "Emberline", 7L, "R-1", "jwt", "en-NZ", 1L); + SessionContext context = GameplayCommandTestFixtures.webSocketEmberline(); when(session.getId()).thenReturn("session-41"); when(decoratedSession.getId()).thenReturn("session-41"); when(activeTransportSessionRegistry.find(41L)).thenReturn(Optional.of(decoratedSession)); @@ -1087,9 +1078,7 @@ void handleMessageKeepsNonUiCommunicationUnderNormalPromptBurstPolicy() throws E @Test void handleMessageDoesNotReplayReconnectBufferForNormalizedLoggedInShell() throws Exception { TextCommand command = new TextCommand(TextCommandType.PLAY, List.of("demo"), "PLAY demo"); - SessionContext clearedShell = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 0L, null, 0L, null, "jwt", "en-NZ", 1L); + SessionContext clearedShell = GameplayCommandTestFixtures.bootstrapDemo(); when(parser.parse("PLAY demo")).thenReturn(command); when(interpreter.interpret("41", command, false)) .thenReturn( @@ -1157,9 +1146,7 @@ void handleMessageUsesTenantScopedSessionContextWhenTenantAttributePresent() thr "22")); TextCommand command = new TextCommand(TextCommandType.LOOK, List.of(), "LOOK"); PlayerOutput output = PlayerOutput.message("Recent room line"); - SessionContext clearedShell = - new SessionContext( - 41L, 22L, "123", "demo@example.com", 0L, null, 0L, null, "jwt", "en-NZ", 1L); + SessionContext clearedShell = GameplayCommandTestFixtures.bootstrapDemo(); when(parser.parse("LOOK")).thenReturn(command); when(interpreter.interpret("41", command, false)) .thenReturn( @@ -1753,7 +1740,7 @@ void queuedFirstPartyFrameWithoutRegistrationCannotBootstrapOrInterpret() throws @Test void sendFailureCloseCallbackOwnsCleanup() throws Exception { - SessionContext context = new SessionContext(41L, 22L, "123", 123L, 1L, "R-1", "jwt"); + SessionContext context = GameplayCommandTestFixtures.unnamedOutputActor(); PlayerOutput output = PlayerOutput.notice("hello"); PresentationProperties presentation = new PresentationProperties(); when(settingsResolver.presentation(context)).thenReturn(presentation); diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/websocket/WebSocketOutputProjectorTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/websocket/WebSocketOutputProjectorTest.java index bf36dd9d4d..9abd52fb73 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/websocket/WebSocketOutputProjectorTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/websocket/WebSocketOutputProjectorTest.java @@ -33,6 +33,7 @@ import net.firedevops.firemud.gamesession.presentation.TextPlayerOutputRenderer; import net.firedevops.firemud.gamesession.presentation.WhoViewOutput; import net.firedevops.firemud.gamesession.service.SessionContext; +import net.firedevops.firemud.gamesession.test.GameplayCommandTestFixtures; import org.junit.jupiter.api.Test; import org.springframework.web.socket.WebSocketSession; @@ -154,9 +155,7 @@ void firstPartyWebUsesAdmittedMetadataForAuthoredCommand() throws Exception { .thenReturn( Map.of( GameSessionWebSocketHandshakeInterceptor.CONNECTION_MODE_ATTR, "first_party_web")); - SessionContext context = - new SessionContext( - 7L, 22L, "41", "emberline@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + SessionContext context = GameplayCommandTestFixtures.authoredDispatchEmberline(); AdmittedTextCommandRegistryResolver admittedResolver = mock(AdmittedTextCommandRegistryResolver.class); when(admittedResolver.resolveMetadata(context, "wave", "wave")) diff --git a/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/ChatTestFixtures.java b/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/ChatTestFixtures.java index 5c92ce6ff3..f50490bd33 100644 --- a/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/ChatTestFixtures.java +++ b/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/ChatTestFixtures.java @@ -4,13 +4,21 @@ import net.firedevops.firemud.entitymanagement.v1.EntityType; import net.firedevops.firemud.entitymanagement.v1.ListRoomEntitiesResponse; import net.firedevops.firemud.entitymanagement.v1.RoomEntity; +import net.firedevops.firemud.gamesession.service.SessionContext; public final class ChatTestFixtures { public static final String ROOM_ID = "R-1021"; public static final String TENANT = "demo"; - public static final String PLAYER_EMBERLINE = "7"; - public static final String PLAYER_SORA = "8"; - public static final String PLAYER_NYX = "9"; + // Account database coordinates and character coordinates are independent fixture facts. + public static final long EMBERLINE_ACCOUNT_ROW_ID = 7L; + public static final long SORA_ACCOUNT_ROW_ID = 8L; + public static final long NYX_ACCOUNT_ROW_ID = 9L; + public static final long EMBERLINE_CHARACTER_ID = 7L; + public static final long SORA_CHARACTER_ID = 8L; + public static final long NYX_CHARACTER_ID = 9L; + public static final String PLAYER_EMBERLINE = Long.toString(EMBERLINE_CHARACTER_ID); + public static final String PLAYER_SORA = Long.toString(SORA_CHARACTER_ID); + public static final String PLAYER_NYX = Long.toString(NYX_CHARACTER_ID); private ChatTestFixtures() {} @@ -57,7 +65,7 @@ public static Character characterByName(String name) { return Character.newBuilder() .setId(PLAYER_EMBERLINE) .setTenantId("1") - .setAccountId("7") + .setAccountId(Long.toString(EMBERLINE_ACCOUNT_ROW_ID)) .setName("Emberline") .build(); } @@ -65,7 +73,7 @@ public static Character characterByName(String name) { return Character.newBuilder() .setId(PLAYER_SORA) .setTenantId("1") - .setAccountId("8") + .setAccountId(Long.toString(SORA_ACCOUNT_ROW_ID)) .setName("Sora") .build(); } @@ -73,13 +81,34 @@ public static Character characterByName(String name) { return Character.newBuilder() .setId(PLAYER_NYX) .setTenantId("1") - .setAccountId("9") + .setAccountId(Long.toString(NYX_ACCOUNT_ROW_ID)) .setName("Nyx") .build(); } return Character.getDefaultInstance(); } + public static SessionContext soraRecipientSession( + long sessionId, long tenantId, long gameInstanceId) { + Character sora = characterByName("Sora"); + return new SessionContext( + sessionId, + tenantId, + sora.getAccountId(), + "sora@example.com", + SORA_CHARACTER_ID, + sora.getName(), + gameInstanceId, + ROOM_ID, + "target-jwt", + null, + gameInstanceId, + "demo", + "production", + 1L, + "SHARED"); + } + public static String canonicalSayText() { return "You say, \"Hello travelers.\""; } diff --git a/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/GameplayCommandTestFixtures.java b/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/GameplayCommandTestFixtures.java new file mode 100644 index 0000000000..71d2c2ae13 --- /dev/null +++ b/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/GameplayCommandTestFixtures.java @@ -0,0 +1,89 @@ +package net.firedevops.firemud.gamesession.test; + +import net.firedevops.firemud.gamesession.entity.GameplayCommand; +import net.firedevops.firemud.gamesession.service.SessionContext; + +/** Named command scenarios shared by handler, dispatch, and durable-execution tests. */ +public final class GameplayCommandTestFixtures { + private GameplayCommandTestFixtures() {} + + public static SessionContext inventoryEmberline() { + return new SessionContext( + 1L, 22L, "123", "emberline@example.com", 911L, "Emberline", 77L, "R-7", "jwt-token"); + } + + public static SessionContext authoredDispatchEmberline() { + return new SessionContext( + 7L, 22L, "41", "emberline@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + } + + public static SessionContext historyEmberline() { + return new SessionContext( + 22L, 7L, "99", "demo@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + } + + public static SessionContext durableDemo() { + return new SessionContext( + 42L, 22L, "7", "demo@example.com", 91L, "Demo", 5L, "R-1", "jwt-token"); + } + + public static SessionContext authoredHelpEmberline() { + return new SessionContext( + 41L, 22L, "123", "demo@example.com", 7001L, "Emberline", 7L, "R-1", "jwt"); + } + + public static SessionContext helpCapabilityEmberline() { + return helpCapabilityEmberline(42L); + } + + public static SessionContext helpCapabilityEmberline(long sessionId) { + return new SessionContext( + sessionId, 22L, "123", "emberline@example.com", 7001L, "Emberline", 9L, "R-1", "jwt"); + } + + public static SessionContext settingsEmber() { + return new SessionContext(1L, 22L, "123", "demo@example.com", 911L, "Ember", 7L, "R-1", null); + } + + public static SessionContext unnamedOutputActor() { + return new SessionContext(41L, 22L, "123", 123L, 1L, "R-1", "jwt"); + } + + public static SessionContext communicationSenderEmberline() { + return new SessionContext( + 41L, 22L, "123", "demo@example.com", 123L, "Emberline", 1L, "R-1", "jwt"); + } + + public static SessionContext communicationTargetSora() { + return new SessionContext( + 42L, 22L, "456", "friend@example.com", 456L, "Sora", 1L, "R-2", "jwt", "en-NZ", 1L); + } + + public static SessionContext worldBrowseDemo() { + return new SessionContext(1L, 22L, "123", "demo@example.com", 0L, null, 0L, "jwt"); + } + + public static SessionContext bootstrapDemo() { + return new SessionContext( + 41L, 22L, "123", "demo@example.com", 0L, null, 0L, null, "jwt", "en-NZ", 1L); + } + + public static SessionContext webSocketEmberline() { + return new SessionContext( + 41L, 22L, "123", "demo@example.com", 7001L, "Emberline", 7L, "R-1", "jwt", "en-NZ", 1L); + } + + public static GameplayCommand durableDemoCommand(String commandName, String commandText) { + SessionContext actor = durableDemo(); + GameplayCommand command = new GameplayCommand(); + command.setCommandId("cmd-1"); + command.setTenantId(actor.tenantId()); + command.setGameInstanceId(actor.gameInstanceId()); + command.setSessionId(actor.sessionId()); + command.setCharacterId(actor.characterId()); + command.setCommandName(commandName); + command.setCommandText(commandText); + command.setSanitizedCommandText(commandText); + return command; + } +} diff --git a/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/GameplayHistoryTestFixtures.java b/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/GameplayHistoryTestFixtures.java new file mode 100644 index 0000000000..214e7cb328 --- /dev/null +++ b/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/GameplayHistoryTestFixtures.java @@ -0,0 +1,33 @@ +package net.firedevops.firemud.gamesession.test; + +import java.time.Instant; +import net.firedevops.firemud.gamesession.entity.PlayerCommandHistoryEntry; +import net.firedevops.firemud.gamesession.repository.PlayerCommandHistoryRepository.HistoryScope; + +/** The retained-history scope shared by storage, sweep, and physical repository scenarios. */ +public final class GameplayHistoryTestFixtures { + private GameplayHistoryTestFixtures() {} + + public static HistoryScope retainedPlayerScope() { + return new HistoryScope(22L, 7L, 13L); + } + + public static HistoryScope nextRetainedPlayerScope() { + return new HistoryScope(22L, 7L, 14L); + } + + public static HistoryScope retentionCursor() { + return new HistoryScope(21L, 7L, 12L); + } + + public static PlayerCommandHistoryEntry retainedCommand(String text, Instant acceptedAt) { + HistoryScope scope = retainedPlayerScope(); + PlayerCommandHistoryEntry entry = new PlayerCommandHistoryEntry(); + entry.setTenantId(scope.tenantId()); + entry.setGameInstanceId(scope.gameInstanceId()); + entry.setCharacterId(scope.characterId()); + entry.setCommandText(text); + entry.setAcceptedAt(acceptedAt); + return entry; + } +} diff --git a/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/GameplayPresenceTestFixtures.java b/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/GameplayPresenceTestFixtures.java new file mode 100644 index 0000000000..dd21458f23 --- /dev/null +++ b/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/GameplayPresenceTestFixtures.java @@ -0,0 +1,48 @@ +package net.firedevops.firemud.gamesession.test; + +import net.firedevops.firemud.gamesession.service.GameplayPresence; +import net.firedevops.firemud.gamesession.service.GameplayPresenceRole; +import net.firedevops.firemud.gamesession.service.SessionContext; + +/** Concrete WHO roster subjects and the separate activity-resolution scenario. */ +public final class GameplayPresenceTestFixtures { + private GameplayPresenceTestFixtures() {} + + public static SessionContext whoBen(String loginName) { + return new SessionContext(2L, 22L, "2", loginName, 102L, "Ben", 7L, "R-1", null); + } + + public static SessionContext whoAster(String loginName, String jwt) { + return new SessionContext(1L, 22L, "1", loginName, 101L, "Aster", 7L, "R-1", jwt); + } + + public static SessionContext whoCara() { + return new SessionContext(3L, 22L, "3", "third@example.com", 103L, "Cara", 7L, "R-1", null); + } + + public static SessionContext whoDara(String jwt) { + return new SessionContext(4L, 22L, "4", "moderator@example.com", 104L, "Dara", 7L, "R-1", jwt); + } + + public static GameplayPresence activityBen( + long connectedAt, + Long explicitAfkSince, + Long lastAcceptedCommandAt, + Long lastMeaningfulActivityAt) { + SessionContext ben = whoBen("second@example.com"); + return new GameplayPresence( + 1L, + ben.tenantId(), + ben.gameInstanceId(), + "demo", + "production", + ben.accountId(), + ben.characterId(), + ben.characterName(), + GameplayPresenceRole.PLAYER, + connectedAt, + explicitAfkSince, + lastAcceptedCommandAt, + lastMeaningfulActivityAt); + } +}