Polishing spring-websocket tests

This commit is contained in:
rstoyanchev
2023-09-11 13:13:06 +01:00
parent 19588d413d
commit f51838b6ba
4 changed files with 40 additions and 25 deletions

View File

@@ -55,12 +55,11 @@ import static org.junit.jupiter.params.provider.Arguments.arguments;
*/
public abstract class AbstractWebSocketIntegrationTests {
private static Map<Class<?>, Class<?>> upgradeStrategyConfigTypes = Map.of(
JettyWebSocketTestServer.class, JettyUpgradeStrategyConfig.class, //
TomcatWebSocketTestServer.class, TomcatUpgradeStrategyConfig.class, //
private static final Map<Class<?>, Class<?>> upgradeStrategyConfigTypes = Map.of(
JettyWebSocketTestServer.class, JettyUpgradeStrategyConfig.class,
TomcatWebSocketTestServer.class, TomcatUpgradeStrategyConfig.class,
UndertowTestServer.class, UndertowUpgradeStrategyConfig.class);
@SuppressWarnings("removal")
static Stream<Arguments> argumentsFactory() {
return Stream.of(
arguments(named("Tomcat", new TomcatWebSocketTestServer()), named("Standard", new StandardWebSocketClient())),
@@ -112,7 +111,7 @@ public abstract class AbstractWebSocketIntegrationTests {
protected abstract Class<?>[] getAnnotatedConfigClasses();
@AfterEach
void teardown() throws Exception {
void teardown() {
try {
if (this.webSocketClient instanceof Lifecycle) {
((Lifecycle) this.webSocketClient).stop();

View File

@@ -53,25 +53,27 @@ class WebSocketHandshakeTests extends AbstractWebSocketIntegrationTests {
@ParameterizedWebSocketTest
@SuppressWarnings("deprecation")
void subProtocolNegotiation(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
void subProtocolNegotiation(
WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
super.setup(server, webSocketClient, testInfo);
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
headers.setSecWebSocketProtocol("foo");
URI url = URI.create(getWsBaseUrl() + "/ws");
WebSocketSession session = this.webSocketClient.doHandshake(new TextWebSocketHandler(), headers, url).get();
WebSocketSession session = this.webSocketClient.execute(new TextWebSocketHandler(), headers, url).get();
assertThat(session.getAcceptedProtocol()).isEqualTo("foo");
session.close();
}
@ParameterizedWebSocketTest // SPR-12727
@SuppressWarnings("deprecation")
void unsolicitedPongWithEmptyPayload(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
void unsolicitedPongWithEmptyPayload(
WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
super.setup(server, webSocketClient, testInfo);
String url = getWsBaseUrl() + "/ws";
WebSocketSession session = this.webSocketClient.doHandshake(new AbstractWebSocketHandler() {}, url).get();
WebSocketSession session = this.webSocketClient.execute(new AbstractWebSocketHandler() {}, url).get();
TestWebSocketHandler serverHandler = this.wac.getBean(TestWebSocketHandler.class);
serverHandler.setWaitMessageCount(1);
@@ -129,7 +131,7 @@ class WebSocketHandshakeTests extends AbstractWebSocketIntegrationTests {
}
@Override
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) {
this.receivedMessages.add(message);
if (this.receivedMessages.size() >= this.waitMessageCount) {
this.latch.countDown();
@@ -137,7 +139,7 @@ class WebSocketHandshakeTests extends AbstractWebSocketIntegrationTests {
}
@Override
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
public void handleTransportError(WebSocketSession session, Throwable exception) {
this.transportError = exception;
this.latch.countDown();
}

View File

@@ -49,11 +49,12 @@ class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTests {
@ParameterizedWebSocketTest
@SuppressWarnings("deprecation")
void registerWebSocketHandler(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
void registerWebSocketHandler(
WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
super.setup(server, webSocketClient, testInfo);
WebSocketSession session = this.webSocketClient.doHandshake(
WebSocketSession session = this.webSocketClient.execute(
new AbstractWebSocketHandler() {}, getWsBaseUrl() + "/ws").get();
TestHandler serverHandler = this.wac.getBean(TestHandler.class);
@@ -63,11 +64,12 @@ class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTests {
}
@ParameterizedWebSocketTest
@SuppressWarnings("deprecation")
void registerWebSocketHandlerWithSockJS(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
void registerWebSocketHandlerWithSockJS(
WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
super.setup(server, webSocketClient, testInfo);
WebSocketSession session = this.webSocketClient.doHandshake(
WebSocketSession session = this.webSocketClient.execute(
new AbstractWebSocketHandler() {}, getWsBaseUrl() + "/sockjs/websocket").get();
TestHandler serverHandler = this.wac.getBean(TestHandler.class);

View File

@@ -74,7 +74,9 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
@ParameterizedWebSocketTest
void sendMessageToController(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
void sendMessageToController(
WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
super.setup(server, webSocketClient, testInfo);
TextMessage message = create(StompCommand.SEND).headers("destination:/app/simple").build();
@@ -87,7 +89,9 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
}
@ParameterizedWebSocketTest
void sendMessageToControllerAndReceiveReplyViaTopic(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
void sendMessageToControllerAndReceiveReplyViaTopic(
WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
super.setup(server, webSocketClient, testInfo);
TextMessage m0 = create(StompCommand.CONNECT).headers("accept-version:1.1").build();
@@ -105,7 +109,9 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
}
@ParameterizedWebSocketTest // SPR-10930
void sendMessageToBrokerAndReceiveReplyViaTopicWithSelectorHeader(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
void sendMessageToBrokerAndReceiveReplyViaTopicWithSelectorHeader(
WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
super.setup(server, webSocketClient, testInfo);
String destination = "destination:/topic/foo";
@@ -127,7 +133,9 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
}
@ParameterizedWebSocketTest // SPR-11648
void sendSubscribeToControllerAndReceiveReply(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
void sendSubscribeToControllerAndReceiveReply(
WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
super.setup(server, webSocketClient, testInfo);
TextMessage m0 = create(StompCommand.CONNECT).headers("accept-version:1.1").build();
@@ -146,7 +154,9 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
}
@ParameterizedWebSocketTest
void handleExceptionAndSendToUser(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
void handleExceptionAndSendToUser(
WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
super.setup(server, webSocketClient, testInfo);
String destHeader = "destination:/user/queue/error";
@@ -167,7 +177,9 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
}
@ParameterizedWebSocketTest
void webSocketScope(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
void webSocketScope(
WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
super.setup(server, webSocketClient, testInfo);
TextMessage m0 = create(StompCommand.CONNECT).headers("accept-version:1.1").build();