Skip to content

Commit

Permalink
Add test for websocket+HTTP root path
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored and gsmet committed Apr 26, 2022
1 parent 7c37451 commit f79e231
Showing 1 changed file with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.quarkus.websockets.test;

import java.net.URI;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

import javax.websocket.ClientEndpointConfig;
import javax.websocket.ContainerProvider;
import javax.websocket.Endpoint;
import javax.websocket.EndpointConfig;
import javax.websocket.MessageHandler;
import javax.websocket.Session;

import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.quarkus.test.common.http.TestHTTPResource;

/**
* smoke test that websockets work as expected in dev mode
*/
public class WebsocketRootPathTestCase {

@TestHTTPResource("foo/echo")
URI echoUri;

@RegisterExtension
public static final QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot(a -> {
a.addClasses(EchoWebSocket.class, EchoService.class)
.add(new StringAsset("quarkus.http.root-path=/foo"), "application.properties");
});

@Test
public void testHttpRootPath() throws Exception {

LinkedBlockingDeque<String> message = new LinkedBlockingDeque<>();
Session session = ContainerProvider.getWebSocketContainer().connectToServer(new Endpoint() {
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
session.addMessageHandler(new MessageHandler.Whole<String>() {
@Override
public void onMessage(String s) {
message.add(s);
}
});
session.getAsyncRemote().sendText("hello");
}
}, ClientEndpointConfig.Builder.create().build(), echoUri);

try {
Assertions.assertEquals("hello", message.poll(20, TimeUnit.SECONDS));
} finally {
session.close();
}
}
}

0 comments on commit f79e231

Please sign in to comment.