diff --git a/extensions/websockets/server/deployment/src/test/java/io/quarkus/websockets/test/WebsocketRootPathTestCase.java b/extensions/websockets/server/deployment/src/test/java/io/quarkus/websockets/test/WebsocketRootPathTestCase.java new file mode 100644 index 0000000000000..ff0ad1904607d --- /dev/null +++ b/extensions/websockets/server/deployment/src/test/java/io/quarkus/websockets/test/WebsocketRootPathTestCase.java @@ -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 message = new LinkedBlockingDeque<>(); + Session session = ContainerProvider.getWebSocketContainer().connectToServer(new Endpoint() { + @Override + public void onOpen(Session session, EndpointConfig endpointConfig) { + session.addMessageHandler(new MessageHandler.Whole() { + @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(); + } + } +}