Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions misk/src/test/kotlin/misk/web/WebSocketsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ internal class WebSocketsTest {
assertThat(logCollector.takeMessages(RequestLoggingInterceptor::class)).isEmpty()
}

@Test
fun queryArgumentsAreParsedCorrectly() {
val client = OkHttpClient()

val request = Request.Builder()
.url(
jettyService.httpServerUrl
.resolve("/echo-with-query-args?first=this&second=that&second=those")!!
)
.build()

val webSocket = client.newWebSocket(request, listener)

webSocket.send("hello")
assertEquals("ACK hello: this [that, those]", listener.takeMessage())
}

class TestModule : KAbstractModule() {
override fun configure() {
install(WebServerTestingModule())
Expand Down Expand Up @@ -106,4 +123,21 @@ class EchoWebSocket @Inject constructor() : WebAction {
override fun toString() = "EchoListener"
}
}

@ConnectWebSocket("/echo-with-query-args")
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
fun echoWithQueryArgs(
@QueryParam("first") first: String?,
@QueryParam("second") second: List<String>,
@Suppress("UNUSED_PARAMETER") webSocket: WebSocket
): WebSocketListener {
return object : WebSocketListener() {
override fun onMessage(webSocket: WebSocket, text: String) {
webSocket.send("ACK $text: $first $second")
}

override fun toString() = "EchoListener"
}
}

}