Use URI#create instead of URI constructor where feasible in spring-websocket
This commit is contained in:
parent
284cb12f8f
commit
9b38e43c17
|
|
@ -59,7 +59,7 @@ class WebSocketHandshakeTests extends AbstractWebSocketIntegrationTests {
|
|||
|
||||
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
|
||||
headers.setSecWebSocketProtocol("foo");
|
||||
URI url = new URI(getWsBaseUrl() + "/ws");
|
||||
URI url = URI.create(getWsBaseUrl() + "/ws");
|
||||
WebSocketSession session = this.webSocketClient.doHandshake(new TextWebSocketHandler(), headers, url).get();
|
||||
assertThat(session.getAcceptedProtocol()).isEqualTo("foo");
|
||||
session.close();
|
||||
|
|
|
|||
|
|
@ -39,11 +39,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class WebSocketConnectionManagerTests {
|
||||
|
||||
class WebSocketConnectionManagerTests {
|
||||
|
||||
@Test
|
||||
public void openConnection() throws Exception {
|
||||
void openConnection() {
|
||||
List<String> subprotocols = List.of("abc");
|
||||
|
||||
TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
|
||||
|
|
@ -57,7 +56,7 @@ public class WebSocketConnectionManagerTests {
|
|||
expectedHeaders.setSecWebSocketProtocol(subprotocols);
|
||||
|
||||
assertThat(client.headers).isEqualTo(expectedHeaders);
|
||||
assertThat(client.uri).isEqualTo(new URI("/path/123"));
|
||||
assertThat(client.uri).isEqualTo(URI.create("/path/123"));
|
||||
|
||||
WebSocketHandlerDecorator loggingHandler = (WebSocketHandlerDecorator) client.webSocketHandler;
|
||||
assertThat(loggingHandler.getClass()).isEqualTo(LoggingWebSocketHandlerDecorator.class);
|
||||
|
|
@ -66,7 +65,7 @@ public class WebSocketConnectionManagerTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void clientLifecycle() throws Exception {
|
||||
void clientLifecycle() throws Exception {
|
||||
TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
|
||||
WebSocketHandler handler = new TextWebSocketHandler();
|
||||
WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/a");
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import java.util.Map;
|
|||
import jakarta.websocket.ClientEndpointConfig;
|
||||
import jakarta.websocket.Endpoint;
|
||||
import jakarta.websocket.WebSocketContainer;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
|
|
@ -46,31 +45,21 @@ import static org.mockito.Mockito.verify;
|
|||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class StandardWebSocketClientTests {
|
||||
class StandardWebSocketClientTests {
|
||||
|
||||
private StandardWebSocketClient wsClient;
|
||||
private final WebSocketHandler wsHandler = new AbstractWebSocketHandler() {};
|
||||
|
||||
private WebSocketContainer wsContainer;
|
||||
private final WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
|
||||
|
||||
private WebSocketHandler wsHandler;
|
||||
private final WebSocketContainer wsContainer = mock(WebSocketContainer.class);
|
||||
|
||||
private WebSocketHttpHeaders headers;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.headers = new WebSocketHttpHeaders();
|
||||
this.wsHandler = new AbstractWebSocketHandler() {
|
||||
};
|
||||
this.wsContainer = mock(WebSocketContainer.class);
|
||||
this.wsClient = new StandardWebSocketClient(this.wsContainer);
|
||||
}
|
||||
private final StandardWebSocketClient wsClient = new StandardWebSocketClient(this.wsContainer);
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testGetLocalAddress() throws Exception {
|
||||
URI uri = new URI("ws://localhost/abc");
|
||||
void getLocalAddress() throws Exception {
|
||||
URI uri = URI.create("ws://localhost/abc");
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
assertThat(session.getLocalAddress()).isNotNull();
|
||||
|
|
@ -79,8 +68,8 @@ public class StandardWebSocketClientTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testGetLocalAddressWss() throws Exception {
|
||||
URI uri = new URI("wss://localhost/abc");
|
||||
void getLocalAddressWss() throws Exception {
|
||||
URI uri = URI.create("wss://localhost/abc");
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
assertThat(session.getLocalAddress()).isNotNull();
|
||||
|
|
@ -89,16 +78,16 @@ public class StandardWebSocketClientTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testGetLocalAddressNoScheme() throws Exception {
|
||||
URI uri = new URI("localhost/abc");
|
||||
void getLocalAddressNoScheme() {
|
||||
URI uri = URI.create("localhost/abc");
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
this.wsClient.doHandshake(this.wsHandler, this.headers, uri));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testGetRemoteAddress() throws Exception {
|
||||
URI uri = new URI("wss://localhost/abc");
|
||||
void getRemoteAddress() throws Exception {
|
||||
URI uri = URI.create("wss://localhost/abc");
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
assertThat(session.getRemoteAddress()).isNotNull();
|
||||
|
|
@ -108,8 +97,8 @@ public class StandardWebSocketClientTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void handshakeHeaders() throws Exception {
|
||||
URI uri = new URI("ws://localhost/abc");
|
||||
void handshakeHeaders() throws Exception {
|
||||
URI uri = URI.create("ws://localhost/abc");
|
||||
List<String> protocols = Collections.singletonList("abc");
|
||||
this.headers.setSecWebSocketProtocol(protocols);
|
||||
this.headers.add("foo", "bar");
|
||||
|
|
@ -122,8 +111,8 @@ public class StandardWebSocketClientTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void clientEndpointConfig() throws Exception {
|
||||
URI uri = new URI("ws://localhost/abc");
|
||||
void clientEndpointConfig() throws Exception {
|
||||
URI uri = URI.create("ws://localhost/abc");
|
||||
List<String> protocols = Collections.singletonList("abc");
|
||||
this.headers.setSecWebSocketProtocol(protocols);
|
||||
|
||||
|
|
@ -138,10 +127,10 @@ public class StandardWebSocketClientTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void clientEndpointConfigWithUserProperties() throws Exception {
|
||||
void clientEndpointConfigWithUserProperties() throws Exception {
|
||||
Map<String,Object> userProperties = Collections.singletonMap("foo", "bar");
|
||||
|
||||
URI uri = new URI("ws://localhost/abc");
|
||||
URI uri = URI.create("ws://localhost/abc");
|
||||
this.wsClient.setUserProperties(userProperties);
|
||||
this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
|
|
@ -154,8 +143,8 @@ public class StandardWebSocketClientTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void standardWebSocketClientConfiguratorInsertsHandshakeHeaders() throws Exception {
|
||||
URI uri = new URI("ws://localhost/abc");
|
||||
void standardWebSocketClientConfiguratorInsertsHandshakeHeaders() throws Exception {
|
||||
URI uri = URI.create("ws://localhost/abc");
|
||||
this.headers.add("foo", "bar");
|
||||
|
||||
this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
|
|
@ -171,8 +160,8 @@ public class StandardWebSocketClientTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void taskExecutor() throws Exception {
|
||||
URI uri = new URI("ws://localhost/abc");
|
||||
void taskExecutor() throws Exception {
|
||||
URI uri = URI.create("ws://localhost/abc");
|
||||
this.wsClient.setTaskExecutor(new SimpleAsyncTaskExecutor());
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ abstract class AbstractSockJsIntegrationTests {
|
|||
}
|
||||
TestClientHandler handler = new TestClientHandler();
|
||||
initSockJsClient(transport);
|
||||
URI url = new URI(this.baseUrl + "/echo");
|
||||
URI url = URI.create(this.baseUrl + "/echo");
|
||||
WebSocketSession session = this.sockJsClient.doHandshake(handler, headers, url).get();
|
||||
for (TextMessage message : messages) {
|
||||
session.sendMessage(message);
|
||||
|
|
@ -285,7 +285,7 @@ abstract class AbstractSockJsIntegrationTests {
|
|||
|
||||
TestClientHandler clientHandler = new TestClientHandler();
|
||||
initSockJsClient(transport);
|
||||
this.sockJsClient.doHandshake(clientHandler, headers, new URI(this.baseUrl + "/test")).get();
|
||||
this.sockJsClient.doHandshake(clientHandler, headers, URI.create(this.baseUrl + "/test")).get();
|
||||
TestServerHandler serverHandler = this.wac.getBean(TestServerHandler.class);
|
||||
|
||||
assertThat(clientHandler.session).as("afterConnectionEstablished should have been called").isNotNull();
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ClientSockJsSessionTests {
|
||||
class ClientSockJsSessionTests {
|
||||
|
||||
private static final Jackson2SockJsMessageCodec CODEC = new Jackson2SockJsMessageCodec();
|
||||
|
||||
|
|
@ -60,8 +60,8 @@ public class ClientSockJsSessionTests {
|
|||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
SockJsUrlInfo urlInfo = new SockJsUrlInfo(new URI("https://example.com"));
|
||||
void setup() {
|
||||
SockJsUrlInfo urlInfo = new SockJsUrlInfo(URI.create("https://example.com"));
|
||||
Transport transport = mock(Transport.class);
|
||||
TransportRequest request = new DefaultTransportRequest(urlInfo, null, null, transport, TransportType.XHR, CODEC);
|
||||
this.handler = mock(WebSocketHandler.class);
|
||||
|
|
@ -71,7 +71,7 @@ public class ClientSockJsSessionTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void handleFrameOpen() throws Exception {
|
||||
void handleFrameOpen() throws Exception {
|
||||
assertThat(this.session.isOpen()).isFalse();
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
assertThat(this.session.isOpen()).isTrue();
|
||||
|
|
@ -82,7 +82,7 @@ public class ClientSockJsSessionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void handleFrameOpenWhenStatusNotNew() throws Exception {
|
||||
void handleFrameOpenWhenStatusNotNew() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
assertThat(this.session.isOpen()).isTrue();
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
|
|
@ -90,14 +90,14 @@ public class ClientSockJsSessionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void handleFrameOpenWithWebSocketHandlerException() throws Exception {
|
||||
void handleFrameOpenWithWebSocketHandlerException() throws Exception {
|
||||
willThrow(new IllegalStateException("Fake error")).given(this.handler).afterConnectionEstablished(this.session);
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
assertThat(this.session.isOpen()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleFrameMessage() throws Exception {
|
||||
void handleFrameMessage() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.handleFrame(SockJsFrame.messageFrame(CODEC, "foo", "bar").getContent());
|
||||
verify(this.handler).afterConnectionEstablished(this.session);
|
||||
|
|
@ -107,7 +107,7 @@ public class ClientSockJsSessionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void handleFrameMessageWhenNotOpen() throws Exception {
|
||||
void handleFrameMessageWhenNotOpen() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.close();
|
||||
reset(this.handler);
|
||||
|
|
@ -116,7 +116,7 @@ public class ClientSockJsSessionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void handleFrameMessageWithBadData() throws Exception {
|
||||
void handleFrameMessageWithBadData() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.handleFrame("a['bad data");
|
||||
assertThat(this.session.isOpen()).isFalse();
|
||||
|
|
@ -126,7 +126,7 @@ public class ClientSockJsSessionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void handleFrameMessageWithWebSocketHandlerException() throws Exception {
|
||||
void handleFrameMessageWithWebSocketHandlerException() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
willThrow(new IllegalStateException("Fake error")).given(this.handler)
|
||||
.handleMessage(this.session, new TextMessage("foo"));
|
||||
|
|
@ -141,7 +141,7 @@ public class ClientSockJsSessionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void handleFrameClose() throws Exception {
|
||||
void handleFrameClose() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.handleFrame(SockJsFrame.closeFrame(1007, "").getContent());
|
||||
assertThat(this.session.isOpen()).isFalse();
|
||||
|
|
@ -151,7 +151,7 @@ public class ClientSockJsSessionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void handleTransportError() throws Exception {
|
||||
void handleTransportError() throws Exception {
|
||||
final IllegalStateException ex = new IllegalStateException("Fake error");
|
||||
this.session.handleTransportError(ex);
|
||||
verify(this.handler).handleTransportError(this.session, ex);
|
||||
|
|
@ -159,7 +159,7 @@ public class ClientSockJsSessionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void afterTransportClosed() throws Exception {
|
||||
void afterTransportClosed() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.afterTransportClosed(CloseStatus.SERVER_ERROR);
|
||||
assertThat(this.session.isOpen()).isFalse();
|
||||
|
|
@ -169,7 +169,7 @@ public class ClientSockJsSessionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void close() throws Exception {
|
||||
void close() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.close();
|
||||
assertThat(this.session.isOpen()).isFalse();
|
||||
|
|
@ -179,14 +179,14 @@ public class ClientSockJsSessionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void closeWithStatus() throws Exception {
|
||||
void closeWithStatus() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.close(new CloseStatus(3000, "reason"));
|
||||
assertThat(this.session.disconnectStatus).isEqualTo(new CloseStatus(3000, "reason"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closeWithNullStatus() throws Exception {
|
||||
void closeWithNullStatus() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
this.session.close(null))
|
||||
|
|
@ -194,7 +194,7 @@ public class ClientSockJsSessionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void closeWithStatusOutOfRange() throws Exception {
|
||||
void closeWithStatusOutOfRange() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
this.session.close(new CloseStatus(2999, "reason")))
|
||||
|
|
@ -202,13 +202,13 @@ public class ClientSockJsSessionTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void timeoutTask() {
|
||||
void timeoutTask() {
|
||||
this.session.getTimeoutTask().run();
|
||||
assertThat(this.session.disconnectStatus).isEqualTo(new CloseStatus(2007, "Transport timed out"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void send() throws Exception {
|
||||
void send() throws Exception {
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
this.session.sendMessage(new TextMessage("foo"));
|
||||
assertThat(this.session.sentMessage).isEqualTo(new TextMessage("[\"foo\"]"));
|
||||
|
|
|
|||
|
|
@ -45,10 +45,9 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class DefaultTransportRequestTests {
|
||||
|
||||
private static final Jackson2SockJsMessageCodec CODEC = new Jackson2SockJsMessageCodec();
|
||||
class DefaultTransportRequestTests {
|
||||
|
||||
private final Jackson2SockJsMessageCodec CODEC = new Jackson2SockJsMessageCodec();
|
||||
|
||||
private CompletableFuture<WebSocketSession> connectFuture;
|
||||
|
||||
|
|
@ -61,7 +60,7 @@ public class DefaultTransportRequestTests {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
void setup() {
|
||||
this.connectCallback = mock(BiConsumer.class);
|
||||
this.connectFuture = new CompletableFuture<>();
|
||||
this.connectFuture.whenComplete(this.connectCallback);
|
||||
|
|
@ -71,7 +70,7 @@ public class DefaultTransportRequestTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void connect() throws Exception {
|
||||
void connect() throws Exception {
|
||||
DefaultTransportRequest request = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET);
|
||||
request.connect(null, this.connectFuture);
|
||||
WebSocketSession session = mock(WebSocketSession.class);
|
||||
|
|
@ -80,7 +79,7 @@ public class DefaultTransportRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void fallbackAfterTransportError() throws Exception {
|
||||
void fallbackAfterTransportError() {
|
||||
DefaultTransportRequest request1 = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET);
|
||||
DefaultTransportRequest request2 = createTransportRequest(this.xhrTransport, TransportType.XHR_STREAMING);
|
||||
request1.setFallbackRequest(request2);
|
||||
|
|
@ -100,7 +99,7 @@ public class DefaultTransportRequestTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void fallbackAfterTimeout() throws Exception {
|
||||
void fallbackAfterTimeout() {
|
||||
TaskScheduler scheduler = mock(TaskScheduler.class);
|
||||
Runnable sessionCleanupTask = mock(Runnable.class);
|
||||
DefaultTransportRequest request1 = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET);
|
||||
|
|
@ -123,8 +122,8 @@ public class DefaultTransportRequestTests {
|
|||
verify(sessionCleanupTask).run();
|
||||
}
|
||||
|
||||
protected DefaultTransportRequest createTransportRequest(Transport transport, TransportType type) throws Exception {
|
||||
SockJsUrlInfo urlInfo = new SockJsUrlInfo(new URI("https://example.com"));
|
||||
protected DefaultTransportRequest createTransportRequest(Transport transport, TransportType type) {
|
||||
SockJsUrlInfo urlInfo = new SockJsUrlInfo(URI.create("https://example.com"));
|
||||
return new DefaultTransportRequest(urlInfo, new HttpHeaders(), new HttpHeaders(), transport, type, CODEC);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ class RestTemplateXhrTransportTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectFailure() throws Exception {
|
||||
void connectFailure() {
|
||||
final HttpServerErrorException expected = new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
RestOperations restTemplate = mock(RestOperations.class);
|
||||
given(restTemplate.execute((URI) any(), eq(HttpMethod.POST), any(), any())).willThrow(expected);
|
||||
|
|
@ -180,18 +180,18 @@ class RestTemplateXhrTransportTests {
|
|||
|
||||
@SuppressWarnings("deprecation")
|
||||
private org.springframework.util.concurrent.ListenableFuture<WebSocketSession> connect(
|
||||
ClientHttpResponse... responses) throws Exception {
|
||||
ClientHttpResponse... responses) {
|
||||
return connect(new TestRestTemplate(responses));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private org.springframework.util.concurrent.ListenableFuture<WebSocketSession> connect(
|
||||
RestOperations restTemplate, ClientHttpResponse... responses) throws Exception {
|
||||
RestOperations restTemplate, ClientHttpResponse... responses) {
|
||||
|
||||
RestTemplateXhrTransport transport = new RestTemplateXhrTransport(restTemplate);
|
||||
transport.setTaskExecutor(new SyncTaskExecutor());
|
||||
|
||||
SockJsUrlInfo urlInfo = new SockJsUrlInfo(new URI("https://example.com"));
|
||||
SockJsUrlInfo urlInfo = new SockJsUrlInfo(URI.create("https://example.com"));
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("h-foo", "h-bar");
|
||||
TransportRequest request = new DefaultTransportRequest(urlInfo, headers, headers,
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class SockJsClientTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectWebSocket() throws Exception {
|
||||
void connectWebSocket() {
|
||||
setupInfoRequest(true);
|
||||
this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback);
|
||||
assertThat(this.webSocketTransport.invoked()).isTrue();
|
||||
|
|
@ -94,7 +94,7 @@ class SockJsClientTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectXhrStreamingDisabled() throws Exception {
|
||||
void connectXhrStreamingDisabled() {
|
||||
setupInfoRequest(false);
|
||||
this.xhrTransport.setStreamingDisabled(true);
|
||||
this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback);
|
||||
|
|
@ -105,14 +105,14 @@ class SockJsClientTests {
|
|||
|
||||
@Test // SPR-13254
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectWithHandshakeHeaders() throws Exception {
|
||||
void connectWithHandshakeHeaders() {
|
||||
ArgumentCaptor<HttpHeaders> headersCaptor = setupInfoRequest(false);
|
||||
this.xhrTransport.setStreamingDisabled(true);
|
||||
|
||||
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
|
||||
headers.set("foo", "bar");
|
||||
headers.set("auth", "123");
|
||||
this.sockJsClient.doHandshake(handler, headers, new URI(URL)).addCallback(this.connectCallback);
|
||||
this.sockJsClient.doHandshake(handler, headers, URI.create(URL)).addCallback(this.connectCallback);
|
||||
|
||||
HttpHeaders httpHeaders = headersCaptor.getValue();
|
||||
assertThat(httpHeaders).hasSize(2);
|
||||
|
|
@ -127,7 +127,7 @@ class SockJsClientTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectAndUseSubsetOfHandshakeHeadersForHttpRequests() throws Exception {
|
||||
void connectAndUseSubsetOfHandshakeHeadersForHttpRequests() {
|
||||
ArgumentCaptor<HttpHeaders> headersCaptor = setupInfoRequest(false);
|
||||
this.xhrTransport.setStreamingDisabled(true);
|
||||
|
||||
|
|
@ -135,7 +135,7 @@ class SockJsClientTests {
|
|||
headers.set("foo", "bar");
|
||||
headers.set("auth", "123");
|
||||
this.sockJsClient.setHttpHeaderNames("auth");
|
||||
this.sockJsClient.doHandshake(handler, headers, new URI(URL)).addCallback(this.connectCallback);
|
||||
this.sockJsClient.doHandshake(handler, headers, URI.create(URL)).addCallback(this.connectCallback);
|
||||
|
||||
assertThat(headersCaptor.getValue()).hasSize(1);
|
||||
assertThat(headersCaptor.getValue().getFirst("auth")).isEqualTo("123");
|
||||
|
|
@ -145,7 +145,7 @@ class SockJsClientTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectSockJsInfo() throws Exception {
|
||||
void connectSockJsInfo() {
|
||||
setupInfoRequest(true);
|
||||
this.sockJsClient.doHandshake(handler, URL);
|
||||
verify(this.infoReceiver, times(1)).executeInfoRequest(any(), any());
|
||||
|
|
@ -153,7 +153,7 @@ class SockJsClientTests {
|
|||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connectSockJsInfoCached() throws Exception {
|
||||
void connectSockJsInfoCached() {
|
||||
setupInfoRequest(true);
|
||||
this.sockJsClient.doHandshake(handler, URL);
|
||||
this.sockJsClient.doHandshake(handler, URL);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
|
|
@ -35,15 +35,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
class SockJsUrlInfoTests {
|
||||
|
||||
@Test
|
||||
void serverId() throws Exception {
|
||||
SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com"));
|
||||
void serverId() {
|
||||
SockJsUrlInfo info = new SockJsUrlInfo(URI.create("https://example.com"));
|
||||
int serverId = Integer.parseInt(info.getServerId());
|
||||
assertThat(serverId).isGreaterThanOrEqualTo(0).isLessThan(1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
void sessionId() throws Exception {
|
||||
SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com"));
|
||||
void sessionId() {
|
||||
SockJsUrlInfo info = new SockJsUrlInfo(URI.create("https://example.com"));
|
||||
assertThat(info.getSessionId()).as("Invalid sessionId: " + info.getSessionId()).hasSize(32);
|
||||
}
|
||||
|
||||
|
|
@ -54,9 +54,9 @@ class SockJsUrlInfoTests {
|
|||
ws, http
|
||||
wss, https
|
||||
""")
|
||||
void infoUrl(String scheme, String expectedScheme) throws Exception {
|
||||
SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com"));
|
||||
assertThat(info.getInfoUrl()).isEqualTo(new URI(expectedScheme + "://example.com/info"));
|
||||
void infoUrl(String scheme, String expectedScheme) {
|
||||
SockJsUrlInfo info = new SockJsUrlInfo(URI.create(scheme + "://example.com"));
|
||||
assertThat(info.getInfoUrl()).isEqualTo(URI.create(expectedScheme + "://example.com/info"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
|
@ -70,12 +70,12 @@ class SockJsUrlInfoTests {
|
|||
wss, https, XHR_STREAMING
|
||||
wss, wss, WEBSOCKET
|
||||
""")
|
||||
void transportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception {
|
||||
SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com"));
|
||||
void transportUrl(String scheme, String expectedScheme, TransportType transportType) {
|
||||
SockJsUrlInfo info = new SockJsUrlInfo(URI.create(scheme + "://example.com"));
|
||||
String serverId = info.getServerId();
|
||||
String sessionId = info.getSessionId();
|
||||
String transport = transportType.toString().toLowerCase();
|
||||
URI expected = new URI(expectedScheme + "://example.com/" + serverId + "/" + sessionId + "/" + transport);
|
||||
URI expected = URI.create(expectedScheme + "://example.com/" + serverId + "/" + sessionId + "/" + transport);
|
||||
assertThat(info.getTransportUrl(transportType)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,28 +46,28 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
class XhrTransportTests {
|
||||
|
||||
@Test
|
||||
void infoResponse() throws Exception {
|
||||
void infoResponse() {
|
||||
TestXhrTransport transport = new TestXhrTransport();
|
||||
transport.infoResponseToReturn = new ResponseEntity<>("body", HttpStatus.OK);
|
||||
assertThat(transport.executeInfoRequest(new URI("https://example.com/info"), null)).isEqualTo("body");
|
||||
assertThat(transport.executeInfoRequest(URI.create("https://example.com/info"), null)).isEqualTo("body");
|
||||
}
|
||||
|
||||
@Test
|
||||
void infoResponseError() throws Exception {
|
||||
void infoResponseError() {
|
||||
TestXhrTransport transport = new TestXhrTransport();
|
||||
transport.infoResponseToReturn = new ResponseEntity<>("body", HttpStatus.BAD_REQUEST);
|
||||
assertThatExceptionOfType(HttpServerErrorException.class).isThrownBy(() ->
|
||||
transport.executeInfoRequest(new URI("https://example.com/info"), null));
|
||||
transport.executeInfoRequest(URI.create("https://example.com/info"), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendMessage() throws Exception {
|
||||
void sendMessage() {
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.set("foo", "bar");
|
||||
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
TestXhrTransport transport = new TestXhrTransport();
|
||||
transport.sendMessageResponseToReturn = new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
URI url = new URI("https://example.com");
|
||||
URI url = URI.create("https://example.com");
|
||||
transport.executeSendRequest(url, requestHeaders, new TextMessage("payload"));
|
||||
assertThat(transport.actualSendRequestHeaders).hasSize(2);
|
||||
assertThat(transport.actualSendRequestHeaders.getFirst("foo")).isEqualTo("bar");
|
||||
|
|
@ -75,22 +75,22 @@ class XhrTransportTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void sendMessageError() throws Exception {
|
||||
void sendMessageError() {
|
||||
TestXhrTransport transport = new TestXhrTransport();
|
||||
transport.sendMessageResponseToReturn = new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
URI url = new URI("https://example.com");
|
||||
URI url = URI.create("https://example.com");
|
||||
assertThatExceptionOfType(HttpServerErrorException.class).isThrownBy(() ->
|
||||
transport.executeSendRequest(url, new HttpHeaders(), new TextMessage("payload")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void connect() throws Exception {
|
||||
void connect() {
|
||||
HttpHeaders handshakeHeaders = new HttpHeaders();
|
||||
handshakeHeaders.setOrigin("foo");
|
||||
|
||||
TransportRequest request = mock(TransportRequest.class);
|
||||
given(request.getSockJsUrlInfo()).willReturn(new SockJsUrlInfo(new URI("https://example.com")));
|
||||
given(request.getSockJsUrlInfo()).willReturn(new SockJsUrlInfo(URI.create("https://example.com")));
|
||||
given(request.getHandshakeHeaders()).willReturn(handshakeHeaders);
|
||||
given(request.getHttpRequestHeaders()).willReturn(new HttpHeaders());
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue