From b3e5c794cb43ecdffa6b3f04c12a4b7018f2cbfa Mon Sep 17 00:00:00 2001 From: jbion Date: Wed, 20 Feb 2019 03:29:46 +0100 Subject: Separate internal from API stuff in game engine --- backend/build.gradle.kts | 1 + .../org/luxons/sevenwonders/SevenWondersTest.kt | 8 --- .../controllers/GameBrowserControllerTest.kt | 4 +- .../controllers/LobbyControllerTest.kt | 4 +- .../sevenwonders/controllers/TestPrincipal.kt | 4 +- .../org/luxons/sevenwonders/lobby/LobbyTest.kt | 4 +- .../org/luxons/sevenwonders/test/TestUtils.kt | 19 ++----- .../org/luxons/sevenwonders/test/api/ApiBoard.kt | 63 ---------------------- .../org/luxons/sevenwonders/test/api/ApiCard.kt | 37 ------------- .../luxons/sevenwonders/test/api/ApiCardBack.kt | 6 --- .../org/luxons/sevenwonders/test/api/ApiEffect.kt | 3 -- .../luxons/sevenwonders/test/api/ApiHandCard.kt | 16 ------ .../org/luxons/sevenwonders/test/api/ApiLobby.kt | 35 ------------ .../luxons/sevenwonders/test/api/ApiMilitary.kt | 10 ---- .../org/luxons/sevenwonders/test/api/ApiPlayer.kt | 27 ---------- .../sevenwonders/test/api/ApiPlayerTurnInfo.kt | 36 ------------- .../luxons/sevenwonders/test/api/ApiProduction.kt | 11 ---- .../org/luxons/sevenwonders/test/api/ApiScience.kt | 10 ---- .../org/luxons/sevenwonders/test/api/ApiTable.kt | 23 -------- .../sevenwonders/test/api/ApiTradingRules.kt | 9 ---- .../org/luxons/sevenwonders/test/api/ApiWonder.kt | 16 ------ .../luxons/sevenwonders/test/api/ApiWonderStage.kt | 13 ----- .../sevenwonders/test/api/SevenWondersClient.kt | 2 + .../sevenwonders/test/api/SevenWondersSession.kt | 38 +++++++------ 24 files changed, 31 insertions(+), 368 deletions(-) delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiBoard.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiCard.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiCardBack.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiEffect.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiHandCard.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiLobby.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiMilitary.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiPlayer.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiPlayerTurnInfo.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiProduction.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiScience.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiTable.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiTradingRules.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiWonder.kt delete mode 100644 backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiWonderStage.kt (limited to 'backend') diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index d862108b..3ac55acf 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -34,6 +34,7 @@ dependencies { testImplementation(kotlin("test-junit")) testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.hildan.jackstomp:jackstomp:2.0.0") + testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin") } // packages the frontend app within the jar diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/SevenWondersTest.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/SevenWondersTest.kt index 7fea4b2e..01de366a 100644 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/SevenWondersTest.kt +++ b/backend/src/test/kotlin/org/luxons/sevenwonders/SevenWondersTest.kt @@ -10,9 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest import org.springframework.boot.test.context.SpringBootTest.WebEnvironment import org.springframework.boot.web.server.LocalServerPort import org.springframework.test.context.junit4.SpringRunner -import java.util.concurrent.ExecutionException import java.util.concurrent.TimeUnit -import java.util.concurrent.TimeoutException import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.assertNull @@ -41,7 +39,6 @@ class SevenWondersTest { } @Test - @Throws(InterruptedException::class, ExecutionException::class, TimeoutException::class) fun chooseName() { val session = client.connect(serverUrl) val playerName = "Test User" @@ -51,7 +48,6 @@ class SevenWondersTest { session.disconnect() } - @Throws(InterruptedException::class, TimeoutException::class, ExecutionException::class) private fun newPlayer(name: String): SevenWondersSession { val otherSession = client.connect(serverUrl) otherSession.chooseName(name) @@ -59,7 +55,6 @@ class SevenWondersTest { } @Test - @Throws(InterruptedException::class, ExecutionException::class, TimeoutException::class) fun lobbySubscription_ignoredForOutsiders() { val ownerSession = newPlayer("GameOwner") val session1 = newPlayer("Player1") @@ -80,7 +75,6 @@ class SevenWondersTest { } @Test - @Throws(InterruptedException::class, ExecutionException::class, TimeoutException::class) fun createGame_success() { val ownerSession = newPlayer("GameOwner") @@ -93,7 +87,6 @@ class SevenWondersTest { } @Test - @Throws(InterruptedException::class, ExecutionException::class, TimeoutException::class) fun createGame_seenByConnectedPlayers() { val otherSession = newPlayer("OtherPlayer") val games = otherSession.watchGames() @@ -117,7 +110,6 @@ class SevenWondersTest { } @Test - @Throws(Exception::class) fun startGame_3players() { val session1 = newPlayer("Player1") val session2 = newPlayer("Player2") diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.kt index b22b8408..98506fd0 100644 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.kt +++ b/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/GameBrowserControllerTest.kt @@ -9,7 +9,7 @@ import org.luxons.sevenwonders.controllers.GameBrowserController.UserAlreadyInGa import org.luxons.sevenwonders.repositories.LobbyRepository import org.luxons.sevenwonders.repositories.PlayerNotFoundException import org.luxons.sevenwonders.repositories.PlayerRepository -import org.luxons.sevenwonders.test.TestUtils +import org.luxons.sevenwonders.test.mockSimpMessagingTemplate import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -24,7 +24,7 @@ class GameBrowserControllerTest { fun setUp() { playerRepository = PlayerRepository() val lobbyRepository = LobbyRepository() - val template = TestUtils.createSimpMessagingTemplate() + val template = mockSimpMessagingTemplate() val lobbyController = LobbyController(lobbyRepository, playerRepository, template) gameBrowserController = GameBrowserController(lobbyController, lobbyRepository, playerRepository, template) } diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/LobbyControllerTest.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/LobbyControllerTest.kt index ac138921..2d37b0f4 100644 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/LobbyControllerTest.kt +++ b/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/LobbyControllerTest.kt @@ -14,7 +14,7 @@ import org.luxons.sevenwonders.lobby.State import org.luxons.sevenwonders.repositories.LobbyRepository import org.luxons.sevenwonders.repositories.PlayerNotFoundException import org.luxons.sevenwonders.repositories.PlayerRepository -import org.luxons.sevenwonders.test.TestUtils +import org.luxons.sevenwonders.test.mockSimpMessagingTemplate import java.util.Arrays import java.util.HashMap import kotlin.test.assertEquals @@ -32,7 +32,7 @@ class LobbyControllerTest { @Before fun setUp() { - val template = TestUtils.createSimpMessagingTemplate() + val template = mockSimpMessagingTemplate() playerRepository = PlayerRepository() lobbyRepository = LobbyRepository() lobbyController = LobbyController(lobbyRepository, playerRepository, template) diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/TestPrincipal.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/TestPrincipal.kt index ce3cf317..76b0f8fa 100644 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/TestPrincipal.kt +++ b/backend/src/test/kotlin/org/luxons/sevenwonders/controllers/TestPrincipal.kt @@ -4,7 +4,5 @@ import java.security.Principal internal class TestPrincipal(private val name: String) : Principal { - override fun getName(): String { - return name - } + override fun getName(): String = name } diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/lobby/LobbyTest.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/lobby/LobbyTest.kt index 66910924..85c89595 100644 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/lobby/LobbyTest.kt +++ b/backend/src/test/kotlin/org/luxons/sevenwonders/lobby/LobbyTest.kt @@ -223,9 +223,7 @@ class LobbyTest { @JvmStatic @DataPoints - fun nbPlayers(): IntArray { - return intArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - } + fun nbPlayers(): IntArray = intArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) @JvmStatic @BeforeClass diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/TestUtils.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/TestUtils.kt index 51db8d91..9f328c5f 100644 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/TestUtils.kt +++ b/backend/src/test/kotlin/org/luxons/sevenwonders/test/TestUtils.kt @@ -4,18 +4,7 @@ import org.springframework.messaging.Message import org.springframework.messaging.MessageChannel import org.springframework.messaging.simp.SimpMessagingTemplate -object TestUtils { - - fun createSimpMessagingTemplate(): SimpMessagingTemplate { - val messageChannel = object : MessageChannel { - override fun send(message: Message<*>): Boolean { - return true - } - - override fun send(message: Message<*>, timeout: Long): Boolean { - return true - } - } - return SimpMessagingTemplate(messageChannel) - } -} +fun mockSimpMessagingTemplate(): SimpMessagingTemplate = SimpMessagingTemplate(object : MessageChannel { + override fun send(message: Message<*>): Boolean = true + override fun send(message: Message<*>, timeout: Long): Boolean = true +}) diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiBoard.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiBoard.kt deleted file mode 100644 index ab14c2df..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiBoard.kt +++ /dev/null @@ -1,63 +0,0 @@ -package org.luxons.sevenwonders.test.api - -import org.luxons.sevenwonders.game.cards.Card -import org.luxons.sevenwonders.game.effects.SpecialAbility -import java.util.Objects - -class ApiBoard { - - var wonder: ApiWonder? = null - - var playerIndex: Int = 0 - - var playedCards: List? = null - - var production: ApiProduction? = null - - var publicProduction: ApiProduction? = null - - var science: ApiScience? = null - - var tradingRules: ApiTradingRules? = null - - var military: ApiMilitary? = null - - var specialAbilities: Set? = null - - var consumedFreeCards: Map? = null - - var copiedGuild: Card? = null - - var gold: Int = 0 - - var pointsPer3Gold: Int = 0 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - if (other == null || javaClass != other.javaClass) { - return false - } - val apiBoard = other as ApiBoard? - return (playerIndex == apiBoard!!.playerIndex && gold == apiBoard.gold && pointsPer3Gold == apiBoard.pointsPer3Gold && wonder == apiBoard.wonder && playedCards == apiBoard.playedCards && production == apiBoard.production && publicProduction == apiBoard.publicProduction && science == apiBoard.science && tradingRules == apiBoard.tradingRules && military == apiBoard.military && specialAbilities == apiBoard.specialAbilities && consumedFreeCards == apiBoard.consumedFreeCards && copiedGuild == apiBoard.copiedGuild) - } - - override fun hashCode(): Int { - return Objects.hash( - wonder, - playerIndex, - playedCards, - production, - publicProduction, - science, - tradingRules, - military, - specialAbilities, - consumedFreeCards, - copiedGuild, - gold, - pointsPer3Gold - ) - } -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiCard.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiCard.kt deleted file mode 100644 index 9cbbcbfe..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiCard.kt +++ /dev/null @@ -1,37 +0,0 @@ -package org.luxons.sevenwonders.test.api - -import org.luxons.sevenwonders.game.cards.Color -import org.luxons.sevenwonders.game.cards.Requirements -import java.util.Objects - -class ApiCard { - - var name: String? = null - - var color: Color? = null - - var requirements: Requirements? = null - - var chainParent: String? = null - - var chainChildren: List? = null - - var image: String? = null - - var back: ApiCardBack? = null - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - if (other == null || javaClass != other.javaClass) { - return false - } - val apiCard = other as ApiCard? - return name == apiCard!!.name && color === apiCard.color && requirements == apiCard.requirements && chainParent == apiCard.chainParent && chainChildren == apiCard.chainChildren && image == apiCard.image && back == apiCard.back - } - - override fun hashCode(): Int { - return Objects.hash(name, color, requirements, chainParent, chainChildren, image, back) - } -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiCardBack.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiCardBack.kt deleted file mode 100644 index 15bfd009..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiCardBack.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.luxons.sevenwonders.test.api - -class ApiCardBack { - - var image: String? = null -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiEffect.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiEffect.kt deleted file mode 100644 index afe8809f..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiEffect.kt +++ /dev/null @@ -1,3 +0,0 @@ -package org.luxons.sevenwonders.test.api - -class ApiEffect diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiHandCard.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiHandCard.kt deleted file mode 100644 index 003c3783..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiHandCard.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.luxons.sevenwonders.test.api - -/** - * A card with contextual information relative to the hand it is sitting in. The extra information is especially - * useful because it frees the client from a painful business logic implementation. - */ -class ApiHandCard { - - var card: ApiCard? = null - - var isChainable: Boolean = false - - var isFree: Boolean = false - - var isPlayable: Boolean = false -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiLobby.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiLobby.kt deleted file mode 100644 index 487fdede..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiLobby.kt +++ /dev/null @@ -1,35 +0,0 @@ -package org.luxons.sevenwonders.test.api - -import org.luxons.sevenwonders.game.api.CustomizableSettings -import org.luxons.sevenwonders.lobby.State -import java.util.Objects - -class ApiLobby { - - var id: Long = 0 - - var name: String? = null - - var owner: String? = null - - var players: List? = null - - var settings: CustomizableSettings? = null - - var state: State? = null - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - if (other == null || javaClass != other.javaClass) { - return false - } - val apiLobby = other as ApiLobby? - return (id == apiLobby!!.id && name == apiLobby.name && owner == apiLobby.owner && players == apiLobby.players && settings == apiLobby.settings && state === apiLobby.state) - } - - override fun hashCode(): Int { - return Objects.hash(id, name, owner, players, settings, state) - } -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiMilitary.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiMilitary.kt deleted file mode 100644 index 23e4f34c..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiMilitary.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.luxons.sevenwonders.test.api - -class ApiMilitary { - - var nbShields = 0 - - var totalPoints = 0 - - var nbDefeatTokens = 0 -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiPlayer.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiPlayer.kt deleted file mode 100644 index 2887b6c7..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiPlayer.kt +++ /dev/null @@ -1,27 +0,0 @@ -package org.luxons.sevenwonders.test.api - -import java.util.Objects - -class ApiPlayer { - - val username: String? = null - - var displayName: String? = null - - var index: Int = 0 - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - if (other == null || javaClass != other.javaClass) { - return false - } - val apiPlayer = other as ApiPlayer? - return index == apiPlayer!!.index && username == apiPlayer.username && displayName == apiPlayer.displayName - } - - override fun hashCode(): Int { - return Objects.hash(username, displayName, index) - } -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiPlayerTurnInfo.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiPlayerTurnInfo.kt deleted file mode 100644 index b1d27db8..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiPlayerTurnInfo.kt +++ /dev/null @@ -1,36 +0,0 @@ -package org.luxons.sevenwonders.test.api - -import org.luxons.sevenwonders.game.api.Action -import java.util.Objects - -class ApiPlayerTurnInfo { - - var playerIndex: Int = 0 - - var table: ApiTable? = null - - var currentAge: Int = 0 - - var action: Action? = null - - var hand: List? = null - - var neighbourGuildCards: List? = null - - var message: String? = null - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - if (other == null || javaClass != other.javaClass) { - return false - } - val that = other as ApiPlayerTurnInfo? - return (playerIndex == that!!.playerIndex && currentAge == that.currentAge && table == that.table && action === that.action && hand == that.hand && neighbourGuildCards == that.neighbourGuildCards && message == that.message) - } - - override fun hashCode(): Int { - return Objects.hash(playerIndex, table, currentAge, action, hand, neighbourGuildCards, message) - } -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiProduction.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiProduction.kt deleted file mode 100644 index 2ab7c343..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiProduction.kt +++ /dev/null @@ -1,11 +0,0 @@ -package org.luxons.sevenwonders.test.api - -import org.luxons.sevenwonders.game.resources.ResourceType -import org.luxons.sevenwonders.game.resources.Resources - -class ApiProduction { - - var fixedResources: Resources? = null - - var alternativeResources: Set>? = null -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiScience.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiScience.kt deleted file mode 100644 index 5e619904..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiScience.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.luxons.sevenwonders.test.api - -import org.luxons.sevenwonders.game.boards.ScienceType - -class ApiScience { - - var quantities: Map? = null - - var jokers: Int = 0 -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiTable.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiTable.kt deleted file mode 100644 index cffbdf2f..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiTable.kt +++ /dev/null @@ -1,23 +0,0 @@ -package org.luxons.sevenwonders.test.api - -import org.luxons.sevenwonders.game.cards.HandRotationDirection -import org.luxons.sevenwonders.game.moves.Move - -class ApiTable { - - var nbPlayers: Int = 0 - - var boards: List? = null - - var currentAge = 0 - - var handRotationDirection: HandRotationDirection? = null - - var lastPlayedMoves: List? = null - - var neighbourGuildCards: List? = null - - fun increaseCurrentAge() { - this.currentAge++ - } -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiTradingRules.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiTradingRules.kt deleted file mode 100644 index fcebe59e..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiTradingRules.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.luxons.sevenwonders.test.api - -import org.luxons.sevenwonders.game.resources.Provider -import org.luxons.sevenwonders.game.resources.ResourceType - -class ApiTradingRules { - - var costs: Map>? = null -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiWonder.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiWonder.kt deleted file mode 100644 index 1efe7917..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiWonder.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.luxons.sevenwonders.test.api - -import org.luxons.sevenwonders.game.resources.ResourceType - -class ApiWonder { - - private val name: String? = null - - private val initialResource: ResourceType? = null - - private val stages: List? = null - - private val image: String? = null - - private val nbBbuiltStages: Int = 0 -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiWonderStage.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiWonderStage.kt deleted file mode 100644 index 41925a55..00000000 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/ApiWonderStage.kt +++ /dev/null @@ -1,13 +0,0 @@ -package org.luxons.sevenwonders.test.api - -import org.luxons.sevenwonders.game.cards.CardBack -import org.luxons.sevenwonders.game.cards.Requirements - -class ApiWonderStage { - - var requirements: Requirements? = null - - var cardBack: CardBack? = null - - var isBuilt: Boolean = false -} diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/SevenWondersClient.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/SevenWondersClient.kt index 472e5529..ee5827cc 100644 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/SevenWondersClient.kt +++ b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/SevenWondersClient.kt @@ -1,6 +1,7 @@ package org.luxons.sevenwonders.test.api import com.fasterxml.jackson.databind.module.SimpleModule +import com.fasterxml.jackson.module.kotlin.KotlinModule import org.hildan.jackstomp.JackstompClient import org.luxons.sevenwonders.config.SEVEN_WONDERS_WS_ENDPOINT import org.luxons.sevenwonders.game.resources.MutableResources @@ -19,6 +20,7 @@ class SevenWondersClient { val mappingJackson2MessageConverter = MappingJackson2MessageConverter() mappingJackson2MessageConverter.objectMapper.registerModule(customMappingsModule) + mappingJackson2MessageConverter.objectMapper.registerModule(KotlinModule()) client = JackstompClient() client.webSocketClient.messageConverter = mappingJackson2MessageConverter diff --git a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/SevenWondersSession.kt b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/SevenWondersSession.kt index 33aa536f..70031a71 100644 --- a/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/SevenWondersSession.kt +++ b/backend/src/test/kotlin/org/luxons/sevenwonders/test/api/SevenWondersSession.kt @@ -5,7 +5,10 @@ import org.hildan.jackstomp.JackstompSession import org.luxons.sevenwonders.actions.ChooseNameAction import org.luxons.sevenwonders.actions.CreateGameAction import org.luxons.sevenwonders.actions.JoinGameAction +import org.luxons.sevenwonders.api.LobbyDTO +import org.luxons.sevenwonders.api.PlayerDTO import org.luxons.sevenwonders.errors.ErrorDTO +import org.luxons.sevenwonders.game.api.PlayerTurnInfo import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.assertTrue @@ -16,43 +19,39 @@ class SevenWondersSession(val jackstompSession: JackstompSession) { jackstompSession.disconnect() } - fun watchErrors(): Channel { - return jackstompSession.subscribe("/user/queue/errors", ErrorDTO::class.java) - } + fun watchErrors(): Channel = jackstompSession.subscribe("/user/queue/errors", ErrorDTO::class.java) @Throws(InterruptedException::class) - fun chooseName(displayName: String): ApiPlayer { + fun chooseName(displayName: String): PlayerDTO { val action = ChooseNameAction(displayName) - return jackstompSession.request(action, ApiPlayer::class.java, "/app/chooseName", "/user/queue/nameChoice") + return jackstompSession.request(action, PlayerDTO::class.java, "/app/chooseName", "/user/queue/nameChoice") } - fun watchGames(): Channel> { - return jackstompSession.subscribe("/topic/games", Array::class.java) + fun watchGames(): Channel> { + return jackstompSession.subscribe("/topic/games", Array::class.java) } @Throws(InterruptedException::class) - fun createGame(gameName: String): ApiLobby { + fun createGame(gameName: String): LobbyDTO { val action = CreateGameAction(gameName) - return jackstompSession.request(action, ApiLobby::class.java, "/app/lobby/create", "/user/queue/lobby/joined") + return jackstompSession.request(action, LobbyDTO::class.java, "/app/lobby/create", "/user/queue/lobby/joined") } @Throws(InterruptedException::class) - fun joinGame(gameId: Long): ApiLobby { + fun joinGame(gameId: Long): LobbyDTO { val action = JoinGameAction(gameId) val lobby = - jackstompSession.request(action, ApiLobby::class.java, "/app/lobby/join", "/user/queue/lobby/joined") + jackstompSession.request(action, LobbyDTO::class.java, "/app/lobby/join", "/user/queue/lobby/joined") assertNotNull(lobby) assertEquals(gameId, lobby.id) return lobby } - fun watchLobbyUpdates(gameId: Long): Channel { - return jackstompSession.subscribe("/topic/lobby/$gameId/updated", ApiLobby::class.java) - } + fun watchLobbyUpdates(gameId: Long): Channel = + jackstompSession.subscribe("/topic/lobby/$gameId/updated", LobbyDTO::class.java) - fun watchLobbyStart(gameId: Long): Channel { - return jackstompSession.subscribe("/topic/lobby/$gameId/started", ApiLobby::class.java) - } + fun watchLobbyStart(gameId: Long): Channel = + jackstompSession.subscribe("/topic/lobby/$gameId/started", LobbyDTO::class.java) @Throws(InterruptedException::class) fun startGame(gameId: Long) { @@ -66,7 +65,6 @@ class SevenWondersSession(val jackstompSession: JackstompSession) { jackstompSession.send("/app/game/sayReady", "") } - fun watchTurns(): Channel { - return jackstompSession.subscribe("/user/queue/game/turn", ApiPlayerTurnInfo::class.java) - } + fun watchTurns(): Channel = + jackstompSession.subscribe("/user/queue/game/turn", PlayerTurnInfo::class.java) } -- cgit