-
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.
WebSockets Next: fix OnOpen callback that returns Buffer/byte[]
- this callback should send a binary message
- Loading branch information
Showing
3 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
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
71 changes: 71 additions & 0 deletions
71
...rc/test/java/io/quarkus/websockets/next/test/onopenreturntypes/OnOpenReturnTypesTest.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,71 @@ | ||
package io.quarkus.websockets.next.test.onopenreturntypes; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.net.URI; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
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; | ||
import io.quarkus.websockets.next.OnOpen; | ||
import io.quarkus.websockets.next.WebSocket; | ||
import io.quarkus.websockets.next.WebSocketConnection; | ||
import io.quarkus.websockets.next.test.utils.WSClient; | ||
import io.quarkus.websockets.next.test.utils.WSClient.ReceiverMode; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.buffer.Buffer; | ||
|
||
public class OnOpenReturnTypesTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(EndpointText.class, EndpointBinary.class, WSClient.class); | ||
}); | ||
|
||
@Inject | ||
Vertx vertx; | ||
|
||
@TestHTTPResource("end-text") | ||
URI endText; | ||
|
||
@TestHTTPResource("end-binary") | ||
URI endBinary; | ||
|
||
@Test | ||
void testReturnTypes() throws Exception { | ||
try (WSClient textClient = WSClient.create(vertx, ReceiverMode.TEXT).connect(endText)) { | ||
textClient.waitForMessages(1); | ||
assertEquals("/end-text", textClient.getMessages().get(0).toString()); | ||
} | ||
try (WSClient binaryClient = WSClient.create(vertx, ReceiverMode.BINARY).connect(endBinary)) { | ||
binaryClient.waitForMessages(1); | ||
assertEquals("/end-binary", binaryClient.getMessages().get(0).toString()); | ||
} | ||
} | ||
|
||
@WebSocket(path = "/end-text") | ||
public static class EndpointText { | ||
|
||
@OnOpen | ||
String open(WebSocketConnection connection) { | ||
return connection.handshakeRequest().path(); | ||
} | ||
|
||
} | ||
|
||
@WebSocket(path = "/end-binary") | ||
public static class EndpointBinary { | ||
|
||
@OnOpen | ||
Buffer open(WebSocketConnection connection) { | ||
return Buffer.buffer(connection.handshakeRequest().path()); | ||
} | ||
|
||
} | ||
|
||
} |
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