diff options
Diffstat (limited to 'backend')
3 files changed, 24 insertions, 11 deletions
diff --git a/backend/build.gradle b/backend/build.gradle index 6c733559..af5ed8e2 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -65,7 +65,7 @@ dependencies { annotationProcessor 'org.hildan.livedoc:livedoc-javadoc-processor:4.3.2' testCompile 'org.springframework.boot:spring-boot-starter-test' - testCompile 'org.hildan.jackstomp:jackstomp:1.1.0' + testCompile 'org.hildan.jackstomp:jackstomp:2.0.0' checkstyleConfig 'org.hildan.checkstyle:checkstyle-config:2.1.0' } diff --git a/backend/src/main/kotlin/org/luxons/sevenwonders/config/WebSocketConfig.kt b/backend/src/main/kotlin/org/luxons/sevenwonders/config/WebSocketConfig.kt index bebb3233..743e3d1a 100644 --- a/backend/src/main/kotlin/org/luxons/sevenwonders/config/WebSocketConfig.kt +++ b/backend/src/main/kotlin/org/luxons/sevenwonders/config/WebSocketConfig.kt @@ -10,6 +10,8 @@ import org.springframework.web.socket.config.annotation.StompEndpointRegistry import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer import org.springframework.web.socket.server.support.DefaultHandshakeHandler +const val SEVEN_WONDERS_WS_ENDPOINT = "/seven-wonders-websocket" + @Configuration @EnableWebSocketMessageBroker class WebSocketConfig @Autowired constructor(private val topicSubscriptionInterceptor: TopicSubscriptionInterceptor) : @@ -25,7 +27,7 @@ class WebSocketConfig @Autowired constructor(private val topicSubscriptionInterc } override fun registerStompEndpoints(registry: StompEndpointRegistry) { - registry.addEndpoint("/seven-wonders-websocket") + registry.addEndpoint(SEVEN_WONDERS_WS_ENDPOINT) .setHandshakeHandler(handshakeHandler()) .setAllowedOrigins("http://localhost:3000") // to allow frontend server proxy requests in dev mode .withSockJS() 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 d98e932e..472e5529 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,25 +1,36 @@ package org.luxons.sevenwonders.test.api +import com.fasterxml.jackson.databind.module.SimpleModule +import org.hildan.jackstomp.JackstompClient +import org.luxons.sevenwonders.config.SEVEN_WONDERS_WS_ENDPOINT +import org.luxons.sevenwonders.game.resources.MutableResources +import org.luxons.sevenwonders.game.resources.Resources +import org.springframework.messaging.converter.MappingJackson2MessageConverter import java.util.concurrent.ExecutionException import java.util.concurrent.TimeoutException -import org.hildan.jackstomp.JackstompClient -import org.hildan.jackstomp.JackstompSession +class SevenWondersClient { + + private val client: JackstompClient -class SevenWondersClient @JvmOverloads constructor(private val client: JackstompClient = JackstompClient()) { + init { + val customMappingsModule = SimpleModule("ConcreteResourcesDeserializationModule") + customMappingsModule.addAbstractTypeMapping(Resources::class.java, MutableResources::class.java) + + val mappingJackson2MessageConverter = MappingJackson2MessageConverter() + mappingJackson2MessageConverter.objectMapper.registerModule(customMappingsModule) + + client = JackstompClient() + client.webSocketClient.messageConverter = mappingJackson2MessageConverter + } @Throws(InterruptedException::class, ExecutionException::class, TimeoutException::class) fun connect(serverUrl: String): SevenWondersSession { - val session = client.connect(serverUrl + WEBSOCKET_ENDPOINT) + val session = client.syncConnect(serverUrl + SEVEN_WONDERS_WS_ENDPOINT) return SevenWondersSession(session) } fun stop() { client.stop() } - - companion object { - - private val WEBSOCKET_ENDPOINT = "/seven-wonders-websocket" - } } |