Clean up warnings and polishing
This commit is contained in:
@@ -166,7 +166,7 @@ public abstract class AbstractWebSocketIntegrationTests {
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class JettyUpgradeStrategyConfig extends AbstractRequestUpgradeStrategyConfig {
|
||||
|
||||
@Override
|
||||
@@ -177,7 +177,7 @@ public abstract class AbstractWebSocketIntegrationTests {
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class TomcatUpgradeStrategyConfig extends AbstractRequestUpgradeStrategyConfig {
|
||||
|
||||
@Override
|
||||
@@ -188,7 +188,7 @@ public abstract class AbstractWebSocketIntegrationTests {
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class UndertowUpgradeStrategyConfig extends AbstractRequestUpgradeStrategyConfig {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -53,6 +53,7 @@ class WebSocketHandshakeTests extends AbstractWebSocketIntegrationTests {
|
||||
|
||||
|
||||
@ParameterizedWebSocketTest
|
||||
@SuppressWarnings("deprecation")
|
||||
void subProtocolNegotiation(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
|
||||
super.setup(server, webSocketClient, testInfo);
|
||||
|
||||
@@ -65,6 +66,7 @@ class WebSocketHandshakeTests extends AbstractWebSocketIntegrationTests {
|
||||
}
|
||||
|
||||
@ParameterizedWebSocketTest // SPR-12727
|
||||
@SuppressWarnings("deprecation")
|
||||
void unsolicitedPongWithEmptyPayload(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
|
||||
super.setup(server, webSocketClient, testInfo);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -68,6 +68,7 @@ public class StandardWebSocketClientTests {
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testGetLocalAddress() throws Exception {
|
||||
URI uri = new URI("ws://localhost/abc");
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
@@ -77,6 +78,7 @@ public class StandardWebSocketClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testGetLocalAddressWss() throws Exception {
|
||||
URI uri = new URI("wss://localhost/abc");
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
@@ -86,6 +88,7 @@ public class StandardWebSocketClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testGetLocalAddressNoScheme() throws Exception {
|
||||
URI uri = new URI("localhost/abc");
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
@@ -93,6 +96,7 @@ public class StandardWebSocketClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testGetRemoteAddress() throws Exception {
|
||||
URI uri = new URI("wss://localhost/abc");
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
@@ -103,8 +107,8 @@ public class StandardWebSocketClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void handshakeHeaders() throws Exception {
|
||||
|
||||
URI uri = new URI("ws://localhost/abc");
|
||||
List<String> protocols = Collections.singletonList("abc");
|
||||
this.headers.setSecWebSocketProtocol(protocols);
|
||||
@@ -117,8 +121,8 @@ public class StandardWebSocketClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void clientEndpointConfig() throws Exception {
|
||||
|
||||
URI uri = new URI("ws://localhost/abc");
|
||||
List<String> protocols = Collections.singletonList("abc");
|
||||
this.headers.setSecWebSocketProtocol(protocols);
|
||||
@@ -133,8 +137,8 @@ public class StandardWebSocketClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void clientEndpointConfigWithUserProperties() throws Exception {
|
||||
|
||||
Map<String,Object> userProperties = Collections.singletonMap("foo", "bar");
|
||||
|
||||
URI uri = new URI("ws://localhost/abc");
|
||||
@@ -149,8 +153,8 @@ public class StandardWebSocketClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void standardWebSocketClientConfiguratorInsertsHandshakeHeaders() throws Exception {
|
||||
|
||||
URI uri = new URI("ws://localhost/abc");
|
||||
this.headers.add("foo", "bar");
|
||||
|
||||
@@ -166,8 +170,8 @@ public class StandardWebSocketClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void taskExecutor() throws Exception {
|
||||
|
||||
URI uri = new URI("ws://localhost/abc");
|
||||
this.wsClient.setTaskExecutor(new SimpleAsyncTaskExecutor());
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,6 +49,7 @@ class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTests {
|
||||
|
||||
|
||||
@ParameterizedWebSocketTest
|
||||
@SuppressWarnings("deprecation")
|
||||
void registerWebSocketHandler(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
|
||||
super.setup(server, webSocketClient, testInfo);
|
||||
|
||||
@@ -62,6 +63,7 @@ class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTests {
|
||||
}
|
||||
|
||||
@ParameterizedWebSocketTest
|
||||
@SuppressWarnings("deprecation")
|
||||
void registerWebSocketHandlerWithSockJS(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception {
|
||||
super.setup(server, webSocketClient, testInfo);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -109,8 +109,8 @@ class WebSocketStompClientIntegrationTests {
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void publishSubscribe() throws Exception {
|
||||
|
||||
String url = "ws://127.0.0.1:" + this.server.getPort() + "/stomp";
|
||||
|
||||
TestHandler testHandler = new TestHandler("/topic/foo", "payload");
|
||||
@@ -121,7 +121,7 @@ class WebSocketStompClientIntegrationTests {
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class TestConfig extends WebSocketMessageBrokerConfigurationSupport {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,8 +51,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.testfixture.EnabledForTestGroups;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
@@ -79,7 +77,7 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
@EnabledForTestGroups(LONG_RUNNING)
|
||||
public abstract class AbstractSockJsIntegrationTests {
|
||||
abstract class AbstractSockJsIntegrationTests {
|
||||
|
||||
protected Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
@@ -96,7 +94,7 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(TestInfo testInfo) throws Exception {
|
||||
void setup(TestInfo testInfo) throws Exception {
|
||||
logger.debug("Setting up '" + testInfo.getTestMethod().get().getName() + "'");
|
||||
|
||||
this.testFilter = new TestFilter();
|
||||
@@ -116,7 +114,7 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void teardown() throws Exception {
|
||||
void teardown() throws Exception {
|
||||
try {
|
||||
this.sockJsClient.stop();
|
||||
}
|
||||
@@ -157,17 +155,17 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void echoWebSocket() throws Exception {
|
||||
void echoWebSocket() throws Exception {
|
||||
testEcho(100, createWebSocketTransport(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void echoXhrStreaming() throws Exception {
|
||||
void echoXhrStreaming() throws Exception {
|
||||
testEcho(100, createXhrTransport(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void echoXhr() throws Exception {
|
||||
void echoXhr() throws Exception {
|
||||
AbstractXhrTransport xhrTransport = createXhrTransport();
|
||||
xhrTransport.setXhrStreamingDisabled(true);
|
||||
testEcho(100, xhrTransport, null);
|
||||
@@ -176,7 +174,7 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
// SPR-13254
|
||||
|
||||
@Test
|
||||
public void echoXhrWithHeaders() throws Exception {
|
||||
void echoXhrWithHeaders() throws Exception {
|
||||
AbstractXhrTransport xhrTransport = createXhrTransport();
|
||||
xhrTransport.setXhrStreamingDisabled(true);
|
||||
|
||||
@@ -191,30 +189,31 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveOneMessageWebSocket() throws Exception {
|
||||
void receiveOneMessageWebSocket() throws Exception {
|
||||
testReceiveOneMessage(createWebSocketTransport(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveOneMessageXhrStreaming() throws Exception {
|
||||
void receiveOneMessageXhrStreaming() throws Exception {
|
||||
testReceiveOneMessage(createXhrTransport(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveOneMessageXhr() throws Exception {
|
||||
void receiveOneMessageXhr() throws Exception {
|
||||
AbstractXhrTransport xhrTransport = createXhrTransport();
|
||||
xhrTransport.setXhrStreamingDisabled(true);
|
||||
testReceiveOneMessage(xhrTransport, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void infoRequestFailure() throws Exception {
|
||||
@SuppressWarnings("deprecation")
|
||||
void infoRequestFailure() throws Exception {
|
||||
TestClientHandler handler = new TestClientHandler();
|
||||
this.testFilter.sendErrorMap.put("/info", 500);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
initSockJsClient(createWebSocketTransport());
|
||||
this.sockJsClient.doHandshake(handler, this.baseUrl + "/echo").addCallback(
|
||||
new ListenableFutureCallback<WebSocketSession>() {
|
||||
new org.springframework.util.concurrent.ListenableFutureCallback<WebSocketSession>() {
|
||||
@Override
|
||||
public void onSuccess(WebSocketSession result) {
|
||||
}
|
||||
@@ -229,12 +228,12 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fallbackAfterTransportFailure() throws Exception {
|
||||
void fallbackAfterTransportFailure() throws Exception {
|
||||
this.testFilter.sendErrorMap.put("/websocket", 200);
|
||||
this.testFilter.sendErrorMap.put("/xhr_streaming", 500);
|
||||
TestClientHandler handler = new TestClientHandler();
|
||||
initSockJsClient(createWebSocketTransport(), createXhrTransport());
|
||||
WebSocketSession session = this.sockJsClient.doHandshake(handler, this.baseUrl + "/echo").get();
|
||||
WebSocketSession session = this.sockJsClient.execute(handler, this.baseUrl + "/echo").get();
|
||||
assertThat(session.getClass()).as("Fallback didn't occur").isEqualTo(XhrClientSockJsSession.class);
|
||||
TextMessage message = new TextMessage("message1");
|
||||
session.sendMessage(message);
|
||||
@@ -243,12 +242,13 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
|
||||
@Test
|
||||
@Timeout(5)
|
||||
public void fallbackAfterConnectTimeout() throws Exception {
|
||||
@SuppressWarnings("deprecation")
|
||||
void fallbackAfterConnectTimeout() throws Exception {
|
||||
TestClientHandler clientHandler = new TestClientHandler();
|
||||
this.testFilter.sleepDelayMap.put("/xhr_streaming", 10000L);
|
||||
this.testFilter.sendErrorMap.put("/xhr_streaming", 503);
|
||||
initSockJsClient(createXhrTransport());
|
||||
this.sockJsClient.setConnectTimeoutScheduler(this.wac.getBean(ThreadPoolTaskScheduler.class));
|
||||
// this.sockJsClient.setConnectTimeoutScheduler(this.wac.getBean(ThreadPoolTaskScheduler.class));
|
||||
WebSocketSession clientSession = sockJsClient.doHandshake(clientHandler, this.baseUrl + "/echo").get();
|
||||
assertThat(clientSession.getClass()).as("Fallback didn't occur").isEqualTo(XhrClientSockJsSession.class);
|
||||
TextMessage message = new TextMessage("message1");
|
||||
@@ -258,6 +258,7 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void testEcho(int messageCount, Transport transport, WebSocketHttpHeaders headers) throws Exception {
|
||||
List<TextMessage> messages = new ArrayList<>();
|
||||
for (int i = 0; i < messageCount; i++) {
|
||||
@@ -278,6 +279,7 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
session.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void testReceiveOneMessage(Transport transport, WebSocketHttpHeaders headers)
|
||||
throws Exception {
|
||||
|
||||
@@ -311,7 +313,7 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableWebSocket
|
||||
static class TestConfig implements WebSocketConfigurer {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,7 @@ import org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategy;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class JettySockJsIntegrationTests extends AbstractSockJsIntegrationTests {
|
||||
class JettySockJsIntegrationTests extends AbstractSockJsIntegrationTests {
|
||||
|
||||
@Override
|
||||
protected Class<?> upgradeStrategyConfigClass() {
|
||||
@@ -53,10 +53,10 @@ public class JettySockJsIntegrationTests extends AbstractSockJsIntegrationTests
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class JettyTestConfig {
|
||||
@Bean
|
||||
public RequestUpgradeStrategy upgradeStrategy() {
|
||||
RequestUpgradeStrategy upgradeStrategy() {
|
||||
return new JettyRequestUpgradeStrategy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,8 +40,6 @@ import org.springframework.messaging.simp.stomp.StompCommand;
|
||||
import org.springframework.messaging.simp.stomp.StompEncoder;
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
import org.springframework.web.client.RequestCallback;
|
||||
import org.springframework.web.client.ResponseExtractor;
|
||||
@@ -124,6 +122,7 @@ public class RestTemplateXhrTransportTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void connectFailure() throws Exception {
|
||||
final HttpServerErrorException expected = new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
RestOperations restTemplate = mock(RestOperations.class);
|
||||
@@ -131,7 +130,7 @@ public class RestTemplateXhrTransportTests {
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
connect(restTemplate).addCallback(
|
||||
new ListenableFutureCallback<WebSocketSession>() {
|
||||
new org.springframework.util.concurrent.ListenableFutureCallback<WebSocketSession>() {
|
||||
@Override
|
||||
public void onSuccess(WebSocketSession result) {
|
||||
}
|
||||
@@ -168,12 +167,15 @@ public class RestTemplateXhrTransportTests {
|
||||
verify(response).close();
|
||||
}
|
||||
|
||||
private ListenableFuture<WebSocketSession> connect(ClientHttpResponse... responses) throws Exception {
|
||||
@SuppressWarnings("deprecation")
|
||||
private org.springframework.util.concurrent.ListenableFuture<WebSocketSession> connect(
|
||||
ClientHttpResponse... responses) throws Exception {
|
||||
return connect(new TestRestTemplate(responses));
|
||||
}
|
||||
|
||||
private ListenableFuture<WebSocketSession> connect(RestOperations restTemplate, ClientHttpResponse... responses)
|
||||
throws Exception {
|
||||
@SuppressWarnings("deprecation")
|
||||
private org.springframework.util.concurrent.ListenableFuture<WebSocketSession> connect(
|
||||
RestOperations restTemplate, ClientHttpResponse... responses) throws Exception {
|
||||
|
||||
RestTemplateXhrTransport transport = new RestTemplateXhrTransport(restTemplate);
|
||||
transport.setTaskExecutor(new SyncTaskExecutor());
|
||||
@@ -201,7 +203,6 @@ public class RestTemplateXhrTransportTests {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class TestRestTemplate extends RestTemplate {
|
||||
|
||||
private Queue<ClientHttpResponse> responses = new LinkedBlockingDeque<>();
|
||||
@@ -225,5 +226,4 @@ public class RestTemplateXhrTransportTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.web.socket.sockjs.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -27,7 +26,6 @@ import org.mockito.ArgumentCaptor;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
@@ -43,46 +41,38 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.springframework.web.socket.sockjs.client.SockJsClient}.
|
||||
* Unit tests for {@link SockJsClient}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class SockJsClientTests {
|
||||
class SockJsClientTests {
|
||||
|
||||
private static final String URL = "https://example.com";
|
||||
|
||||
private static final WebSocketHandler handler = mock(WebSocketHandler.class);
|
||||
|
||||
|
||||
private SockJsClient sockJsClient;
|
||||
private final InfoReceiver infoReceiver = mock(InfoReceiver.class);
|
||||
|
||||
private InfoReceiver infoReceiver;
|
||||
private final TestTransport webSocketTransport = new TestTransport("WebSocketTestTransport");
|
||||
|
||||
private TestTransport webSocketTransport;
|
||||
private final XhrTestTransport xhrTransport = new XhrTestTransport("XhrTestTransport");
|
||||
|
||||
private XhrTestTransport xhrTransport;
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
private org.springframework.util.concurrent.ListenableFutureCallback<WebSocketSession> connectCallback =
|
||||
mock(org.springframework.util.concurrent.ListenableFutureCallback.class);
|
||||
|
||||
private ListenableFutureCallback<WebSocketSession> connectCallback;
|
||||
private SockJsClient sockJsClient = new SockJsClient(List.of(this.webSocketTransport, this.xhrTransport));
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setup() {
|
||||
this.infoReceiver = mock(InfoReceiver.class);
|
||||
this.webSocketTransport = new TestTransport("WebSocketTestTransport");
|
||||
this.xhrTransport = new XhrTestTransport("XhrTestTransport");
|
||||
|
||||
List<Transport> transports = new ArrayList<>();
|
||||
transports.add(this.webSocketTransport);
|
||||
transports.add(this.xhrTransport);
|
||||
this.sockJsClient = new SockJsClient(transports);
|
||||
void setup() {
|
||||
this.sockJsClient.setInfoReceiver(this.infoReceiver);
|
||||
|
||||
this.connectCallback = mock(ListenableFutureCallback.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectWebSocket() throws Exception {
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectWebSocket() throws Exception {
|
||||
setupInfoRequest(true);
|
||||
this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback);
|
||||
assertThat(this.webSocketTransport.invoked()).isTrue();
|
||||
@@ -93,7 +83,8 @@ public class SockJsClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectWebSocketDisabled() throws URISyntaxException {
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectWebSocketDisabled() throws URISyntaxException {
|
||||
setupInfoRequest(false);
|
||||
this.sockJsClient.doHandshake(handler, URL);
|
||||
assertThat(this.webSocketTransport.invoked()).isFalse();
|
||||
@@ -102,7 +93,8 @@ public class SockJsClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectXhrStreamingDisabled() throws Exception {
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectXhrStreamingDisabled() throws Exception {
|
||||
setupInfoRequest(false);
|
||||
this.xhrTransport.setStreamingDisabled(true);
|
||||
this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback);
|
||||
@@ -111,10 +103,9 @@ public class SockJsClientTests {
|
||||
assertThat(this.xhrTransport.getRequest().getTransportUrl().toString().endsWith("xhr")).isTrue();
|
||||
}
|
||||
|
||||
// SPR-13254
|
||||
|
||||
@Test
|
||||
public void connectWithHandshakeHeaders() throws Exception {
|
||||
@Test // SPR-13254
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectWithHandshakeHeaders() throws Exception {
|
||||
ArgumentCaptor<HttpHeaders> headersCaptor = setupInfoRequest(false);
|
||||
this.xhrTransport.setStreamingDisabled(true);
|
||||
|
||||
@@ -135,7 +126,8 @@ public class SockJsClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectAndUseSubsetOfHandshakeHeadersForHttpRequests() throws Exception {
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectAndUseSubsetOfHandshakeHeadersForHttpRequests() throws Exception {
|
||||
ArgumentCaptor<HttpHeaders> headersCaptor = setupInfoRequest(false);
|
||||
this.xhrTransport.setStreamingDisabled(true);
|
||||
|
||||
@@ -152,14 +144,16 @@ public class SockJsClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectSockJsInfo() throws Exception {
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectSockJsInfo() throws Exception {
|
||||
setupInfoRequest(true);
|
||||
this.sockJsClient.doHandshake(handler, URL);
|
||||
verify(this.infoReceiver, times(1)).executeInfoRequest(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectSockJsInfoCached() throws Exception {
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectSockJsInfoCached() throws Exception {
|
||||
setupInfoRequest(true);
|
||||
this.sockJsClient.doHandshake(handler, URL);
|
||||
this.sockJsClient.doHandshake(handler, URL);
|
||||
@@ -168,7 +162,8 @@ public class SockJsClientTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectInfoRequestFailure() throws URISyntaxException {
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectInfoRequestFailure() throws URISyntaxException {
|
||||
HttpServerErrorException exception = new HttpServerErrorException(HttpStatus.SERVICE_UNAVAILABLE);
|
||||
given(this.infoReceiver.executeInfoRequest(any(), any())).willThrow(exception);
|
||||
this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback);
|
||||
@@ -178,12 +173,15 @@ public class SockJsClientTests {
|
||||
}
|
||||
|
||||
private ArgumentCaptor<HttpHeaders> setupInfoRequest(boolean webSocketEnabled) {
|
||||
String response = """
|
||||
{
|
||||
"entropy": 123,
|
||||
"origins": ["*:*"],
|
||||
"cookie_needed": true,
|
||||
"websocket": %s
|
||||
}""".formatted(webSocketEnabled).replace('\n', '\0');
|
||||
ArgumentCaptor<HttpHeaders> headersCaptor = ArgumentCaptor.forClass(HttpHeaders.class);
|
||||
given(this.infoReceiver.executeInfoRequest(any(), headersCaptor.capture())).willReturn(
|
||||
"{\"entropy\":123," +
|
||||
"\"origins\":[\"*:*\"]," +
|
||||
"\"cookie_needed\":true," +
|
||||
"\"websocket\":" + webSocketEnabled + "}");
|
||||
given(this.infoReceiver.executeInfoRequest(any(), headersCaptor.capture())).willReturn(response);
|
||||
return headersCaptor;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,7 +29,7 @@ import org.springframework.web.socket.server.standard.UndertowRequestUpgradeStra
|
||||
/**
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
public class UndertowSockJsIntegrationTests extends AbstractSockJsIntegrationTests {
|
||||
class UndertowSockJsIntegrationTests extends AbstractSockJsIntegrationTests {
|
||||
|
||||
@Override
|
||||
protected Class<?> upgradeStrategyConfigClass() {
|
||||
@@ -56,11 +56,13 @@ public class UndertowSockJsIntegrationTests extends AbstractSockJsIntegrationTes
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class UndertowTestConfig {
|
||||
@Bean
|
||||
public RequestUpgradeStrategy upgradeStrategy() {
|
||||
RequestUpgradeStrategy upgradeStrategy() {
|
||||
return new UndertowRequestUpgradeStrategy();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,22 +39,21 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Unit tests for
|
||||
* {@link org.springframework.web.socket.sockjs.client.AbstractXhrTransport}.
|
||||
* Unit tests for {@link AbstractXhrTransport}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class XhrTransportTests {
|
||||
class XhrTransportTests {
|
||||
|
||||
@Test
|
||||
public void infoResponse() throws Exception {
|
||||
void infoResponse() throws Exception {
|
||||
TestXhrTransport transport = new TestXhrTransport();
|
||||
transport.infoResponseToReturn = new ResponseEntity<>("body", HttpStatus.OK);
|
||||
assertThat(transport.executeInfoRequest(new URI("https://example.com/info"), null)).isEqualTo("body");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void infoResponseError() throws Exception {
|
||||
void infoResponseError() throws Exception {
|
||||
TestXhrTransport transport = new TestXhrTransport();
|
||||
transport.infoResponseToReturn = new ResponseEntity<>("body", HttpStatus.BAD_REQUEST);
|
||||
assertThatExceptionOfType(HttpServerErrorException.class).isThrownBy(() ->
|
||||
@@ -62,7 +61,7 @@ public class XhrTransportTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendMessage() throws Exception {
|
||||
void sendMessage() throws Exception {
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.set("foo", "bar");
|
||||
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
@@ -76,7 +75,7 @@ public class XhrTransportTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendMessageError() throws Exception {
|
||||
void sendMessageError() throws Exception {
|
||||
TestXhrTransport transport = new TestXhrTransport();
|
||||
transport.sendMessageResponseToReturn = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
URI url = new URI("https://example.com");
|
||||
@@ -85,7 +84,8 @@ public class XhrTransportTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connect() throws Exception {
|
||||
@SuppressWarnings("deprecation")
|
||||
void connect() throws Exception {
|
||||
HttpHeaders handshakeHeaders = new HttpHeaders();
|
||||
handshakeHeaders.setOrigin("foo");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user