Browse Source

Polishing spring-websocket tests

pull/31206/head
rstoyanchev 3 years ago
parent
commit
f51838b6ba
  1. 9
      spring-websocket/src/test/java/org/springframework/web/socket/AbstractWebSocketIntegrationTests.java
  2. 18
      spring-websocket/src/test/java/org/springframework/web/socket/WebSocketHandshakeTests.java
  3. 14
      spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationTests.java
  4. 24
      spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java

9
spring-websocket/src/test/java/org/springframework/web/socket/AbstractWebSocketIntegrationTests.java

@ -55,12 +55,11 @@ import static org.junit.jupiter.params.provider.Arguments.arguments; @@ -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 { @@ -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();

18
spring-websocket/src/test/java/org/springframework/web/socket/WebSocketHandshakeTests.java

@ -53,25 +53,27 @@ class WebSocketHandshakeTests extends AbstractWebSocketIntegrationTests { @@ -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 { @@ -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 { @@ -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();
}

14
spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationTests.java

@ -49,11 +49,12 @@ class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTests { @@ -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 { @@ -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);

24
spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java

@ -74,7 +74,9 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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();

Loading…
Cancel
Save