forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebSockets Next: add test that UpgradeRejectedException is thrown
- when WebSocketConnector#connectAndAwait() is called and the upgrade failed - added ClientUpgradeFailureTest
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...oyment/src/test/java/io/quarkus/websockets/next/test/client/ClientUpgradeFailureTest.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,79 @@ | ||
package io.quarkus.websockets.next.test.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.net.URI; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
|
||
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.HttpUpgradeCheck; | ||
import io.quarkus.websockets.next.OnOpen; | ||
import io.quarkus.websockets.next.WebSocket; | ||
import io.quarkus.websockets.next.WebSocketClient; | ||
import io.quarkus.websockets.next.WebSocketConnector; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.core.http.UpgradeRejectedException; | ||
|
||
public class ClientUpgradeFailureTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> { | ||
root.addClasses(ServerEndpoint.class, ClientEndpoint.class, AlwaysFailing.class); | ||
}); | ||
|
||
@Inject | ||
WebSocketConnector<ClientEndpoint> connector; | ||
|
||
@TestHTTPResource("/") | ||
URI uri; | ||
|
||
@Test | ||
public void testClient() throws InterruptedException { | ||
UpgradeRejectedException e = assertThrows(UpgradeRejectedException.class, () -> connector.baseUri(uri).connectAndAwait()); | ||
assertEquals(500, e.getStatus()); | ||
assertTrue(AlwaysFailing.REJECTED.get()); | ||
} | ||
|
||
@WebSocket(path = "/end") | ||
public static class ServerEndpoint { | ||
|
||
@OnOpen | ||
String open() { | ||
return "Hello!"; | ||
} | ||
} | ||
|
||
@Singleton | ||
public static class AlwaysFailing implements HttpUpgradeCheck { | ||
|
||
static final AtomicBoolean REJECTED = new AtomicBoolean(); | ||
|
||
@Override | ||
public Uni<CheckResult> perform(HttpUpgradeContext context) { | ||
REJECTED.set(true); | ||
return CheckResult.rejectUpgrade(500); | ||
} | ||
|
||
} | ||
|
||
@WebSocketClient(path = "/end") | ||
public static class ClientEndpoint { | ||
|
||
@OnOpen | ||
String open() { | ||
return "Hello!"; | ||
} | ||
|
||
} | ||
|
||
} |