-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25156 from stuartwdouglas/websockets-http-root
Add test for websocket+HTTP root path
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...server/deployment/src/test/java/io/quarkus/websockets/test/WebsocketRootPathTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |