Migrate JUnit 4 assertions to AssertJ
Migrate all existing JUnit 4 `assert...` based assertions to AssertJ and add a checkstyle rule to ensure they don't return. See gh-23022
This commit is contained in:
@@ -21,7 +21,6 @@ import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link WebSocketExtension}
|
||||
@@ -35,10 +34,10 @@ public class WebSocketExtensionTests {
|
||||
assertThat(extensions).hasSize(1);
|
||||
WebSocketExtension extension = extensions.get(0);
|
||||
|
||||
assertEquals("x-test-extension", extension.getName());
|
||||
assertEquals(2, extension.getParameters().size());
|
||||
assertEquals("bar", extension.getParameters().get("foo"));
|
||||
assertEquals("baz", extension.getParameters().get("bar"));
|
||||
assertThat(extension.getName()).isEqualTo("x-test-extension");
|
||||
assertThat(extension.getParameters().size()).isEqualTo(2);
|
||||
assertThat(extension.getParameters().get("foo")).isEqualTo("bar");
|
||||
assertThat(extension.getParameters().get("bar")).isEqualTo("baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -40,8 +40,7 @@ import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Client and server-side WebSocket integration tests.
|
||||
@@ -73,7 +72,7 @@ public class WebSocketHandshakeTests extends AbstractWebSocketIntegrationTests {
|
||||
headers.setSecWebSocketProtocol("foo");
|
||||
URI url = new URI(getWsBaseUrl() + "/ws");
|
||||
WebSocketSession session = this.webSocketClient.doHandshake(new TextWebSocketHandler(), headers, url).get();
|
||||
assertEquals("foo", session.getAcceptedProtocol());
|
||||
assertThat(session.getAcceptedProtocol()).isEqualTo("foo");
|
||||
session.close();
|
||||
}
|
||||
|
||||
@@ -88,9 +87,9 @@ public class WebSocketHandshakeTests extends AbstractWebSocketIntegrationTests {
|
||||
session.sendMessage(new PongMessage());
|
||||
|
||||
serverHandler.await();
|
||||
assertNull(serverHandler.getTransportError());
|
||||
assertEquals(1, serverHandler.getReceivedMessages().size());
|
||||
assertEquals(PongMessage.class, serverHandler.getReceivedMessages().get(0).getClass());
|
||||
assertThat(serverHandler.getTransportError()).isNull();
|
||||
assertThat(serverHandler.getReceivedMessages().size()).isEqualTo(1);
|
||||
assertThat(serverHandler.getReceivedMessages().get(0).getClass()).isEqualTo(PongMessage.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,8 +27,7 @@ import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.web.socket.handler.TestPrincipal;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
@@ -49,7 +48,7 @@ public class JettyWebSocketSessionTests {
|
||||
TestPrincipal user = new TestPrincipal("joe");
|
||||
JettyWebSocketSession session = new JettyWebSocketSession(attributes, user);
|
||||
|
||||
assertSame(user, session.getPrincipal());
|
||||
assertThat(session.getPrincipal()).isSameAs(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,7 +71,7 @@ public class JettyWebSocketSessionTests {
|
||||
|
||||
reset(nativeSession);
|
||||
|
||||
assertSame(user, session.getPrincipal());
|
||||
assertThat(session.getPrincipal()).isSameAs(user);
|
||||
verifyNoMoreInteractions(nativeSession);
|
||||
}
|
||||
|
||||
@@ -94,7 +93,7 @@ public class JettyWebSocketSessionTests {
|
||||
|
||||
reset(nativeSession);
|
||||
|
||||
assertNull(session.getPrincipal());
|
||||
assertThat(session.getPrincipal()).isNull();
|
||||
verifyNoMoreInteractions(nativeSession);
|
||||
}
|
||||
|
||||
@@ -118,7 +117,7 @@ public class JettyWebSocketSessionTests {
|
||||
|
||||
reset(nativeSession);
|
||||
|
||||
assertSame(protocol, session.getAcceptedProtocol());
|
||||
assertThat(session.getAcceptedProtocol()).isSameAs(protocol);
|
||||
verifyNoMoreInteractions(nativeSession);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.junit.Test;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
@@ -69,7 +69,7 @@ public class StandardWebSocketHandlerAdapterTests {
|
||||
verify(this.session, atLeast(2)).addMessageHandler(any(MessageHandler.Whole.class));
|
||||
|
||||
given(this.session.getRequestURI()).willReturn(uri);
|
||||
assertEquals(uri, this.webSocketSession.getUri());
|
||||
assertThat(this.webSocketSession.getUri()).isEqualTo(uri);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,9 +26,7 @@ import org.mockito.Mockito;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.socket.handler.TestPrincipal;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
@@ -51,7 +49,7 @@ public class StandardWebSocketSessionTests {
|
||||
TestPrincipal user = new TestPrincipal("joe");
|
||||
StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null, user);
|
||||
|
||||
assertSame(user, session.getPrincipal());
|
||||
assertThat(session.getPrincipal()).isSameAs(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,7 +63,7 @@ public class StandardWebSocketSessionTests {
|
||||
StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null);
|
||||
session.initializeNativeSession(nativeSession);
|
||||
|
||||
assertSame(user, session.getPrincipal());
|
||||
assertThat(session.getPrincipal()).isSameAs(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +77,7 @@ public class StandardWebSocketSessionTests {
|
||||
|
||||
reset(nativeSession);
|
||||
|
||||
assertNull(session.getPrincipal());
|
||||
assertThat(session.getPrincipal()).isNull();
|
||||
verifyNoMoreInteractions(nativeSession);
|
||||
}
|
||||
|
||||
@@ -96,7 +94,7 @@ public class StandardWebSocketSessionTests {
|
||||
|
||||
reset(nativeSession);
|
||||
|
||||
assertEquals(protocol, session.getAcceptedProtocol());
|
||||
assertThat(session.getAcceptedProtocol()).isEqualTo(protocol);
|
||||
verifyNoMoreInteractions(nativeSession);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,10 +34,7 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import org.springframework.web.socket.handler.WebSocketHandlerDecorator;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link WebSocketConnectionManager}.
|
||||
@@ -61,13 +58,13 @@ public class WebSocketConnectionManagerTests {
|
||||
WebSocketHttpHeaders expectedHeaders = new WebSocketHttpHeaders();
|
||||
expectedHeaders.setSecWebSocketProtocol(subprotocols);
|
||||
|
||||
assertEquals(expectedHeaders, client.headers);
|
||||
assertEquals(new URI("/path/123"), client.uri);
|
||||
assertThat(client.headers).isEqualTo(expectedHeaders);
|
||||
assertThat(client.uri).isEqualTo(new URI("/path/123"));
|
||||
|
||||
WebSocketHandlerDecorator loggingHandler = (WebSocketHandlerDecorator) client.webSocketHandler;
|
||||
assertEquals(LoggingWebSocketHandlerDecorator.class, loggingHandler.getClass());
|
||||
assertThat(loggingHandler.getClass()).isEqualTo(LoggingWebSocketHandlerDecorator.class);
|
||||
|
||||
assertSame(handler, loggingHandler.getDelegate());
|
||||
assertThat(loggingHandler.getDelegate()).isSameAs(handler);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,10 +74,10 @@ public class WebSocketConnectionManagerTests {
|
||||
WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/a");
|
||||
|
||||
manager.startInternal();
|
||||
assertTrue(client.isRunning());
|
||||
assertThat(client.isRunning()).isTrue();
|
||||
|
||||
manager.stopInternal();
|
||||
assertFalse(client.isRunning());
|
||||
assertThat(client.isRunning()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.web.socket.adapter.jetty.JettyWebSocketHandlerAdapter
|
||||
import org.springframework.web.socket.adapter.jetty.JettyWebSocketSession;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link JettyWebSocketClient}.
|
||||
@@ -83,8 +83,8 @@ public class JettyWebSocketClientTests {
|
||||
|
||||
this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get();
|
||||
|
||||
assertEquals(this.wsUrl, this.wsSession.getUri().toString());
|
||||
assertEquals("echo", this.wsSession.getAcceptedProtocol());
|
||||
assertThat(this.wsSession.getUri().toString()).isEqualTo(this.wsUrl);
|
||||
assertThat(this.wsSession.getAcceptedProtocol()).isEqualTo("echo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,8 +96,8 @@ public class JettyWebSocketClientTests {
|
||||
this.client.setTaskExecutor(new SimpleAsyncTaskExecutor());
|
||||
this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get();
|
||||
|
||||
assertEquals(this.wsUrl, this.wsSession.getUri().toString());
|
||||
assertEquals("echo", this.wsSession.getAcceptedProtocol());
|
||||
assertThat(this.wsSession.getUri().toString()).isEqualTo(this.wsUrl);
|
||||
assertThat(this.wsSession.getAcceptedProtocol()).isEqualTo("echo");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,9 +35,8 @@ import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -73,8 +72,8 @@ public class StandardWebSocketClientTests {
|
||||
URI uri = new URI("ws://localhost/abc");
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
assertNotNull(session.getLocalAddress());
|
||||
assertEquals(80, session.getLocalAddress().getPort());
|
||||
assertThat(session.getLocalAddress()).isNotNull();
|
||||
assertThat(session.getLocalAddress().getPort()).isEqualTo(80);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,8 +81,8 @@ public class StandardWebSocketClientTests {
|
||||
URI uri = new URI("wss://localhost/abc");
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
assertNotNull(session.getLocalAddress());
|
||||
assertEquals(443, session.getLocalAddress().getPort());
|
||||
assertThat(session.getLocalAddress()).isNotNull();
|
||||
assertThat(session.getLocalAddress().getPort()).isEqualTo(443);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,9 +97,9 @@ public class StandardWebSocketClientTests {
|
||||
URI uri = new URI("wss://localhost/abc");
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
assertNotNull(session.getRemoteAddress());
|
||||
assertEquals("localhost", session.getRemoteAddress().getHostName());
|
||||
assertEquals(443, session.getLocalAddress().getPort());
|
||||
assertThat(session.getRemoteAddress()).isNotNull();
|
||||
assertThat(session.getRemoteAddress().getHostName()).isEqualTo("localhost");
|
||||
assertThat(session.getLocalAddress().getPort()).isEqualTo(443);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,8 +112,8 @@ public class StandardWebSocketClientTests {
|
||||
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
assertEquals(1, session.getHandshakeHeaders().size());
|
||||
assertEquals("bar", session.getHandshakeHeaders().getFirst("foo"));
|
||||
assertThat(session.getHandshakeHeaders().size()).isEqualTo(1);
|
||||
assertThat(session.getHandshakeHeaders().getFirst("foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,7 +129,7 @@ public class StandardWebSocketClientTests {
|
||||
verify(this.wsContainer).connectToServer(any(Endpoint.class), captor.capture(), any(URI.class));
|
||||
ClientEndpointConfig endpointConfig = captor.getValue();
|
||||
|
||||
assertEquals(protocols, endpointConfig.getPreferredSubprotocols());
|
||||
assertThat(endpointConfig.getPreferredSubprotocols()).isEqualTo(protocols);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -146,7 +145,7 @@ public class StandardWebSocketClientTests {
|
||||
verify(this.wsContainer).connectToServer(any(Endpoint.class), captor.capture(), any(URI.class));
|
||||
ClientEndpointConfig endpointConfig = captor.getValue();
|
||||
|
||||
assertEquals(userProperties, endpointConfig.getUserProperties());
|
||||
assertThat(endpointConfig.getUserProperties()).isEqualTo(userProperties);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -163,7 +162,7 @@ public class StandardWebSocketClientTests {
|
||||
|
||||
Map<String, List<String>> headers = new HashMap<>();
|
||||
endpointConfig.getConfigurator().beforeRequest(headers);
|
||||
assertEquals(1, headers.size());
|
||||
assertThat(headers.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,7 +172,7 @@ public class StandardWebSocketClientTests {
|
||||
this.wsClient.setTaskExecutor(new SimpleAsyncTaskExecutor());
|
||||
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
|
||||
|
||||
assertNotNull(session);
|
||||
assertThat(session).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,11 +61,6 @@ import org.springframework.web.socket.sockjs.transport.handler.XhrReceivingTrans
|
||||
import org.springframework.web.socket.sockjs.transport.handler.XhrStreamingTransportHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test fixture for HandlersBeanDefinitionParser.
|
||||
@@ -84,96 +79,102 @@ public class HandlersBeanDefinitionParserTests {
|
||||
loadBeanDefinitions("websocket-config-handlers.xml");
|
||||
|
||||
Map<String, HandlerMapping> handlersMap = this.appContext.getBeansOfType(HandlerMapping.class);
|
||||
assertNotNull(handlersMap);
|
||||
assertThat(handlersMap).isNotNull();
|
||||
assertThat(handlersMap).hasSize(2);
|
||||
|
||||
for (HandlerMapping hm : handlersMap.values()) {
|
||||
assertTrue(hm instanceof SimpleUrlHandlerMapping);
|
||||
boolean condition2 = hm instanceof SimpleUrlHandlerMapping;
|
||||
assertThat(condition2).isTrue();
|
||||
SimpleUrlHandlerMapping shm = (SimpleUrlHandlerMapping) hm;
|
||||
|
||||
if (shm.getUrlMap().keySet().contains("/foo")) {
|
||||
assertThat(shm.getUrlMap()).containsOnlyKeys("/foo", "/bar");
|
||||
WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) shm.getUrlMap().get("/foo");
|
||||
assertNotNull(handler);
|
||||
assertThat(handler).isNotNull();
|
||||
unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), FooWebSocketHandler.class);
|
||||
HandshakeHandler handshakeHandler = handler.getHandshakeHandler();
|
||||
assertNotNull(handshakeHandler);
|
||||
assertTrue(handshakeHandler instanceof DefaultHandshakeHandler);
|
||||
assertFalse(handler.getHandshakeInterceptors().isEmpty());
|
||||
assertTrue(handler.getHandshakeInterceptors().get(0) instanceof OriginHandshakeInterceptor);
|
||||
assertThat(handshakeHandler).isNotNull();
|
||||
boolean condition1 = handshakeHandler instanceof DefaultHandshakeHandler;
|
||||
assertThat(condition1).isTrue();
|
||||
assertThat(handler.getHandshakeInterceptors().isEmpty()).isFalse();
|
||||
boolean condition = handler.getHandshakeInterceptors().get(0) instanceof OriginHandshakeInterceptor;
|
||||
assertThat(condition).isTrue();
|
||||
}
|
||||
else {
|
||||
assertThat(shm.getUrlMap()).containsOnlyKeys("/test");
|
||||
WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) shm.getUrlMap().get("/test");
|
||||
assertNotNull(handler);
|
||||
assertThat(handler).isNotNull();
|
||||
unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);
|
||||
HandshakeHandler handshakeHandler = handler.getHandshakeHandler();
|
||||
assertNotNull(handshakeHandler);
|
||||
assertTrue(handshakeHandler instanceof DefaultHandshakeHandler);
|
||||
assertFalse(handler.getHandshakeInterceptors().isEmpty());
|
||||
assertTrue(handler.getHandshakeInterceptors().get(0) instanceof OriginHandshakeInterceptor);
|
||||
assertThat(handshakeHandler).isNotNull();
|
||||
boolean condition1 = handshakeHandler instanceof DefaultHandshakeHandler;
|
||||
assertThat(condition1).isTrue();
|
||||
assertThat(handler.getHandshakeInterceptors().isEmpty()).isFalse();
|
||||
boolean condition = handler.getHandshakeInterceptors().get(0) instanceof OriginHandshakeInterceptor;
|
||||
assertThat(condition).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void webSocketHandlersAttributes() {
|
||||
loadBeanDefinitions("websocket-config-handlers-attributes.xml");
|
||||
|
||||
HandlerMapping handlerMapping = this.appContext.getBean(HandlerMapping.class);
|
||||
assertNotNull(handlerMapping);
|
||||
assertTrue(handlerMapping instanceof SimpleUrlHandlerMapping);
|
||||
assertThat(handlerMapping).isNotNull();
|
||||
boolean condition2 = handlerMapping instanceof SimpleUrlHandlerMapping;
|
||||
assertThat(condition2).isTrue();
|
||||
|
||||
SimpleUrlHandlerMapping urlHandlerMapping = (SimpleUrlHandlerMapping) handlerMapping;
|
||||
assertEquals(2, urlHandlerMapping.getOrder());
|
||||
assertThat(urlHandlerMapping.getOrder()).isEqualTo(2);
|
||||
|
||||
WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) urlHandlerMapping.getUrlMap().get("/foo");
|
||||
assertNotNull(handler);
|
||||
assertThat(handler).isNotNull();
|
||||
unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), FooWebSocketHandler.class);
|
||||
HandshakeHandler handshakeHandler = handler.getHandshakeHandler();
|
||||
assertNotNull(handshakeHandler);
|
||||
assertTrue(handshakeHandler instanceof TestHandshakeHandler);
|
||||
assertThat(handshakeHandler).isNotNull();
|
||||
boolean condition1 = handshakeHandler instanceof TestHandshakeHandler;
|
||||
assertThat(condition1).isTrue();
|
||||
List<HandshakeInterceptor> interceptors = handler.getHandshakeInterceptors();
|
||||
assertThat(interceptors).extracting("class")
|
||||
.containsExactlyInAnyOrder(FooTestInterceptor.class, BarTestInterceptor.class, OriginHandshakeInterceptor.class);
|
||||
|
||||
handler = (WebSocketHttpRequestHandler) urlHandlerMapping.getUrlMap().get("/test");
|
||||
assertNotNull(handler);
|
||||
assertThat(handler).isNotNull();
|
||||
unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);
|
||||
handshakeHandler = handler.getHandshakeHandler();
|
||||
assertNotNull(handshakeHandler);
|
||||
assertTrue(handshakeHandler instanceof TestHandshakeHandler);
|
||||
assertThat(handshakeHandler).isNotNull();
|
||||
boolean condition = handshakeHandler instanceof TestHandshakeHandler;
|
||||
assertThat(condition).isTrue();
|
||||
interceptors = handler.getHandshakeInterceptors();
|
||||
assertThat(interceptors).extracting("class")
|
||||
.containsExactlyInAnyOrder(FooTestInterceptor.class, BarTestInterceptor.class, OriginHandshakeInterceptor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void sockJs() {
|
||||
loadBeanDefinitions("websocket-config-handlers-sockjs.xml");
|
||||
|
||||
SimpleUrlHandlerMapping handlerMapping = this.appContext.getBean(SimpleUrlHandlerMapping.class);
|
||||
assertNotNull(handlerMapping);
|
||||
assertThat(handlerMapping).isNotNull();
|
||||
|
||||
SockJsHttpRequestHandler testHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/test/**");
|
||||
assertNotNull(testHandler);
|
||||
assertThat(testHandler).isNotNull();
|
||||
unwrapAndCheckDecoratedHandlerType(testHandler.getWebSocketHandler(), TestWebSocketHandler.class);
|
||||
SockJsService testSockJsService = testHandler.getSockJsService();
|
||||
|
||||
SockJsHttpRequestHandler fooHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/foo/**");
|
||||
assertNotNull(fooHandler);
|
||||
assertThat(fooHandler).isNotNull();
|
||||
unwrapAndCheckDecoratedHandlerType(fooHandler.getWebSocketHandler(), FooWebSocketHandler.class);
|
||||
SockJsService sockJsService = fooHandler.getSockJsService();
|
||||
assertNotNull(sockJsService);
|
||||
assertThat(sockJsService).isNotNull();
|
||||
|
||||
assertSame(testSockJsService, sockJsService);
|
||||
assertThat(sockJsService).isSameAs(testSockJsService);
|
||||
|
||||
assertThat(sockJsService).isInstanceOf(DefaultSockJsService.class);
|
||||
DefaultSockJsService defaultSockJsService = (DefaultSockJsService) sockJsService;
|
||||
assertThat(defaultSockJsService.getTaskScheduler()).isInstanceOf(ThreadPoolTaskScheduler.class);
|
||||
assertFalse(defaultSockJsService.shouldSuppressCors());
|
||||
assertThat(defaultSockJsService.shouldSuppressCors()).isFalse();
|
||||
|
||||
Map<TransportType, TransportHandler> handlerMap = defaultSockJsService.getTransportHandlers();
|
||||
assertThat(handlerMap.values()).extracting("class")
|
||||
@@ -186,7 +187,7 @@ public class HandlersBeanDefinitionParserTests {
|
||||
WebSocketTransportHandler.class);
|
||||
|
||||
WebSocketTransportHandler handler = (WebSocketTransportHandler) handlerMap.get(TransportType.WEBSOCKET);
|
||||
assertEquals(TestHandshakeHandler.class, handler.getHandshakeHandler().getClass());
|
||||
assertThat(handler.getHandshakeHandler().getClass()).isEqualTo(TestHandshakeHandler.class);
|
||||
|
||||
List<HandshakeInterceptor> interceptors = defaultSockJsService.getHandshakeInterceptors();
|
||||
assertThat(interceptors).extracting("class")
|
||||
@@ -194,40 +195,39 @@ public class HandlersBeanDefinitionParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void sockJsAttributes() {
|
||||
loadBeanDefinitions("websocket-config-handlers-sockjs-attributes.xml");
|
||||
|
||||
SimpleUrlHandlerMapping handlerMapping = appContext.getBean(SimpleUrlHandlerMapping.class);
|
||||
assertNotNull(handlerMapping);
|
||||
assertThat(handlerMapping).isNotNull();
|
||||
|
||||
SockJsHttpRequestHandler handler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/test/**");
|
||||
assertNotNull(handler);
|
||||
assertThat(handler).isNotNull();
|
||||
unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);
|
||||
|
||||
SockJsService sockJsService = handler.getSockJsService();
|
||||
assertNotNull(sockJsService);
|
||||
assertThat(sockJsService).isNotNull();
|
||||
assertThat(sockJsService).isInstanceOf(TransportHandlingSockJsService.class);
|
||||
TransportHandlingSockJsService transportService = (TransportHandlingSockJsService) sockJsService;
|
||||
assertThat(transportService.getTaskScheduler()).isInstanceOf(TestTaskScheduler.class);
|
||||
assertThat(transportService.getTransportHandlers().values()).extracting("class")
|
||||
.containsExactlyInAnyOrder(XhrPollingTransportHandler.class, XhrStreamingTransportHandler.class);
|
||||
|
||||
assertEquals("testSockJsService", transportService.getName());
|
||||
assertFalse(transportService.isWebSocketEnabled());
|
||||
assertFalse(transportService.isSessionCookieNeeded());
|
||||
assertEquals(2048, transportService.getStreamBytesLimit());
|
||||
assertEquals(256, transportService.getDisconnectDelay());
|
||||
assertEquals(1024, transportService.getHttpMessageCacheSize());
|
||||
assertEquals(20, transportService.getHeartbeatTime());
|
||||
assertEquals("/js/sockjs.min.js", transportService.getSockJsClientLibraryUrl());
|
||||
assertEquals(TestMessageCodec.class, transportService.getMessageCodec().getClass());
|
||||
assertThat(transportService.getName()).isEqualTo("testSockJsService");
|
||||
assertThat(transportService.isWebSocketEnabled()).isFalse();
|
||||
assertThat(transportService.isSessionCookieNeeded()).isFalse();
|
||||
assertThat(transportService.getStreamBytesLimit()).isEqualTo(2048);
|
||||
assertThat(transportService.getDisconnectDelay()).isEqualTo(256);
|
||||
assertThat(transportService.getHttpMessageCacheSize()).isEqualTo(1024);
|
||||
assertThat(transportService.getHeartbeatTime()).isEqualTo(20);
|
||||
assertThat(transportService.getSockJsClientLibraryUrl()).isEqualTo("/js/sockjs.min.js");
|
||||
assertThat(transportService.getMessageCodec().getClass()).isEqualTo(TestMessageCodec.class);
|
||||
|
||||
List<HandshakeInterceptor> interceptors = transportService.getHandshakeInterceptors();
|
||||
assertThat(interceptors).extracting("class").containsExactly(OriginHandshakeInterceptor.class);
|
||||
assertTrue(transportService.shouldSuppressCors());
|
||||
assertTrue(transportService.getAllowedOrigins().contains("https://mydomain1.com"));
|
||||
assertTrue(transportService.getAllowedOrigins().contains("https://mydomain2.com"));
|
||||
assertThat(transportService.shouldSuppressCors()).isTrue();
|
||||
assertThat(transportService.getAllowedOrigins().contains("https://mydomain1.com")).isTrue();
|
||||
assertThat(transportService.getAllowedOrigins().contains("https://mydomain2.com")).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -242,7 +242,7 @@ public class HandlersBeanDefinitionParserTests {
|
||||
if (handler instanceof WebSocketHandlerDecorator) {
|
||||
handler = ((WebSocketHandlerDecorator) handler).getLastHandler();
|
||||
}
|
||||
assertTrue(handlerClass.isInstance(handler));
|
||||
assertThat(handlerClass.isInstance(handler)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,12 +91,6 @@ import org.springframework.web.socket.sockjs.transport.handler.WebSocketTranspor
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link MessageBrokerBeanDefinitionParser}.
|
||||
@@ -112,7 +106,6 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void simpleBroker() throws Exception {
|
||||
loadBeanDefinitions("websocket-config-broker-simple.xml");
|
||||
|
||||
@@ -122,20 +115,20 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
assertThat(suhm.getUrlMap()).hasSize(4);
|
||||
|
||||
HttpRequestHandler httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/foo");
|
||||
assertNotNull(httpRequestHandler);
|
||||
assertThat(httpRequestHandler).isNotNull();
|
||||
assertThat(httpRequestHandler).isInstanceOf(WebSocketHttpRequestHandler.class);
|
||||
|
||||
WebSocketHttpRequestHandler wsHttpRequestHandler = (WebSocketHttpRequestHandler) httpRequestHandler;
|
||||
HandshakeHandler handshakeHandler = wsHttpRequestHandler.getHandshakeHandler();
|
||||
assertNotNull(handshakeHandler);
|
||||
assertTrue(handshakeHandler instanceof TestHandshakeHandler);
|
||||
assertThat(handshakeHandler).isNotNull();
|
||||
assertThat(handshakeHandler instanceof TestHandshakeHandler).isTrue();
|
||||
List<HandshakeInterceptor> interceptors = wsHttpRequestHandler.getHandshakeInterceptors();
|
||||
assertThat(interceptors).extracting("class").containsExactly(FooTestInterceptor.class,
|
||||
BarTestInterceptor.class, OriginHandshakeInterceptor.class);
|
||||
|
||||
WebSocketSession session = new TestWebSocketSession("id");
|
||||
wsHttpRequestHandler.getWebSocketHandler().afterConnectionEstablished(session);
|
||||
assertEquals(true, session.getAttributes().get("decorated"));
|
||||
assertThat(session.getAttributes().get("decorated")).isEqualTo(true);
|
||||
|
||||
WebSocketHandler wsHandler = wsHttpRequestHandler.getWebSocketHandler();
|
||||
assertThat(wsHandler).isInstanceOf(ExceptionWebSocketHandlerDecorator.class);
|
||||
@@ -145,74 +138,74 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
assertThat(wsHandler).isInstanceOf(TestWebSocketHandlerDecorator.class);
|
||||
wsHandler = ((TestWebSocketHandlerDecorator) wsHandler).getDelegate();
|
||||
assertThat(wsHandler).isInstanceOf(SubProtocolWebSocketHandler.class);
|
||||
assertSame(wsHandler, this.appContext.getBean(MessageBrokerBeanDefinitionParser.WEB_SOCKET_HANDLER_BEAN_NAME));
|
||||
assertThat(this.appContext.getBean(MessageBrokerBeanDefinitionParser.WEB_SOCKET_HANDLER_BEAN_NAME)).isSameAs(wsHandler);
|
||||
|
||||
SubProtocolWebSocketHandler subProtocolWsHandler = (SubProtocolWebSocketHandler) wsHandler;
|
||||
assertEquals(Arrays.asList("v10.stomp", "v11.stomp", "v12.stomp"), subProtocolWsHandler.getSubProtocols());
|
||||
assertEquals(25 * 1000, subProtocolWsHandler.getSendTimeLimit());
|
||||
assertEquals(1024 * 1024, subProtocolWsHandler.getSendBufferSizeLimit());
|
||||
assertEquals(30 * 1000, subProtocolWsHandler.getTimeToFirstMessage());
|
||||
assertThat(subProtocolWsHandler.getSubProtocols()).isEqualTo(Arrays.asList("v10.stomp", "v11.stomp", "v12.stomp"));
|
||||
assertThat(subProtocolWsHandler.getSendTimeLimit()).isEqualTo(25 * 1000);
|
||||
assertThat(subProtocolWsHandler.getSendBufferSizeLimit()).isEqualTo(1024 * 1024);
|
||||
assertThat(subProtocolWsHandler.getTimeToFirstMessage()).isEqualTo(30 * 1000);
|
||||
|
||||
Map<String, SubProtocolHandler> handlerMap = subProtocolWsHandler.getProtocolHandlerMap();
|
||||
StompSubProtocolHandler stompHandler = (StompSubProtocolHandler) handlerMap.get("v12.stomp");
|
||||
assertNotNull(stompHandler);
|
||||
assertEquals(128 * 1024, stompHandler.getMessageSizeLimit());
|
||||
assertNotNull(stompHandler.getErrorHandler());
|
||||
assertEquals(TestStompErrorHandler.class, stompHandler.getErrorHandler().getClass());
|
||||
assertThat(stompHandler).isNotNull();
|
||||
assertThat(stompHandler.getMessageSizeLimit()).isEqualTo(128 * 1024);
|
||||
assertThat(stompHandler.getErrorHandler()).isNotNull();
|
||||
assertThat(stompHandler.getErrorHandler().getClass()).isEqualTo(TestStompErrorHandler.class);
|
||||
|
||||
assertNotNull(new DirectFieldAccessor(stompHandler).getPropertyValue("eventPublisher"));
|
||||
assertThat(new DirectFieldAccessor(stompHandler).getPropertyValue("eventPublisher")).isNotNull();
|
||||
|
||||
httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/test/**");
|
||||
assertNotNull(httpRequestHandler);
|
||||
assertThat(httpRequestHandler).isNotNull();
|
||||
assertThat(httpRequestHandler).isInstanceOf(SockJsHttpRequestHandler.class);
|
||||
|
||||
SockJsHttpRequestHandler sockJsHttpRequestHandler = (SockJsHttpRequestHandler) httpRequestHandler;
|
||||
wsHandler = unwrapWebSocketHandler(sockJsHttpRequestHandler.getWebSocketHandler());
|
||||
assertNotNull(wsHandler);
|
||||
assertThat(wsHandler).isNotNull();
|
||||
assertThat(wsHandler).isInstanceOf(SubProtocolWebSocketHandler.class);
|
||||
assertNotNull(sockJsHttpRequestHandler.getSockJsService());
|
||||
assertThat(sockJsHttpRequestHandler.getSockJsService()).isNotNull();
|
||||
assertThat(sockJsHttpRequestHandler.getSockJsService()).isInstanceOf(DefaultSockJsService.class);
|
||||
|
||||
DefaultSockJsService defaultSockJsService = (DefaultSockJsService) sockJsHttpRequestHandler.getSockJsService();
|
||||
WebSocketTransportHandler wsTransportHandler = (WebSocketTransportHandler) defaultSockJsService
|
||||
.getTransportHandlers().get(TransportType.WEBSOCKET);
|
||||
assertNotNull(wsTransportHandler.getHandshakeHandler());
|
||||
assertThat(wsTransportHandler.getHandshakeHandler()).isNotNull();
|
||||
assertThat(wsTransportHandler.getHandshakeHandler()).isInstanceOf(TestHandshakeHandler.class);
|
||||
assertFalse(defaultSockJsService.shouldSuppressCors());
|
||||
assertThat(defaultSockJsService.shouldSuppressCors()).isFalse();
|
||||
|
||||
ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler) defaultSockJsService.getTaskScheduler();
|
||||
ScheduledThreadPoolExecutor executor = scheduler.getScheduledThreadPoolExecutor();
|
||||
assertEquals(Runtime.getRuntime().availableProcessors(), executor.getCorePoolSize());
|
||||
assertTrue(executor.getRemoveOnCancelPolicy());
|
||||
assertThat(executor.getCorePoolSize()).isEqualTo(Runtime.getRuntime().availableProcessors());
|
||||
assertThat(executor.getRemoveOnCancelPolicy()).isTrue();
|
||||
|
||||
interceptors = defaultSockJsService.getHandshakeInterceptors();
|
||||
assertThat(interceptors).extracting("class").containsExactly(FooTestInterceptor.class,
|
||||
BarTestInterceptor.class, OriginHandshakeInterceptor.class);
|
||||
assertTrue(defaultSockJsService.getAllowedOrigins().contains("https://mydomain3.com"));
|
||||
assertTrue(defaultSockJsService.getAllowedOrigins().contains("https://mydomain4.com"));
|
||||
assertThat(defaultSockJsService.getAllowedOrigins().contains("https://mydomain3.com")).isTrue();
|
||||
assertThat(defaultSockJsService.getAllowedOrigins().contains("https://mydomain4.com")).isTrue();
|
||||
|
||||
SimpUserRegistry userRegistry = this.appContext.getBean(SimpUserRegistry.class);
|
||||
assertNotNull(userRegistry);
|
||||
assertEquals(DefaultSimpUserRegistry.class, userRegistry.getClass());
|
||||
assertThat(userRegistry).isNotNull();
|
||||
assertThat(userRegistry.getClass()).isEqualTo(DefaultSimpUserRegistry.class);
|
||||
|
||||
UserDestinationResolver userDestResolver = this.appContext.getBean(UserDestinationResolver.class);
|
||||
assertNotNull(userDestResolver);
|
||||
assertThat(userDestResolver).isNotNull();
|
||||
assertThat(userDestResolver).isInstanceOf(DefaultUserDestinationResolver.class);
|
||||
DefaultUserDestinationResolver defaultUserDestResolver = (DefaultUserDestinationResolver) userDestResolver;
|
||||
assertEquals("/personal/", defaultUserDestResolver.getDestinationPrefix());
|
||||
assertThat(defaultUserDestResolver.getDestinationPrefix()).isEqualTo("/personal/");
|
||||
|
||||
UserDestinationMessageHandler userDestHandler = this.appContext.getBean(UserDestinationMessageHandler.class);
|
||||
assertNotNull(userDestHandler);
|
||||
assertThat(userDestHandler).isNotNull();
|
||||
|
||||
SimpleBrokerMessageHandler brokerMessageHandler = this.appContext.getBean(SimpleBrokerMessageHandler.class);
|
||||
assertNotNull(brokerMessageHandler);
|
||||
assertThat(brokerMessageHandler).isNotNull();
|
||||
Collection<String> prefixes = brokerMessageHandler.getDestinationPrefixes();
|
||||
assertEquals(Arrays.asList("/topic", "/queue"), new ArrayList<>(prefixes));
|
||||
assertThat(new ArrayList<>(prefixes)).isEqualTo(Arrays.asList("/topic", "/queue"));
|
||||
DefaultSubscriptionRegistry registry = (DefaultSubscriptionRegistry) brokerMessageHandler.getSubscriptionRegistry();
|
||||
assertEquals("my-selector", registry.getSelectorHeaderName());
|
||||
assertNotNull(brokerMessageHandler.getTaskScheduler());
|
||||
assertArrayEquals(new long[] {15000, 15000}, brokerMessageHandler.getHeartbeatValue());
|
||||
assertTrue(brokerMessageHandler.isPreservePublishOrder());
|
||||
assertThat(registry.getSelectorHeaderName()).isEqualTo("my-selector");
|
||||
assertThat(brokerMessageHandler.getTaskScheduler()).isNotNull();
|
||||
assertThat(brokerMessageHandler.getHeartbeatValue()).isEqualTo(new long[] {15000, 15000});
|
||||
assertThat(brokerMessageHandler.isPreservePublishOrder()).isTrue();
|
||||
|
||||
List<Class<? extends MessageHandler>> subscriberTypes = Arrays.asList(SimpAnnotationMethodMessageHandler.class,
|
||||
UserDestinationMessageHandler.class, SimpleBrokerMessageHandler.class);
|
||||
@@ -228,12 +221,12 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
|
||||
this.appContext.getBean("brokerChannelExecutor", ThreadPoolTaskExecutor.class));
|
||||
|
||||
assertNotNull(this.appContext.getBean("webSocketScopeConfigurer", CustomScopeConfigurer.class));
|
||||
assertThat(this.appContext.getBean("webSocketScopeConfigurer", CustomScopeConfigurer.class)).isNotNull();
|
||||
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(registry);
|
||||
Object pathMatcher = accessor.getPropertyValue("pathMatcher");
|
||||
String pathSeparator = (String) new DirectFieldAccessor(pathMatcher).getPropertyValue("pathSeparator");
|
||||
assertEquals(".", pathSeparator);
|
||||
assertThat(pathSeparator).isEqualTo(".");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -241,41 +234,41 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
loadBeanDefinitions("websocket-config-broker-relay.xml");
|
||||
|
||||
HandlerMapping hm = this.appContext.getBean(HandlerMapping.class);
|
||||
assertNotNull(hm);
|
||||
assertThat(hm).isNotNull();
|
||||
assertThat(hm).isInstanceOf(SimpleUrlHandlerMapping.class);
|
||||
|
||||
SimpleUrlHandlerMapping suhm = (SimpleUrlHandlerMapping) hm;
|
||||
assertThat(suhm.getUrlMap()).hasSize(1);
|
||||
assertEquals(2, suhm.getOrder());
|
||||
assertThat(suhm.getOrder()).isEqualTo(2);
|
||||
|
||||
HttpRequestHandler httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/foo/**");
|
||||
assertNotNull(httpRequestHandler);
|
||||
assertThat(httpRequestHandler).isNotNull();
|
||||
assertThat(httpRequestHandler).isInstanceOf(SockJsHttpRequestHandler.class);
|
||||
SockJsHttpRequestHandler sockJsHttpRequestHandler = (SockJsHttpRequestHandler) httpRequestHandler;
|
||||
WebSocketHandler wsHandler = unwrapWebSocketHandler(sockJsHttpRequestHandler.getWebSocketHandler());
|
||||
assertNotNull(wsHandler);
|
||||
assertThat(wsHandler).isNotNull();
|
||||
assertThat(wsHandler).isInstanceOf(SubProtocolWebSocketHandler.class);
|
||||
assertNotNull(sockJsHttpRequestHandler.getSockJsService());
|
||||
assertThat(sockJsHttpRequestHandler.getSockJsService()).isNotNull();
|
||||
|
||||
UserDestinationResolver userDestResolver = this.appContext.getBean(UserDestinationResolver.class);
|
||||
assertNotNull(userDestResolver);
|
||||
assertThat(userDestResolver).isNotNull();
|
||||
assertThat(userDestResolver).isInstanceOf(DefaultUserDestinationResolver.class);
|
||||
DefaultUserDestinationResolver defaultUserDestResolver = (DefaultUserDestinationResolver) userDestResolver;
|
||||
assertEquals("/user/", defaultUserDestResolver.getDestinationPrefix());
|
||||
assertThat(defaultUserDestResolver.getDestinationPrefix()).isEqualTo("/user/");
|
||||
|
||||
StompBrokerRelayMessageHandler messageBroker = this.appContext.getBean(StompBrokerRelayMessageHandler.class);
|
||||
assertNotNull(messageBroker);
|
||||
assertEquals("clientlogin", messageBroker.getClientLogin());
|
||||
assertEquals("clientpass", messageBroker.getClientPasscode());
|
||||
assertEquals("syslogin", messageBroker.getSystemLogin());
|
||||
assertEquals("syspass", messageBroker.getSystemPasscode());
|
||||
assertEquals("relayhost", messageBroker.getRelayHost());
|
||||
assertEquals(1234, messageBroker.getRelayPort());
|
||||
assertEquals("spring.io", messageBroker.getVirtualHost());
|
||||
assertEquals(5000, messageBroker.getSystemHeartbeatReceiveInterval());
|
||||
assertEquals(5000, messageBroker.getSystemHeartbeatSendInterval());
|
||||
assertThat(messageBroker).isNotNull();
|
||||
assertThat(messageBroker.getClientLogin()).isEqualTo("clientlogin");
|
||||
assertThat(messageBroker.getClientPasscode()).isEqualTo("clientpass");
|
||||
assertThat(messageBroker.getSystemLogin()).isEqualTo("syslogin");
|
||||
assertThat(messageBroker.getSystemPasscode()).isEqualTo("syspass");
|
||||
assertThat(messageBroker.getRelayHost()).isEqualTo("relayhost");
|
||||
assertThat(messageBroker.getRelayPort()).isEqualTo(1234);
|
||||
assertThat(messageBroker.getVirtualHost()).isEqualTo("spring.io");
|
||||
assertThat(messageBroker.getSystemHeartbeatReceiveInterval()).isEqualTo(5000);
|
||||
assertThat(messageBroker.getSystemHeartbeatSendInterval()).isEqualTo(5000);
|
||||
assertThat(messageBroker.getDestinationPrefixes()).containsExactlyInAnyOrder("/topic","/queue");
|
||||
assertTrue(messageBroker.isPreservePublishOrder());
|
||||
assertThat(messageBroker.isPreservePublishOrder()).isTrue();
|
||||
|
||||
List<Class<? extends MessageHandler>> subscriberTypes = Arrays.asList(SimpAnnotationMethodMessageHandler.class,
|
||||
UserDestinationMessageHandler.class, StompBrokerRelayMessageHandler.class);
|
||||
@@ -293,18 +286,18 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
|
||||
String destination = "/topic/unresolved-user-destination";
|
||||
UserDestinationMessageHandler userDestHandler = this.appContext.getBean(UserDestinationMessageHandler.class);
|
||||
assertEquals(destination, userDestHandler.getBroadcastDestination());
|
||||
assertNotNull(messageBroker.getSystemSubscriptions());
|
||||
assertSame(userDestHandler, messageBroker.getSystemSubscriptions().get(destination));
|
||||
assertThat(userDestHandler.getBroadcastDestination()).isEqualTo(destination);
|
||||
assertThat(messageBroker.getSystemSubscriptions()).isNotNull();
|
||||
assertThat(messageBroker.getSystemSubscriptions().get(destination)).isSameAs(userDestHandler);
|
||||
|
||||
destination = "/topic/simp-user-registry";
|
||||
UserRegistryMessageHandler userRegistryHandler = this.appContext.getBean(UserRegistryMessageHandler.class);
|
||||
assertEquals(destination, userRegistryHandler.getBroadcastDestination());
|
||||
assertNotNull(messageBroker.getSystemSubscriptions());
|
||||
assertSame(userRegistryHandler, messageBroker.getSystemSubscriptions().get(destination));
|
||||
assertThat(userRegistryHandler.getBroadcastDestination()).isEqualTo(destination);
|
||||
assertThat(messageBroker.getSystemSubscriptions()).isNotNull();
|
||||
assertThat(messageBroker.getSystemSubscriptions().get(destination)).isSameAs(userRegistryHandler);
|
||||
|
||||
SimpUserRegistry userRegistry = this.appContext.getBean(SimpUserRegistry.class);
|
||||
assertEquals(MultiServerUserRegistry.class, userRegistry.getClass());
|
||||
assertThat(userRegistry.getClass()).isEqualTo(MultiServerUserRegistry.class);
|
||||
|
||||
String name = "webSocketMessageBrokerStats";
|
||||
WebSocketMessageBrokerStats stats = this.appContext.getBean(name, WebSocketMessageBrokerStats.class);
|
||||
@@ -321,7 +314,7 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
"sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, " +
|
||||
"completed tasks = \\d\\]";
|
||||
|
||||
assertTrue("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual, actual.matches(expected));
|
||||
assertThat(actual.matches(expected)).as("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -331,19 +324,19 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
SimpAnnotationMethodMessageHandler annotationMethodMessageHandler =
|
||||
this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);
|
||||
|
||||
assertNotNull(annotationMethodMessageHandler);
|
||||
assertThat(annotationMethodMessageHandler).isNotNull();
|
||||
MessageConverter messageConverter = annotationMethodMessageHandler.getMessageConverter();
|
||||
assertNotNull(messageConverter);
|
||||
assertTrue(messageConverter instanceof CompositeMessageConverter);
|
||||
assertThat(messageConverter).isNotNull();
|
||||
assertThat(messageConverter instanceof CompositeMessageConverter).isTrue();
|
||||
|
||||
String name = MessageBrokerBeanDefinitionParser.MESSAGE_CONVERTER_BEAN_NAME;
|
||||
CompositeMessageConverter compositeMessageConverter = this.appContext.getBean(name, CompositeMessageConverter.class);
|
||||
assertNotNull(compositeMessageConverter);
|
||||
assertThat(compositeMessageConverter).isNotNull();
|
||||
|
||||
name = MessageBrokerBeanDefinitionParser.MESSAGING_TEMPLATE_BEAN_NAME;
|
||||
SimpMessagingTemplate simpMessagingTemplate = this.appContext.getBean(name, SimpMessagingTemplate.class);
|
||||
assertNotNull(simpMessagingTemplate);
|
||||
assertEquals("/personal/", simpMessagingTemplate.getUserDestinationPrefix());
|
||||
assertThat(simpMessagingTemplate).isNotNull();
|
||||
assertThat(simpMessagingTemplate.getUserDestinationPrefix()).isEqualTo("/personal/");
|
||||
|
||||
List<MessageConverter> converters = compositeMessageConverter.getConverters();
|
||||
assertThat(converters).hasSize(3);
|
||||
@@ -352,12 +345,12 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
assertThat(converters.get(2)).isInstanceOf(MappingJackson2MessageConverter.class);
|
||||
|
||||
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
|
||||
assertEquals(MimeTypeUtils.APPLICATION_JSON, ((DefaultContentTypeResolver) resolver).getDefaultMimeType());
|
||||
assertThat(((DefaultContentTypeResolver) resolver).getDefaultMimeType()).isEqualTo(MimeTypeUtils.APPLICATION_JSON);
|
||||
|
||||
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(annotationMethodMessageHandler);
|
||||
Object pathMatcher = handlerAccessor.getPropertyValue("pathMatcher");
|
||||
String pathSeparator = (String) new DirectFieldAccessor(pathMatcher).getPropertyValue("pathSeparator");
|
||||
assertEquals(".", pathSeparator);
|
||||
assertThat(pathSeparator).isEqualTo(".");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -368,8 +361,8 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);
|
||||
|
||||
Validator validator = annotationMethodMessageHandler.getValidator();
|
||||
assertNotNull(validator);
|
||||
assertSame(this.appContext.getBean("myValidator"), validator);
|
||||
assertThat(validator).isNotNull();
|
||||
assertThat(validator).isSameAs(this.appContext.getBean("myValidator"));
|
||||
assertThat(validator).isInstanceOf(TestValidator.class);
|
||||
|
||||
List<Class<? extends MessageHandler>> subscriberTypes = Arrays.asList(SimpAnnotationMethodMessageHandler.class,
|
||||
@@ -395,7 +388,7 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
|
||||
testExecutor("clientInboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60);
|
||||
testExecutor("clientOutboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60);
|
||||
assertFalse(this.appContext.containsBean("brokerChannelExecutor"));
|
||||
assertThat(this.appContext.containsBean("brokerChannelExecutor")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -405,14 +398,14 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
SimpAnnotationMethodMessageHandler handler = this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);
|
||||
|
||||
List<HandlerMethodArgumentResolver> customResolvers = handler.getCustomArgumentResolvers();
|
||||
assertEquals(2, customResolvers.size());
|
||||
assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(0)));
|
||||
assertTrue(handler.getArgumentResolvers().contains(customResolvers.get(1)));
|
||||
assertThat(customResolvers.size()).isEqualTo(2);
|
||||
assertThat(handler.getArgumentResolvers().contains(customResolvers.get(0))).isTrue();
|
||||
assertThat(handler.getArgumentResolvers().contains(customResolvers.get(1))).isTrue();
|
||||
|
||||
List<HandlerMethodReturnValueHandler> customHandlers = handler.getCustomReturnValueHandlers();
|
||||
assertEquals(2, customHandlers.size());
|
||||
assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(0)));
|
||||
assertTrue(handler.getReturnValueHandlers().contains(customHandlers.get(1)));
|
||||
assertThat(customHandlers.size()).isEqualTo(2);
|
||||
assertThat(handler.getReturnValueHandlers().contains(customHandlers.get(0))).isTrue();
|
||||
assertThat(handler.getReturnValueHandlers().contains(customHandlers.get(1))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -420,10 +413,10 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
loadBeanDefinitions("websocket-config-broker-converters.xml");
|
||||
|
||||
CompositeMessageConverter compositeConverter = this.appContext.getBean(CompositeMessageConverter.class);
|
||||
assertNotNull(compositeConverter);
|
||||
assertThat(compositeConverter).isNotNull();
|
||||
|
||||
assertEquals(4, compositeConverter.getConverters().size());
|
||||
assertEquals(StringMessageConverter.class, compositeConverter.getConverters().iterator().next().getClass());
|
||||
assertThat(compositeConverter.getConverters().size()).isEqualTo(4);
|
||||
assertThat(compositeConverter.getConverters().iterator().next().getClass()).isEqualTo(StringMessageConverter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -431,10 +424,10 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
loadBeanDefinitions("websocket-config-broker-converters-defaults-off.xml");
|
||||
|
||||
CompositeMessageConverter compositeConverter = this.appContext.getBean(CompositeMessageConverter.class);
|
||||
assertNotNull(compositeConverter);
|
||||
assertThat(compositeConverter).isNotNull();
|
||||
|
||||
assertEquals(1, compositeConverter.getConverters().size());
|
||||
assertEquals(StringMessageConverter.class, compositeConverter.getConverters().iterator().next().getClass());
|
||||
assertThat(compositeConverter.getConverters().size()).isEqualTo(1);
|
||||
assertThat(compositeConverter.getConverters().iterator().next().getClass()).isEqualTo(StringMessageConverter.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -444,20 +437,20 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
AbstractSubscribableChannel channel = this.appContext.getBean(channelName, AbstractSubscribableChannel.class);
|
||||
for (Class<? extends MessageHandler> subscriberType : subscriberTypes) {
|
||||
MessageHandler subscriber = this.appContext.getBean(subscriberType);
|
||||
assertNotNull("No subscription for " + subscriberType, subscriber);
|
||||
assertTrue(channel.hasSubscription(subscriber));
|
||||
assertThat(subscriber).as("No subscription for " + subscriberType).isNotNull();
|
||||
assertThat(channel.hasSubscription(subscriber)).isTrue();
|
||||
}
|
||||
List<ChannelInterceptor> interceptors = channel.getInterceptors();
|
||||
assertEquals(interceptorCount, interceptors.size());
|
||||
assertEquals(ImmutableMessageChannelInterceptor.class, interceptors.get(interceptors.size()-1).getClass());
|
||||
assertThat(interceptors.size()).isEqualTo(interceptorCount);
|
||||
assertThat(interceptors.get(interceptors.size() - 1).getClass()).isEqualTo(ImmutableMessageChannelInterceptor.class);
|
||||
}
|
||||
|
||||
private void testExecutor(String channelName, int corePoolSize, int maxPoolSize, int keepAliveSeconds) {
|
||||
ThreadPoolTaskExecutor taskExecutor =
|
||||
this.appContext.getBean(channelName + "Executor", ThreadPoolTaskExecutor.class);
|
||||
assertEquals(corePoolSize, taskExecutor.getCorePoolSize());
|
||||
assertEquals(maxPoolSize, taskExecutor.getMaxPoolSize());
|
||||
assertEquals(keepAliveSeconds, taskExecutor.getKeepAliveSeconds());
|
||||
assertThat(taskExecutor.getCorePoolSize()).isEqualTo(corePoolSize);
|
||||
assertThat(taskExecutor.getMaxPoolSize()).isEqualTo(maxPoolSize);
|
||||
assertThat(taskExecutor.getKeepAliveSeconds()).isEqualTo(keepAliveSeconds);
|
||||
}
|
||||
|
||||
private void loadBeanDefinitions(String fileName) {
|
||||
|
||||
@@ -30,9 +30,7 @@ import org.springframework.web.socket.messaging.SubProtocolHandler;
|
||||
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -65,16 +63,16 @@ public class WebMvcStompEndpointRegistryTests {
|
||||
this.endpointRegistry.addEndpoint("/stomp");
|
||||
|
||||
Map<String, SubProtocolHandler> protocolHandlers = webSocketHandler.getProtocolHandlerMap();
|
||||
assertEquals(3, protocolHandlers.size());
|
||||
assertNotNull(protocolHandlers.get("v10.stomp"));
|
||||
assertNotNull(protocolHandlers.get("v11.stomp"));
|
||||
assertNotNull(protocolHandlers.get("v12.stomp"));
|
||||
assertThat(protocolHandlers.size()).isEqualTo(3);
|
||||
assertThat(protocolHandlers.get("v10.stomp")).isNotNull();
|
||||
assertThat(protocolHandlers.get("v11.stomp")).isNotNull();
|
||||
assertThat(protocolHandlers.get("v12.stomp")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlerMapping() {
|
||||
SimpleUrlHandlerMapping hm = (SimpleUrlHandlerMapping) this.endpointRegistry.getHandlerMapping();
|
||||
assertEquals(0, hm.getUrlMap().size());
|
||||
assertThat(hm.getUrlMap().size()).isEqualTo(0);
|
||||
|
||||
UrlPathHelper pathHelper = new UrlPathHelper();
|
||||
this.endpointRegistry.setUrlPathHelper(pathHelper);
|
||||
@@ -82,13 +80,13 @@ public class WebMvcStompEndpointRegistryTests {
|
||||
this.endpointRegistry.addEndpoint("/stompOverSockJS").withSockJS();
|
||||
|
||||
//SPR-12403
|
||||
assertEquals(1, this.webSocketHandler.getProtocolHandlers().size());
|
||||
assertThat(this.webSocketHandler.getProtocolHandlers().size()).isEqualTo(1);
|
||||
|
||||
hm = (SimpleUrlHandlerMapping) this.endpointRegistry.getHandlerMapping();
|
||||
assertEquals(2, hm.getUrlMap().size());
|
||||
assertNotNull(hm.getUrlMap().get("/stompOverWebSocket"));
|
||||
assertNotNull(hm.getUrlMap().get("/stompOverSockJS/**"));
|
||||
assertSame(pathHelper, hm.getUrlPathHelper());
|
||||
assertThat(hm.getUrlMap().size()).isEqualTo(2);
|
||||
assertThat(hm.getUrlMap().get("/stompOverWebSocket")).isNotNull();
|
||||
assertThat(hm.getUrlMap().get("/stompOverSockJS/**")).isNotNull();
|
||||
assertThat(hm.getUrlPathHelper()).isSameAs(pathHelper);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,7 +97,7 @@ public class WebMvcStompEndpointRegistryTests {
|
||||
|
||||
Map<String, SubProtocolHandler> protocolHandlers = this.webSocketHandler.getProtocolHandlerMap();
|
||||
StompSubProtocolHandler stompHandler = (StompSubProtocolHandler) protocolHandlers.get("v12.stomp");
|
||||
assertSame(errorHandler, stompHandler.getErrorHandler());
|
||||
assertThat(stompHandler.getErrorHandler()).isSameAs(errorHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,11 +39,7 @@ import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -71,12 +67,12 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
|
||||
new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler);
|
||||
|
||||
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
|
||||
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
|
||||
assertNotNull(((WebSocketHttpRequestHandler) entry.getKey()).getWebSocketHandler());
|
||||
assertEquals(1, ((WebSocketHttpRequestHandler) entry.getKey()).getHandshakeInterceptors().size());
|
||||
assertEquals(Arrays.asList("/foo"), entry.getValue());
|
||||
assertThat(((WebSocketHttpRequestHandler) entry.getKey()).getWebSocketHandler()).isNotNull();
|
||||
assertThat(((WebSocketHttpRequestHandler) entry.getKey()).getHandshakeInterceptors().size()).isEqualTo(1);
|
||||
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,12 +83,12 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
|
||||
registration.setAllowedOrigins();
|
||||
|
||||
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
HttpRequestHandler handler = mappings.entrySet().iterator().next().getKey();
|
||||
WebSocketHttpRequestHandler wsHandler = (WebSocketHttpRequestHandler) handler;
|
||||
assertNotNull(wsHandler.getWebSocketHandler());
|
||||
assertEquals(1, wsHandler.getHandshakeInterceptors().size());
|
||||
assertEquals(OriginHandshakeInterceptor.class, wsHandler.getHandshakeInterceptors().get(0).getClass());
|
||||
assertThat(wsHandler.getWebSocketHandler()).isNotNull();
|
||||
assertThat(wsHandler.getHandshakeInterceptors().size()).isEqualTo(1);
|
||||
assertThat(wsHandler.getHandshakeInterceptors().get(0).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,12 +99,12 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
|
||||
registration.setAllowedOrigins();
|
||||
|
||||
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
HttpRequestHandler handler = mappings.entrySet().iterator().next().getKey();
|
||||
WebSocketHttpRequestHandler wsHandler = (WebSocketHttpRequestHandler) handler;
|
||||
assertNotNull(wsHandler.getWebSocketHandler());
|
||||
assertEquals(1, wsHandler.getHandshakeInterceptors().size());
|
||||
assertEquals(OriginHandshakeInterceptor.class, wsHandler.getHandshakeInterceptors().get(0).getClass());
|
||||
assertThat(wsHandler.getWebSocketHandler()).isNotNull();
|
||||
assertThat(wsHandler.getHandshakeInterceptors().size()).isEqualTo(1);
|
||||
assertThat(wsHandler.getHandshakeInterceptors().get(0).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,23 +116,23 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
|
||||
registration.setAllowedOrigins(origin).withSockJS();
|
||||
|
||||
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler)mappings.entrySet().iterator().next().getKey();
|
||||
assertNotNull(requestHandler.getSockJsService());
|
||||
assertThat(requestHandler.getSockJsService()).isNotNull();
|
||||
DefaultSockJsService sockJsService = (DefaultSockJsService)requestHandler.getSockJsService();
|
||||
assertTrue(sockJsService.getAllowedOrigins().contains(origin));
|
||||
assertFalse(sockJsService.shouldSuppressCors());
|
||||
assertThat(sockJsService.getAllowedOrigins().contains(origin)).isTrue();
|
||||
assertThat(sockJsService.shouldSuppressCors()).isFalse();
|
||||
|
||||
registration =
|
||||
new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler);
|
||||
registration.withSockJS().setAllowedOrigins(origin);
|
||||
mappings = registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
requestHandler = (SockJsHttpRequestHandler)mappings.entrySet().iterator().next().getKey();
|
||||
assertNotNull(requestHandler.getSockJsService());
|
||||
assertThat(requestHandler.getSockJsService()).isNotNull();
|
||||
sockJsService = (DefaultSockJsService)requestHandler.getSockJsService();
|
||||
assertTrue(sockJsService.getAllowedOrigins().contains(origin));
|
||||
assertFalse(sockJsService.shouldSuppressCors());
|
||||
assertThat(sockJsService.getAllowedOrigins().contains(origin)).isTrue();
|
||||
assertThat(sockJsService.shouldSuppressCors()).isFalse();
|
||||
}
|
||||
|
||||
@Test // SPR-12283
|
||||
@@ -147,11 +143,11 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
|
||||
registration.withSockJS().setSupressCors(true);
|
||||
|
||||
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler)mappings.entrySet().iterator().next().getKey();
|
||||
assertNotNull(requestHandler.getSockJsService());
|
||||
assertThat(requestHandler.getSockJsService()).isNotNull();
|
||||
DefaultSockJsService sockJsService = (DefaultSockJsService)requestHandler.getSockJsService();
|
||||
assertTrue(sockJsService.shouldSuppressCors());
|
||||
assertThat(sockJsService.shouldSuppressCors()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,17 +161,17 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
|
||||
registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor);
|
||||
|
||||
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
|
||||
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
|
||||
assertEquals(Arrays.asList("/foo"), entry.getValue());
|
||||
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo"));
|
||||
|
||||
WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey();
|
||||
assertNotNull(requestHandler.getWebSocketHandler());
|
||||
assertSame(handshakeHandler, requestHandler.getHandshakeHandler());
|
||||
assertEquals(2, requestHandler.getHandshakeInterceptors().size());
|
||||
assertEquals(interceptor, requestHandler.getHandshakeInterceptors().get(0));
|
||||
assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(1).getClass());
|
||||
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
|
||||
assertThat(requestHandler.getHandshakeHandler()).isSameAs(handshakeHandler);
|
||||
assertThat(requestHandler.getHandshakeInterceptors().size()).isEqualTo(2);
|
||||
assertThat(requestHandler.getHandshakeInterceptors().get(0)).isEqualTo(interceptor);
|
||||
assertThat(requestHandler.getHandshakeInterceptors().get(1).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -189,17 +185,17 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
|
||||
registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).setAllowedOrigins(origin);
|
||||
|
||||
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
|
||||
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
|
||||
assertEquals(Arrays.asList("/foo"), entry.getValue());
|
||||
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo"));
|
||||
|
||||
WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey();
|
||||
assertNotNull(requestHandler.getWebSocketHandler());
|
||||
assertSame(handshakeHandler, requestHandler.getHandshakeHandler());
|
||||
assertEquals(2, requestHandler.getHandshakeInterceptors().size());
|
||||
assertEquals(interceptor, requestHandler.getHandshakeInterceptors().get(0));
|
||||
assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(1).getClass());
|
||||
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
|
||||
assertThat(requestHandler.getHandshakeHandler()).isSameAs(handshakeHandler);
|
||||
assertThat(requestHandler.getHandshakeInterceptors().size()).isEqualTo(2);
|
||||
assertThat(requestHandler.getHandshakeInterceptors().get(0)).isEqualTo(interceptor);
|
||||
assertThat(requestHandler.getHandshakeInterceptors().get(1).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -213,23 +209,23 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
|
||||
registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).withSockJS();
|
||||
|
||||
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
|
||||
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
|
||||
assertEquals(Arrays.asList("/foo/**"), entry.getValue());
|
||||
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo/**"));
|
||||
|
||||
SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey();
|
||||
assertNotNull(requestHandler.getWebSocketHandler());
|
||||
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
|
||||
|
||||
DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService();
|
||||
assertNotNull(sockJsService);
|
||||
assertThat(sockJsService).isNotNull();
|
||||
|
||||
Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers();
|
||||
WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET);
|
||||
assertSame(handshakeHandler, transportHandler.getHandshakeHandler());
|
||||
assertEquals(2, sockJsService.getHandshakeInterceptors().size());
|
||||
assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0));
|
||||
assertEquals(OriginHandshakeInterceptor.class, sockJsService.getHandshakeInterceptors().get(1).getClass());
|
||||
assertThat(transportHandler.getHandshakeHandler()).isSameAs(handshakeHandler);
|
||||
assertThat(sockJsService.getHandshakeInterceptors().size()).isEqualTo(2);
|
||||
assertThat(sockJsService.getHandshakeInterceptors().get(0)).isEqualTo(interceptor);
|
||||
assertThat(sockJsService.getHandshakeInterceptors().get(1).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -245,25 +241,24 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
|
||||
.addInterceptors(interceptor).setAllowedOrigins(origin).withSockJS();
|
||||
|
||||
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
|
||||
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
|
||||
assertEquals(Arrays.asList("/foo/**"), entry.getValue());
|
||||
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo/**"));
|
||||
|
||||
SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey();
|
||||
assertNotNull(requestHandler.getWebSocketHandler());
|
||||
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
|
||||
|
||||
DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService();
|
||||
assertNotNull(sockJsService);
|
||||
assertThat(sockJsService).isNotNull();
|
||||
|
||||
Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers();
|
||||
WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET);
|
||||
assertSame(handshakeHandler, transportHandler.getHandshakeHandler());
|
||||
assertEquals(2, sockJsService.getHandshakeInterceptors().size());
|
||||
assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0));
|
||||
assertEquals(OriginHandshakeInterceptor.class,
|
||||
sockJsService.getHandshakeInterceptors().get(1).getClass());
|
||||
assertTrue(sockJsService.getAllowedOrigins().contains(origin));
|
||||
assertThat(transportHandler.getHandshakeHandler()).isSameAs(handshakeHandler);
|
||||
assertThat(sockJsService.getHandshakeInterceptors().size()).isEqualTo(2);
|
||||
assertThat(sockJsService.getHandshakeInterceptors().get(0)).isEqualTo(interceptor);
|
||||
assertThat(sockJsService.getHandshakeInterceptors().get(1).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
|
||||
assertThat(sockJsService.getAllowedOrigins().contains(origin)).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
||||
import org.springframework.web.socket.server.HandshakeHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for WebSocket Java server-side configuration.
|
||||
@@ -70,7 +70,7 @@ public class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTes
|
||||
new AbstractWebSocketHandler() {}, getWsBaseUrl() + "/ws").get();
|
||||
|
||||
TestHandler serverHandler = this.wac.getBean(TestHandler.class);
|
||||
assertTrue(serverHandler.connectLatch.await(2, TimeUnit.SECONDS));
|
||||
assertThat(serverHandler.connectLatch.await(2, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
session.close();
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTes
|
||||
new AbstractWebSocketHandler() {}, getWsBaseUrl() + "/sockjs/websocket").get();
|
||||
|
||||
TestHandler serverHandler = this.wac.getBean(TestHandler.class);
|
||||
assertTrue(serverHandler.connectLatch.await(2, TimeUnit.SECONDS));
|
||||
assertThat(serverHandler.connectLatch.await(2, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
session.close();
|
||||
}
|
||||
|
||||
@@ -36,10 +36,7 @@ import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test fixture for
|
||||
@@ -66,21 +63,21 @@ public class WebSocketHandlerRegistrationTests {
|
||||
this.registration.addHandler(handler, "/foo", "/bar");
|
||||
|
||||
List<Mapping> mappings = this.registration.getMappings();
|
||||
assertEquals(2, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(2);
|
||||
|
||||
Mapping m1 = mappings.get(0);
|
||||
assertEquals(handler, m1.webSocketHandler);
|
||||
assertEquals("/foo", m1.path);
|
||||
assertNotNull(m1.interceptors);
|
||||
assertEquals(1, m1.interceptors.length);
|
||||
assertEquals(OriginHandshakeInterceptor.class, m1.interceptors[0].getClass());
|
||||
assertThat(m1.webSocketHandler).isEqualTo(handler);
|
||||
assertThat(m1.path).isEqualTo("/foo");
|
||||
assertThat(m1.interceptors).isNotNull();
|
||||
assertThat(m1.interceptors.length).isEqualTo(1);
|
||||
assertThat(m1.interceptors[0].getClass()).isEqualTo(OriginHandshakeInterceptor.class);
|
||||
|
||||
Mapping m2 = mappings.get(1);
|
||||
assertEquals(handler, m2.webSocketHandler);
|
||||
assertEquals("/bar", m2.path);
|
||||
assertNotNull(m2.interceptors);
|
||||
assertEquals(1, m2.interceptors.length);
|
||||
assertEquals(OriginHandshakeInterceptor.class, m2.interceptors[0].getClass());
|
||||
assertThat(m2.webSocketHandler).isEqualTo(handler);
|
||||
assertThat(m2.path).isEqualTo("/bar");
|
||||
assertThat(m2.interceptors).isNotNull();
|
||||
assertThat(m2.interceptors.length).isEqualTo(1);
|
||||
assertThat(m2.interceptors[0].getClass()).isEqualTo(OriginHandshakeInterceptor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,15 +88,15 @@ public class WebSocketHandlerRegistrationTests {
|
||||
this.registration.addHandler(handler, "/foo").addInterceptors(interceptor);
|
||||
|
||||
List<Mapping> mappings = this.registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
|
||||
Mapping mapping = mappings.get(0);
|
||||
assertEquals(handler, mapping.webSocketHandler);
|
||||
assertEquals("/foo", mapping.path);
|
||||
assertNotNull(mapping.interceptors);
|
||||
assertEquals(2, mapping.interceptors.length);
|
||||
assertEquals(interceptor, mapping.interceptors[0]);
|
||||
assertEquals(OriginHandshakeInterceptor.class, mapping.interceptors[1].getClass());
|
||||
assertThat(mapping.webSocketHandler).isEqualTo(handler);
|
||||
assertThat(mapping.path).isEqualTo("/foo");
|
||||
assertThat(mapping.interceptors).isNotNull();
|
||||
assertThat(mapping.interceptors.length).isEqualTo(2);
|
||||
assertThat(mapping.interceptors[0]).isEqualTo(interceptor);
|
||||
assertThat(mapping.interceptors[1].getClass()).isEqualTo(OriginHandshakeInterceptor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,15 +107,15 @@ public class WebSocketHandlerRegistrationTests {
|
||||
this.registration.addHandler(handler, "/foo").addInterceptors(interceptor).setAllowedOrigins();
|
||||
|
||||
List<Mapping> mappings = this.registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
|
||||
Mapping mapping = mappings.get(0);
|
||||
assertEquals(handler, mapping.webSocketHandler);
|
||||
assertEquals("/foo", mapping.path);
|
||||
assertNotNull(mapping.interceptors);
|
||||
assertEquals(2, mapping.interceptors.length);
|
||||
assertEquals(interceptor, mapping.interceptors[0]);
|
||||
assertEquals(OriginHandshakeInterceptor.class, mapping.interceptors[1].getClass());
|
||||
assertThat(mapping.webSocketHandler).isEqualTo(handler);
|
||||
assertThat(mapping.path).isEqualTo("/foo");
|
||||
assertThat(mapping.interceptors).isNotNull();
|
||||
assertThat(mapping.interceptors.length).isEqualTo(2);
|
||||
assertThat(mapping.interceptors[0]).isEqualTo(interceptor);
|
||||
assertThat(mapping.interceptors[1].getClass()).isEqualTo(OriginHandshakeInterceptor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,15 +126,15 @@ public class WebSocketHandlerRegistrationTests {
|
||||
this.registration.addHandler(handler, "/foo").addInterceptors(interceptor).setAllowedOrigins("https://mydomain1.com");
|
||||
|
||||
List<Mapping> mappings = this.registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
|
||||
Mapping mapping = mappings.get(0);
|
||||
assertEquals(handler, mapping.webSocketHandler);
|
||||
assertEquals("/foo", mapping.path);
|
||||
assertNotNull(mapping.interceptors);
|
||||
assertEquals(2, mapping.interceptors.length);
|
||||
assertEquals(interceptor, mapping.interceptors[0]);
|
||||
assertEquals(OriginHandshakeInterceptor.class, mapping.interceptors[1].getClass());
|
||||
assertThat(mapping.webSocketHandler).isEqualTo(handler);
|
||||
assertThat(mapping.path).isEqualTo("/foo");
|
||||
assertThat(mapping.interceptors).isNotNull();
|
||||
assertThat(mapping.interceptors.length).isEqualTo(2);
|
||||
assertThat(mapping.interceptors[0]).isEqualTo(interceptor);
|
||||
assertThat(mapping.interceptors[1].getClass()).isEqualTo(OriginHandshakeInterceptor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -153,16 +150,16 @@ public class WebSocketHandlerRegistrationTests {
|
||||
this.registration.getSockJsServiceRegistration().setTaskScheduler(this.taskScheduler);
|
||||
|
||||
List<Mapping> mappings = this.registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
|
||||
Mapping mapping = mappings.get(0);
|
||||
assertEquals(handler, mapping.webSocketHandler);
|
||||
assertEquals("/foo/**", mapping.path);
|
||||
assertNotNull(mapping.sockJsService);
|
||||
assertTrue(mapping.sockJsService.getAllowedOrigins().contains("https://mydomain1.com"));
|
||||
assertThat(mapping.webSocketHandler).isEqualTo(handler);
|
||||
assertThat(mapping.path).isEqualTo("/foo/**");
|
||||
assertThat(mapping.sockJsService).isNotNull();
|
||||
assertThat(mapping.sockJsService.getAllowedOrigins().contains("https://mydomain1.com")).isTrue();
|
||||
List<HandshakeInterceptor> interceptors = mapping.sockJsService.getHandshakeInterceptors();
|
||||
assertEquals(interceptor, interceptors.get(0));
|
||||
assertEquals(OriginHandshakeInterceptor.class, interceptors.get(1).getClass());
|
||||
assertThat(interceptors.get(0)).isEqualTo(interceptor);
|
||||
assertThat(interceptors.get(1).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,12 +170,12 @@ public class WebSocketHandlerRegistrationTests {
|
||||
this.registration.addHandler(handler, "/foo").setHandshakeHandler(handshakeHandler);
|
||||
|
||||
List<Mapping> mappings = this.registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
|
||||
Mapping mapping = mappings.get(0);
|
||||
assertEquals(handler, mapping.webSocketHandler);
|
||||
assertEquals("/foo", mapping.path);
|
||||
assertSame(handshakeHandler, mapping.handshakeHandler);
|
||||
assertThat(mapping.webSocketHandler).isEqualTo(handler);
|
||||
assertThat(mapping.path).isEqualTo("/foo");
|
||||
assertThat(mapping.handshakeHandler).isSameAs(handshakeHandler);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -190,16 +187,16 @@ public class WebSocketHandlerRegistrationTests {
|
||||
this.registration.getSockJsServiceRegistration().setTaskScheduler(this.taskScheduler);
|
||||
|
||||
List<Mapping> mappings = this.registration.getMappings();
|
||||
assertEquals(1, mappings.size());
|
||||
assertThat(mappings.size()).isEqualTo(1);
|
||||
|
||||
Mapping mapping = mappings.get(0);
|
||||
assertEquals(handler, mapping.webSocketHandler);
|
||||
assertEquals("/foo/**", mapping.path);
|
||||
assertNotNull(mapping.sockJsService);
|
||||
assertThat(mapping.webSocketHandler).isEqualTo(handler);
|
||||
assertThat(mapping.path).isEqualTo("/foo/**");
|
||||
assertThat(mapping.sockJsService).isNotNull();
|
||||
|
||||
WebSocketTransportHandler transportHandler =
|
||||
(WebSocketTransportHandler) mapping.sockJsService.getTransportHandlers().get(TransportType.WEBSOCKET);
|
||||
assertSame(handshakeHandler, transportHandler.getHandshakeHandler());
|
||||
assertThat(transportHandler.getHandshakeHandler()).isSameAs(handshakeHandler);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,11 +60,7 @@ import org.springframework.web.socket.messaging.SubProtocolHandler;
|
||||
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
|
||||
import org.springframework.web.socket.server.support.WebSocketHttpRequestHandler;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -78,11 +74,11 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
|
||||
public void handlerMapping() {
|
||||
ApplicationContext config = createConfig(TestChannelConfig.class, TestConfigurer.class);
|
||||
SimpleUrlHandlerMapping hm = (SimpleUrlHandlerMapping) config.getBean(HandlerMapping.class);
|
||||
assertEquals(1, hm.getOrder());
|
||||
assertThat(hm.getOrder()).isEqualTo(1);
|
||||
|
||||
Map<String, Object> handlerMap = hm.getHandlerMap();
|
||||
assertEquals(1, handlerMap.size());
|
||||
assertNotNull(handlerMap.get("/simpleBroker"));
|
||||
assertThat(handlerMap.size()).isEqualTo(1);
|
||||
assertThat(handlerMap.get("/simpleBroker")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,7 +88,7 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
|
||||
SubProtocolWebSocketHandler webSocketHandler = config.getBean(SubProtocolWebSocketHandler.class);
|
||||
|
||||
List<ChannelInterceptor> interceptors = channel.getInterceptors();
|
||||
assertEquals(ImmutableMessageChannelInterceptor.class, interceptors.get(interceptors.size()-1).getClass());
|
||||
assertThat(interceptors.get(interceptors.size() - 1).getClass()).isEqualTo(ImmutableMessageChannelInterceptor.class);
|
||||
|
||||
TestWebSocketSession session = new TestWebSocketSession("s1");
|
||||
session.setOpen(true);
|
||||
@@ -103,10 +99,10 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
|
||||
|
||||
Message<?> message = channel.messages.get(0);
|
||||
StompHeaderAccessor accessor = StompHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
|
||||
assertNotNull(accessor);
|
||||
assertFalse(accessor.isMutable());
|
||||
assertEquals(SimpMessageType.MESSAGE, accessor.getMessageType());
|
||||
assertEquals("/foo", accessor.getDestination());
|
||||
assertThat(accessor).isNotNull();
|
||||
assertThat(accessor.isMutable()).isFalse();
|
||||
assertThat(accessor.getMessageType()).isEqualTo(SimpMessageType.MESSAGE);
|
||||
assertThat(accessor.getDestination()).isEqualTo("/foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,10 +112,10 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
|
||||
Set<MessageHandler> handlers = channel.getSubscribers();
|
||||
|
||||
List<ChannelInterceptor> interceptors = channel.getInterceptors();
|
||||
assertEquals(ImmutableMessageChannelInterceptor.class, interceptors.get(interceptors.size()-1).getClass());
|
||||
assertThat(interceptors.get(interceptors.size() - 1).getClass()).isEqualTo(ImmutableMessageChannelInterceptor.class);
|
||||
|
||||
assertEquals(1, handlers.size());
|
||||
assertTrue(handlers.contains(config.getBean(SubProtocolWebSocketHandler.class)));
|
||||
assertThat(handlers.size()).isEqualTo(1);
|
||||
assertThat(handlers.contains(config.getBean(SubProtocolWebSocketHandler.class))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,11 +125,11 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
|
||||
Set<MessageHandler> handlers = channel.getSubscribers();
|
||||
|
||||
List<ChannelInterceptor> interceptors = channel.getInterceptors();
|
||||
assertEquals(ImmutableMessageChannelInterceptor.class, interceptors.get(interceptors.size()-1).getClass());
|
||||
assertThat(interceptors.get(interceptors.size() - 1).getClass()).isEqualTo(ImmutableMessageChannelInterceptor.class);
|
||||
|
||||
assertEquals(2, handlers.size());
|
||||
assertTrue(handlers.contains(config.getBean(SimpleBrokerMessageHandler.class)));
|
||||
assertTrue(handlers.contains(config.getBean(UserDestinationMessageHandler.class)));
|
||||
assertThat(handlers.size()).isEqualTo(2);
|
||||
assertThat(handlers.contains(config.getBean(SimpleBrokerMessageHandler.class))).isTrue();
|
||||
assertThat(handlers.contains(config.getBean(UserDestinationMessageHandler.class))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,13 +137,13 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
|
||||
ApplicationContext config = createConfig(TestChannelConfig.class, TestConfigurer.class);
|
||||
SubProtocolWebSocketHandler subWsHandler = config.getBean(SubProtocolWebSocketHandler.class);
|
||||
|
||||
assertEquals(1024 * 1024, subWsHandler.getSendBufferSizeLimit());
|
||||
assertEquals(25 * 1000, subWsHandler.getSendTimeLimit());
|
||||
assertEquals(30 * 1000, subWsHandler.getTimeToFirstMessage());
|
||||
assertThat(subWsHandler.getSendBufferSizeLimit()).isEqualTo((1024 * 1024));
|
||||
assertThat(subWsHandler.getSendTimeLimit()).isEqualTo((25 * 1000));
|
||||
assertThat(subWsHandler.getTimeToFirstMessage()).isEqualTo((30 * 1000));
|
||||
|
||||
Map<String, SubProtocolHandler> handlerMap = subWsHandler.getProtocolHandlerMap();
|
||||
StompSubProtocolHandler protocolHandler = (StompSubProtocolHandler) handlerMap.get("v12.stomp");
|
||||
assertEquals(128 * 1024, protocolHandler.getMessageSizeLimit());
|
||||
assertThat(protocolHandler.getMessageSizeLimit()).isEqualTo((128 * 1024));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,12 +153,12 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
|
||||
String name = "messageBrokerSockJsTaskScheduler";
|
||||
ThreadPoolTaskScheduler taskScheduler = config.getBean(name, ThreadPoolTaskScheduler.class);
|
||||
ScheduledThreadPoolExecutor executor = taskScheduler.getScheduledThreadPoolExecutor();
|
||||
assertEquals(Runtime.getRuntime().availableProcessors(), executor.getCorePoolSize());
|
||||
assertTrue(executor.getRemoveOnCancelPolicy());
|
||||
assertThat(executor.getCorePoolSize()).isEqualTo(Runtime.getRuntime().availableProcessors());
|
||||
assertThat(executor.getRemoveOnCancelPolicy()).isTrue();
|
||||
|
||||
SimpleBrokerMessageHandler handler = config.getBean(SimpleBrokerMessageHandler.class);
|
||||
assertNotNull(handler.getTaskScheduler());
|
||||
assertArrayEquals(new long[] {15000, 15000}, handler.getHeartbeatValue());
|
||||
assertThat(handler.getTaskScheduler()).isNotNull();
|
||||
assertThat(handler.getHeartbeatValue()).isEqualTo(new long[] {15000, 15000});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -179,14 +175,14 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
|
||||
"outboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " +
|
||||
"sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\]";
|
||||
|
||||
assertTrue("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual, actual.matches(expected));
|
||||
assertThat(actual.matches(expected)).as("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webSocketHandlerDecorator() throws Exception {
|
||||
ApplicationContext config = createConfig(WebSocketHandlerDecoratorConfig.class);
|
||||
WebSocketHandler handler = config.getBean(SubProtocolWebSocketHandler.class);
|
||||
assertNotNull(handler);
|
||||
assertThat(handler).isNotNull();
|
||||
|
||||
SimpleUrlHandlerMapping mapping = (SimpleUrlHandlerMapping) config.getBean("stompWebSocketHandlerMapping");
|
||||
WebSocketHttpRequestHandler httpHandler = (WebSocketHttpRequestHandler) mapping.getHandlerMap().get("/test");
|
||||
@@ -194,7 +190,7 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
|
||||
|
||||
WebSocketSession session = new TestWebSocketSession("id");
|
||||
handler.afterConnectionEstablished(session);
|
||||
assertEquals(true, session.getAttributes().get("decorated"));
|
||||
assertThat(session.getAttributes().get("decorated")).isEqualTo(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link BeanCreatingHandlerProvider}.
|
||||
@@ -42,7 +42,7 @@ public class BeanCreatingHandlerProviderTests {
|
||||
BeanCreatingHandlerProvider<SimpleEchoHandler> provider =
|
||||
new BeanCreatingHandlerProvider<>(SimpleEchoHandler.class);
|
||||
|
||||
assertNotNull(provider.getHandler());
|
||||
assertThat(provider.getHandler()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -55,7 +55,7 @@ public class BeanCreatingHandlerProviderTests {
|
||||
new BeanCreatingHandlerProvider<>(EchoHandler.class);
|
||||
provider.setBeanFactory(context.getBeanFactory());
|
||||
|
||||
assertNotNull(provider.getHandler());
|
||||
assertThat(provider.getHandler()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -32,8 +32,6 @@ import org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorato
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ConcurrentWebSocketSessionDecorator}.
|
||||
@@ -54,12 +52,12 @@ public class ConcurrentWebSocketSessionDecoratorTests {
|
||||
TextMessage textMessage = new TextMessage("payload");
|
||||
decorator.sendMessage(textMessage);
|
||||
|
||||
assertEquals(1, session.getSentMessages().size());
|
||||
assertEquals(textMessage, session.getSentMessages().get(0));
|
||||
assertThat(session.getSentMessages().size()).isEqualTo(1);
|
||||
assertThat(session.getSentMessages().get(0)).isEqualTo(textMessage);
|
||||
|
||||
assertEquals(0, decorator.getBufferSize());
|
||||
assertEquals(0, decorator.getTimeSinceSendStarted());
|
||||
assertTrue(session.isOpen());
|
||||
assertThat(decorator.getBufferSize()).isEqualTo(0);
|
||||
assertThat(decorator.getTimeSinceSendStarted()).isEqualTo(0);
|
||||
assertThat(session.isOpen()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,16 +72,16 @@ public class ConcurrentWebSocketSessionDecoratorTests {
|
||||
sendBlockingMessage(decorator);
|
||||
|
||||
Thread.sleep(50);
|
||||
assertTrue(decorator.getTimeSinceSendStarted() > 0);
|
||||
assertThat(decorator.getTimeSinceSendStarted() > 0).isTrue();
|
||||
|
||||
TextMessage payload = new TextMessage("payload");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
decorator.sendMessage(payload);
|
||||
}
|
||||
|
||||
assertTrue(decorator.getTimeSinceSendStarted() > 0);
|
||||
assertEquals(5 * payload.getPayloadLength(), decorator.getBufferSize());
|
||||
assertTrue(session.isOpen());
|
||||
assertThat(decorator.getTimeSinceSendStarted() > 0).isTrue();
|
||||
assertThat(decorator.getBufferSize()).isEqualTo((5 * payload.getPayloadLength()));
|
||||
assertThat(session.isOpen()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,8 +126,8 @@ public class ConcurrentWebSocketSessionDecoratorTests {
|
||||
TextMessage message = new TextMessage(sb.toString());
|
||||
decorator.sendMessage(message);
|
||||
|
||||
assertEquals(1023, decorator.getBufferSize());
|
||||
assertTrue(session.isOpen());
|
||||
assertThat(decorator.getBufferSize()).isEqualTo(1023);
|
||||
assertThat(session.isOpen()).isTrue();
|
||||
|
||||
assertThatExceptionOfType(SessionLimitExceededException.class).isThrownBy(() ->
|
||||
decorator.sendMessage(message))
|
||||
@@ -159,8 +157,8 @@ public class ConcurrentWebSocketSessionDecoratorTests {
|
||||
decorator.sendMessage(message);
|
||||
}
|
||||
|
||||
assertEquals(1023, decorator.getBufferSize());
|
||||
assertTrue(session.isOpen());
|
||||
assertThat(decorator.getBufferSize()).isEqualTo(1023);
|
||||
assertThat(session.isOpen()).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@@ -172,10 +170,10 @@ public class ConcurrentWebSocketSessionDecoratorTests {
|
||||
WebSocketSession decorator = new ConcurrentWebSocketSessionDecorator(session, 10 * 1000, 1024);
|
||||
|
||||
decorator.close(CloseStatus.PROTOCOL_ERROR);
|
||||
assertEquals(CloseStatus.PROTOCOL_ERROR, session.getCloseStatus());
|
||||
assertThat(session.getCloseStatus()).isEqualTo(CloseStatus.PROTOCOL_ERROR);
|
||||
|
||||
decorator.close(CloseStatus.SERVER_ERROR);
|
||||
assertEquals("Should have been ignored", CloseStatus.PROTOCOL_ERROR, session.getCloseStatus());
|
||||
assertThat(session.getCloseStatus()).as("Should have been ignored").isEqualTo(CloseStatus.PROTOCOL_ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -202,15 +200,14 @@ public class ConcurrentWebSocketSessionDecoratorTests {
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(sentMessageLatch.await(5, TimeUnit.SECONDS));
|
||||
assertThat(sentMessageLatch.await(5, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
// ensure some send time elapses
|
||||
Thread.sleep(sendTimeLimit + 100);
|
||||
|
||||
decorator.close(CloseStatus.PROTOCOL_ERROR);
|
||||
|
||||
assertEquals("CloseStatus should have changed to SESSION_NOT_RELIABLE",
|
||||
CloseStatus.SESSION_NOT_RELIABLE, session.getCloseStatus());
|
||||
assertThat(session.getCloseStatus()).as("CloseStatus should have changed to SESSION_NOT_RELIABLE").isEqualTo(CloseStatus.SESSION_NOT_RELIABLE);
|
||||
}
|
||||
|
||||
private void sendBlockingMessage(ConcurrentWebSocketSessionDecorator session) throws InterruptedException {
|
||||
@@ -224,7 +221,7 @@ public class ConcurrentWebSocketSessionDecoratorTests {
|
||||
}
|
||||
});
|
||||
BlockingSession delegate = (BlockingSession) session.getDelegate();
|
||||
assertTrue(delegate.getSentMessageLatch().await(5, TimeUnit.SECONDS));
|
||||
assertThat(delegate.getSentMessageLatch().await(5, TimeUnit.SECONDS)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -60,7 +59,7 @@ public class ExceptionWebSocketHandlerDecoratorTests {
|
||||
|
||||
this.decorator.afterConnectionEstablished(this.session);
|
||||
|
||||
assertEquals(CloseStatus.SERVER_ERROR, this.session.getCloseStatus());
|
||||
assertThat(this.session.getCloseStatus()).isEqualTo(CloseStatus.SERVER_ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +72,7 @@ public class ExceptionWebSocketHandlerDecoratorTests {
|
||||
|
||||
this.decorator.handleMessage(this.session, message);
|
||||
|
||||
assertEquals(CloseStatus.SERVER_ERROR, this.session.getCloseStatus());
|
||||
assertThat(this.session.getCloseStatus()).isEqualTo(CloseStatus.SERVER_ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,7 +85,7 @@ public class ExceptionWebSocketHandlerDecoratorTests {
|
||||
|
||||
this.decorator.handleTransportError(this.session, exception);
|
||||
|
||||
assertEquals(CloseStatus.SERVER_ERROR, this.session.getCloseStatus());
|
||||
assertThat(this.session.getCloseStatus()).isEqualTo(CloseStatus.SERVER_ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,7 +98,7 @@ public class ExceptionWebSocketHandlerDecoratorTests {
|
||||
|
||||
this.decorator.afterConnectionClosed(this.session, closeStatus);
|
||||
|
||||
assertNull(this.session.getCloseStatus());
|
||||
assertThat(this.session.getCloseStatus()).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link PerConnectionWebSocketHandler}.
|
||||
@@ -47,13 +47,13 @@ public class PerConnectionWebSocketHandlerTests {
|
||||
WebSocketSession session = new TestWebSocketSession();
|
||||
handler.afterConnectionEstablished(session);
|
||||
|
||||
assertEquals(1, EchoHandler.initCount);
|
||||
assertEquals(0, EchoHandler.destroyCount);
|
||||
assertThat(EchoHandler.initCount).isEqualTo(1);
|
||||
assertThat(EchoHandler.destroyCount).isEqualTo(0);
|
||||
|
||||
handler.afterConnectionClosed(session, CloseStatus.NORMAL);
|
||||
|
||||
assertEquals(1, EchoHandler.initCount);
|
||||
assertEquals(1, EchoHandler.destroyCount);
|
||||
assertThat(EchoHandler.initCount).isEqualTo(1);
|
||||
assertThat(EchoHandler.destroyCount).isEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.web.socket.handler;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link WebSocketHandlerDecorator}.
|
||||
@@ -34,7 +34,7 @@ public class WebSocketHandlerDecoratorTests {
|
||||
WebSocketHandlerDecorator h2 = new WebSocketHandlerDecorator(h1);
|
||||
WebSocketHandlerDecorator h3 = new WebSocketHandlerDecorator(h2);
|
||||
|
||||
assertSame(h1, h3.getLastHandler());
|
||||
assertThat(h3.getLastHandler()).isSameAs(h1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,9 +33,7 @@ import org.springframework.messaging.simp.user.SimpUser;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test fixture for
|
||||
@@ -56,11 +54,11 @@ public class DefaultSimpUserRegistryTests {
|
||||
registry.onApplicationEvent(event);
|
||||
|
||||
SimpUser simpUser = registry.getUser("joe");
|
||||
assertNotNull(simpUser);
|
||||
assertThat(simpUser).isNotNull();
|
||||
|
||||
assertEquals(1, registry.getUserCount());
|
||||
assertEquals(1, simpUser.getSessions().size());
|
||||
assertNotNull(simpUser.getSession("123"));
|
||||
assertThat(registry.getUserCount()).isEqualTo(1);
|
||||
assertThat(simpUser.getSessions().size()).isEqualTo(1);
|
||||
assertThat(simpUser.getSession("123")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,13 +79,13 @@ public class DefaultSimpUserRegistryTests {
|
||||
registry.onApplicationEvent(event);
|
||||
|
||||
SimpUser simpUser = registry.getUser("joe");
|
||||
assertNotNull(simpUser);
|
||||
assertThat(simpUser).isNotNull();
|
||||
|
||||
assertEquals(1, registry.getUserCount());
|
||||
assertEquals(3, simpUser.getSessions().size());
|
||||
assertNotNull(simpUser.getSession("123"));
|
||||
assertNotNull(simpUser.getSession("456"));
|
||||
assertNotNull(simpUser.getSession("789"));
|
||||
assertThat(registry.getUserCount()).isEqualTo(1);
|
||||
assertThat(simpUser.getSessions().size()).isEqualTo(3);
|
||||
assertThat(simpUser.getSession("123")).isNotNull();
|
||||
assertThat(simpUser.getSession("456")).isNotNull();
|
||||
assertThat(simpUser.getSession("789")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,8 +106,8 @@ public class DefaultSimpUserRegistryTests {
|
||||
registry.onApplicationEvent(connectedEvent);
|
||||
|
||||
SimpUser simpUser = registry.getUser("joe");
|
||||
assertNotNull(simpUser);
|
||||
assertEquals(3, simpUser.getSessions().size());
|
||||
assertThat(simpUser).isNotNull();
|
||||
assertThat(simpUser.getSessions().size()).isEqualTo(3);
|
||||
|
||||
CloseStatus status = CloseStatus.GOING_AWAY;
|
||||
message = createMessage(SimpMessageType.DISCONNECT, "456");
|
||||
@@ -120,8 +118,8 @@ public class DefaultSimpUserRegistryTests {
|
||||
disconnectEvent = new SessionDisconnectEvent(this, message, "789", status, user);
|
||||
registry.onApplicationEvent(disconnectEvent);
|
||||
|
||||
assertEquals(1, simpUser.getSessions().size());
|
||||
assertNotNull(simpUser.getSession("123"));
|
||||
assertThat(simpUser.getSessions().size()).isEqualTo(1);
|
||||
assertThat(simpUser.getSession("123")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -152,13 +150,13 @@ public class DefaultSimpUserRegistryTests {
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(2, matches.size());
|
||||
assertThat(matches.size()).isEqualTo(2);
|
||||
|
||||
Iterator<SimpSubscription> iterator = matches.iterator();
|
||||
Set<String> sessionIds = new HashSet<>(2);
|
||||
sessionIds.add(iterator.next().getId());
|
||||
sessionIds.add(iterator.next().getId());
|
||||
assertEquals(new HashSet<>(Arrays.asList("sub1", "sub2")), sessionIds);
|
||||
assertThat(sessionIds).isEqualTo(new HashSet<>(Arrays.asList("sub1", "sub2")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -171,7 +169,7 @@ public class DefaultSimpUserRegistryTests {
|
||||
registry.onApplicationEvent(event);
|
||||
|
||||
SimpUser simpUser = registry.getUser("joe");
|
||||
assertNull(simpUser.getSession(null));
|
||||
assertThat(simpUser.getSession(null)).isNull();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,9 +25,7 @@ import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.messaging.support.MessageHeaderAccessor;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link StompSubProtocolErrorHandler}.
|
||||
@@ -51,10 +49,11 @@ public class StompSubProtocolErrorHandlerTests {
|
||||
Message<byte[]> actual = this.handler.handleClientMessageProcessingError(null, ex);
|
||||
|
||||
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(actual, StompHeaderAccessor.class);
|
||||
assertNotNull(accessor);
|
||||
assertEquals(StompCommand.ERROR, accessor.getCommand());
|
||||
assertEquals(ex.getMessage(), accessor.getMessage());
|
||||
assertArrayEquals(new byte[0], actual.getPayload());
|
||||
assertThat(accessor).isNotNull();
|
||||
assertThat(accessor.getCommand()).isEqualTo(StompCommand.ERROR);
|
||||
assertThat(accessor.getMessage()).isEqualTo(ex.getMessage());
|
||||
byte[] expecteds = new byte[0];
|
||||
assertThat(actual.getPayload()).isEqualTo(expecteds);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,8 +67,8 @@ public class StompSubProtocolErrorHandlerTests {
|
||||
Message<byte[]> actual = this.handler.handleClientMessageProcessingError(clientMessage, new Exception());
|
||||
|
||||
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(actual, StompHeaderAccessor.class);
|
||||
assertNotNull(accessor);
|
||||
assertEquals(receiptId, accessor.getReceiptId());
|
||||
assertThat(accessor).isNotNull();
|
||||
assertThat(accessor.getReceiptId()).isEqualTo(receiptId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,11 +60,6 @@ import org.springframework.web.socket.handler.TestWebSocketSession;
|
||||
import org.springframework.web.socket.sockjs.transport.SockJsSession;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -112,9 +107,9 @@ public class StompSubProtocolHandlerTests {
|
||||
Message<byte[]> message = MessageBuilder.createMessage(EMPTY_PAYLOAD, headers.getMessageHeaders());
|
||||
this.protocolHandler.handleMessageToClient(this.session, message);
|
||||
|
||||
assertEquals(1, this.session.getSentMessages().size());
|
||||
assertThat(this.session.getSentMessages().size()).isEqualTo(1);
|
||||
WebSocketMessage<?> textMessage = this.session.getSentMessages().get(0);
|
||||
assertEquals("CONNECTED\n" + "user-name:joe\n" + "\n" + "\u0000", textMessage.getPayload());
|
||||
assertThat(textMessage.getPayload()).isEqualTo(("CONNECTED\n" + "user-name:joe\n" + "\n" + "\u0000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,9 +121,9 @@ public class StompSubProtocolHandlerTests {
|
||||
Message<byte[]> message = MessageBuilder.createMessage(EMPTY_PAYLOAD, headers.getMessageHeaders());
|
||||
this.protocolHandler.handleMessageToClient(this.session, message);
|
||||
|
||||
assertEquals(1, this.session.getSentMessages().size());
|
||||
assertThat(this.session.getSentMessages().size()).isEqualTo(1);
|
||||
WebSocketMessage<?> textMessage = this.session.getSentMessages().get(0);
|
||||
assertEquals("CONNECTED\n" + "user-name:joe\n" + "\n" + "\u0000", textMessage.getPayload());
|
||||
assertThat(textMessage.getPayload()).isEqualTo(("CONNECTED\n" + "user-name:joe\n" + "\n" + "\u0000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,10 +140,10 @@ public class StompSubProtocolHandlerTests {
|
||||
Message<byte[]> ackMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, ackAccessor.getMessageHeaders());
|
||||
this.protocolHandler.handleMessageToClient(this.session, ackMessage);
|
||||
|
||||
assertEquals(1, this.session.getSentMessages().size());
|
||||
assertThat(this.session.getSentMessages().size()).isEqualTo(1);
|
||||
TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
|
||||
assertEquals("CONNECTED\n" + "version:1.2\n" + "heart-beat:15000,15000\n" +
|
||||
"user-name:joe\n" + "\n" + "\u0000", actual.getPayload());
|
||||
assertThat(actual.getPayload()).isEqualTo(("CONNECTED\n" + "version:1.2\n" + "heart-beat:15000,15000\n" +
|
||||
"user-name:joe\n" + "\n" + "\u0000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -164,10 +159,10 @@ public class StompSubProtocolHandlerTests {
|
||||
Message<byte[]> ackMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, ackAccessor.getMessageHeaders());
|
||||
this.protocolHandler.handleMessageToClient(this.session, ackMessage);
|
||||
|
||||
assertEquals(1, this.session.getSentMessages().size());
|
||||
assertThat(this.session.getSentMessages().size()).isEqualTo(1);
|
||||
TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
|
||||
assertEquals("CONNECTED\n" + "version:1.0\n" + "heart-beat:0,0\n" +
|
||||
"user-name:joe\n" + "\n" + "\u0000", actual.getPayload());
|
||||
assertThat(actual.getPayload()).isEqualTo(("CONNECTED\n" + "version:1.0\n" + "heart-beat:0,0\n" +
|
||||
"user-name:joe\n" + "\n" + "\u0000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,10 +176,10 @@ public class StompSubProtocolHandlerTests {
|
||||
Message<byte[]> ackMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, ackAccessor.getMessageHeaders());
|
||||
this.protocolHandler.handleMessageToClient(this.session, ackMessage);
|
||||
|
||||
assertEquals(1, this.session.getSentMessages().size());
|
||||
assertThat(this.session.getSentMessages().size()).isEqualTo(1);
|
||||
TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
|
||||
assertEquals("ERROR\n" + "message:Session closed.\n" + "content-length:0\n" +
|
||||
"\n\u0000", actual.getPayload());
|
||||
assertThat(actual.getPayload()).isEqualTo(("ERROR\n" + "message:Session closed.\n" + "content-length:0\n" +
|
||||
"\n\u0000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -199,9 +194,9 @@ public class StompSubProtocolHandlerTests {
|
||||
Message<byte[]> ackMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, ackAccessor.getMessageHeaders());
|
||||
this.protocolHandler.handleMessageToClient(this.session, ackMessage);
|
||||
|
||||
assertEquals(1, this.session.getSentMessages().size());
|
||||
assertThat(this.session.getSentMessages().size()).isEqualTo(1);
|
||||
TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
|
||||
assertEquals("RECEIPT\n" + "receipt-id:message-123\n" + "\n\u0000", actual.getPayload());
|
||||
assertThat(actual.getPayload()).isEqualTo(("RECEIPT\n" + "receipt-id:message-123\n" + "\n\u0000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -213,9 +208,9 @@ public class StompSubProtocolHandlerTests {
|
||||
Message<byte[]> ackMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
|
||||
this.protocolHandler.handleMessageToClient(this.session, ackMessage);
|
||||
|
||||
assertEquals(1, this.session.getSentMessages().size());
|
||||
assertThat(this.session.getSentMessages().size()).isEqualTo(1);
|
||||
TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
|
||||
assertEquals("\n", actual.getPayload());
|
||||
assertThat(actual.getPayload()).isEqualTo("\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,10 +253,10 @@ public class StompSubProtocolHandlerTests {
|
||||
Message<byte[]> message = MessageBuilder.createMessage(EMPTY_PAYLOAD, headers.getMessageHeaders());
|
||||
this.protocolHandler.handleMessageToClient(this.session, message);
|
||||
|
||||
assertEquals(1, this.session.getSentMessages().size());
|
||||
assertThat(this.session.getSentMessages().size()).isEqualTo(1);
|
||||
WebSocketMessage<?> textMessage = this.session.getSentMessages().get(0);
|
||||
assertTrue(((String) textMessage.getPayload()).contains("destination:/user/queue/foo\n"));
|
||||
assertFalse(((String) textMessage.getPayload()).contains(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION));
|
||||
assertThat(((String) textMessage.getPayload()).contains("destination:/user/queue/foo\n")).isTrue();
|
||||
assertThat(((String) textMessage.getPayload()).contains(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION)).isFalse();
|
||||
}
|
||||
|
||||
// SPR-12475
|
||||
@@ -281,9 +276,9 @@ public class StompSubProtocolHandlerTests {
|
||||
Message<byte[]> message = MessageBuilder.createMessage(payload, headers.getMessageHeaders());
|
||||
this.protocolHandler.handleMessageToClient(this.session, message);
|
||||
|
||||
assertEquals(1, this.session.getSentMessages().size());
|
||||
assertThat(this.session.getSentMessages().size()).isEqualTo(1);
|
||||
WebSocketMessage<?> webSocketMessage = this.session.getSentMessages().get(0);
|
||||
assertTrue(webSocketMessage instanceof BinaryMessage);
|
||||
assertThat(webSocketMessage instanceof BinaryMessage).isTrue();
|
||||
|
||||
// Empty payload
|
||||
|
||||
@@ -291,9 +286,9 @@ public class StompSubProtocolHandlerTests {
|
||||
message = MessageBuilder.createMessage(payload, headers.getMessageHeaders());
|
||||
this.protocolHandler.handleMessageToClient(this.session, message);
|
||||
|
||||
assertEquals(2, this.session.getSentMessages().size());
|
||||
assertThat(this.session.getSentMessages().size()).isEqualTo(2);
|
||||
webSocketMessage = this.session.getSentMessages().get(1);
|
||||
assertTrue(webSocketMessage instanceof TextMessage);
|
||||
assertThat(webSocketMessage instanceof TextMessage).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -307,22 +302,22 @@ public class StompSubProtocolHandlerTests {
|
||||
|
||||
verify(this.channel).send(this.messageCaptor.capture());
|
||||
Message<?> actual = this.messageCaptor.getValue();
|
||||
assertNotNull(actual);
|
||||
assertThat(actual).isNotNull();
|
||||
|
||||
assertEquals("s1", SimpMessageHeaderAccessor.getSessionId(actual.getHeaders()));
|
||||
assertNotNull(SimpMessageHeaderAccessor.getSessionAttributes(actual.getHeaders()));
|
||||
assertNotNull(SimpMessageHeaderAccessor.getUser(actual.getHeaders()));
|
||||
assertEquals("joe", SimpMessageHeaderAccessor.getUser(actual.getHeaders()).getName());
|
||||
assertNotNull(SimpMessageHeaderAccessor.getHeartbeat(actual.getHeaders()));
|
||||
assertArrayEquals(new long[] {10000, 10000}, SimpMessageHeaderAccessor.getHeartbeat(actual.getHeaders()));
|
||||
assertThat(SimpMessageHeaderAccessor.getSessionId(actual.getHeaders())).isEqualTo("s1");
|
||||
assertThat(SimpMessageHeaderAccessor.getSessionAttributes(actual.getHeaders())).isNotNull();
|
||||
assertThat(SimpMessageHeaderAccessor.getUser(actual.getHeaders())).isNotNull();
|
||||
assertThat(SimpMessageHeaderAccessor.getUser(actual.getHeaders()).getName()).isEqualTo("joe");
|
||||
assertThat(SimpMessageHeaderAccessor.getHeartbeat(actual.getHeaders())).isNotNull();
|
||||
assertThat(SimpMessageHeaderAccessor.getHeartbeat(actual.getHeaders())).isEqualTo(new long[] {10000, 10000});
|
||||
|
||||
StompHeaderAccessor stompAccessor = StompHeaderAccessor.wrap(actual);
|
||||
assertEquals(StompCommand.STOMP, stompAccessor.getCommand());
|
||||
assertEquals("guest", stompAccessor.getLogin());
|
||||
assertEquals("guest", stompAccessor.getPasscode());
|
||||
assertArrayEquals(new long[] {10000, 10000}, stompAccessor.getHeartbeat());
|
||||
assertEquals(new HashSet<>(Arrays.asList("1.1","1.0")), stompAccessor.getAcceptVersion());
|
||||
assertEquals(0, this.session.getSentMessages().size());
|
||||
assertThat(stompAccessor.getCommand()).isEqualTo(StompCommand.STOMP);
|
||||
assertThat(stompAccessor.getLogin()).isEqualTo("guest");
|
||||
assertThat(stompAccessor.getPasscode()).isEqualTo("guest");
|
||||
assertThat(stompAccessor.getHeartbeat()).isEqualTo(new long[] {10000, 10000});
|
||||
assertThat(stompAccessor.getAcceptVersion()).isEqualTo(new HashSet<>(Arrays.asList("1.1","1.0")));
|
||||
assertThat(this.session.getSentMessages().size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -343,8 +338,8 @@ public class StompSubProtocolHandlerTests {
|
||||
|
||||
TextMessage message = StompTextMessageBuilder.create(StompCommand.CONNECT).build();
|
||||
handler.handleMessageFromClient(this.session, message, channel);
|
||||
assertNotNull(mutable.get());
|
||||
assertTrue(mutable.get());
|
||||
assertThat(mutable.get()).isNotNull();
|
||||
assertThat(mutable.get()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -364,8 +359,8 @@ public class StompSubProtocolHandlerTests {
|
||||
|
||||
TextMessage message = StompTextMessageBuilder.create(StompCommand.CONNECT).build();
|
||||
handler.handleMessageFromClient(this.session, message, channel);
|
||||
assertNotNull(mutable.get());
|
||||
assertFalse(mutable.get());
|
||||
assertThat(mutable.get()).isNotNull();
|
||||
assertThat(mutable.get()).isFalse();
|
||||
}
|
||||
|
||||
@Test // SPR-14690
|
||||
@@ -383,11 +378,11 @@ public class StompSubProtocolHandlerTests {
|
||||
TextMessage wsMessage = StompTextMessageBuilder.create(StompCommand.CONNECT).build();
|
||||
handler.handleMessageFromClient(this.session, wsMessage, channel);
|
||||
|
||||
assertEquals(1, messageHandler.getMessages().size());
|
||||
assertThat(messageHandler.getMessages().size()).isEqualTo(1);
|
||||
Message<?> message = messageHandler.getMessages().get(0);
|
||||
Principal user = SimpMessageHeaderAccessor.getUser(message.getHeaders());
|
||||
assertNotNull(user);
|
||||
assertEquals("__pete__@gmail.com", user.getName());
|
||||
assertThat(user).isNotNull();
|
||||
assertThat(user.getName()).isEqualTo("__pete__@gmail.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -399,9 +394,9 @@ public class StompSubProtocolHandlerTests {
|
||||
this.protocolHandler.handleMessageFromClient(this.session, textMessage, this.channel);
|
||||
|
||||
verifyZeroInteractions(this.channel);
|
||||
assertEquals(1, this.session.getSentMessages().size());
|
||||
assertThat(this.session.getSentMessages().size()).isEqualTo(1);
|
||||
TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
|
||||
assertTrue(actual.getPayload().startsWith("ERROR"));
|
||||
assertThat(actual.getPayload().startsWith("ERROR")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -433,12 +428,12 @@ public class StompSubProtocolHandlerTests {
|
||||
|
||||
this.protocolHandler.afterSessionEnded(this.session, CloseStatus.BAD_DATA, this.channel);
|
||||
|
||||
assertEquals("Unexpected events " + publisher.events, 5, publisher.events.size());
|
||||
assertEquals(SessionConnectEvent.class, publisher.events.get(0).getClass());
|
||||
assertEquals(SessionConnectedEvent.class, publisher.events.get(1).getClass());
|
||||
assertEquals(SessionSubscribeEvent.class, publisher.events.get(2).getClass());
|
||||
assertEquals(SessionUnsubscribeEvent.class, publisher.events.get(3).getClass());
|
||||
assertEquals(SessionDisconnectEvent.class, publisher.events.get(4).getClass());
|
||||
assertThat(publisher.events.size()).as("Unexpected events " + publisher.events).isEqualTo(5);
|
||||
assertThat(publisher.events.get(0).getClass()).isEqualTo(SessionConnectEvent.class);
|
||||
assertThat(publisher.events.get(1).getClass()).isEqualTo(SessionConnectedEvent.class);
|
||||
assertThat(publisher.events.get(2).getClass()).isEqualTo(SessionSubscribeEvent.class);
|
||||
assertThat(publisher.events.get(3).getClass()).isEqualTo(SessionUnsubscribeEvent.class);
|
||||
assertThat(publisher.events.get(4).getClass()).isEqualTo(SessionDisconnectEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -456,27 +451,27 @@ public class StompSubProtocolHandlerTests {
|
||||
|
||||
verify(this.channel).send(this.messageCaptor.capture());
|
||||
Message<?> actual = this.messageCaptor.getValue();
|
||||
assertNotNull(actual);
|
||||
assertEquals(StompCommand.CONNECT, StompHeaderAccessor.wrap(actual).getCommand());
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(StompHeaderAccessor.wrap(actual).getCommand()).isEqualTo(StompCommand.CONNECT);
|
||||
reset(this.channel);
|
||||
|
||||
headers = StompHeaderAccessor.create(StompCommand.CONNECTED);
|
||||
message = MessageBuilder.createMessage(EMPTY_PAYLOAD, headers.getMessageHeaders());
|
||||
this.protocolHandler.handleMessageToClient(this.session, message);
|
||||
|
||||
assertEquals(1, this.session.getSentMessages().size());
|
||||
assertThat(this.session.getSentMessages().size()).isEqualTo(1);
|
||||
textMessage = (TextMessage) this.session.getSentMessages().get(0);
|
||||
assertEquals("CONNECTED\n" + "user-name:joe\n" + "\n" + "\u0000", textMessage.getPayload());
|
||||
assertThat(textMessage.getPayload()).isEqualTo(("CONNECTED\n" + "user-name:joe\n" + "\n" + "\u0000"));
|
||||
|
||||
this.protocolHandler.afterSessionEnded(this.session, CloseStatus.BAD_DATA, this.channel);
|
||||
|
||||
verify(this.channel).send(this.messageCaptor.capture());
|
||||
actual = this.messageCaptor.getValue();
|
||||
assertNotNull(actual);
|
||||
assertThat(actual).isNotNull();
|
||||
StompHeaderAccessor accessor = StompHeaderAccessor.wrap(actual);
|
||||
assertEquals(StompCommand.DISCONNECT, accessor.getCommand());
|
||||
assertEquals("s1", accessor.getSessionId());
|
||||
assertEquals("joe", accessor.getUser().getName());
|
||||
assertThat(accessor.getCommand()).isEqualTo(StompCommand.DISCONNECT);
|
||||
assertThat(accessor.getSessionId()).isEqualTo("s1");
|
||||
assertThat(accessor.getUser().getName()).isEqualTo("joe");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -507,10 +502,10 @@ public class StompSubProtocolHandlerTests {
|
||||
TextMessage textMessage = new TextMessage(new StompEncoder().encode(message));
|
||||
|
||||
this.protocolHandler.handleMessageFromClient(this.session, textMessage, testChannel);
|
||||
assertEquals(Collections.<WebSocketMessage<?>>emptyList(), session.getSentMessages());
|
||||
assertThat(session.getSentMessages()).isEqualTo(Collections.<WebSocketMessage<?>>emptyList());
|
||||
|
||||
this.protocolHandler.afterSessionEnded(this.session, CloseStatus.BAD_DATA, testChannel);
|
||||
assertEquals(Collections.<WebSocketMessage<?>>emptyList(), this.session.getSentMessages());
|
||||
assertThat(this.session.getSentMessages()).isEqualTo(Collections.<WebSocketMessage<?>>emptyList());
|
||||
verify(runnable, times(1)).run();
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerCo
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import org.springframework.web.socket.server.HandshakeHandler;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.web.socket.messaging.StompTextMessageBuilder.create;
|
||||
|
||||
/**
|
||||
@@ -94,7 +94,7 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration
|
||||
|
||||
SimpleController controller = this.wac.getBean(SimpleController.class);
|
||||
try {
|
||||
assertTrue(controller.latch.await(TIMEOUT, TimeUnit.SECONDS));
|
||||
assertThat(controller.latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
|
||||
}
|
||||
finally {
|
||||
session.close();
|
||||
@@ -113,7 +113,7 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration
|
||||
WebSocketSession session = doHandshake(clientHandler, "/ws").get();
|
||||
|
||||
try {
|
||||
assertTrue(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS));
|
||||
assertThat(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
|
||||
}
|
||||
finally {
|
||||
session.close();
|
||||
@@ -130,10 +130,10 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration
|
||||
WebSocketSession session = doHandshake(clientHandler, "/ws").get();
|
||||
|
||||
try {
|
||||
assertTrue(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS));
|
||||
assertThat(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
String payload = clientHandler.actual.get(1).getPayload();
|
||||
assertTrue("Expected STOMP MESSAGE, got " + payload, payload.startsWith("MESSAGE\n"));
|
||||
assertThat(payload.startsWith("MESSAGE\n")).as("Expected STOMP MESSAGE, got " + payload).isTrue();
|
||||
}
|
||||
finally {
|
||||
session.close();
|
||||
@@ -150,10 +150,10 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration
|
||||
WebSocketSession session = doHandshake(clientHandler, "/ws").get();
|
||||
|
||||
try {
|
||||
assertTrue(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS));
|
||||
assertThat(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
|
||||
String payload = clientHandler.actual.get(1).getPayload();
|
||||
assertTrue("Expected STOMP destination=/app/number, got " + payload, payload.contains(destHeader));
|
||||
assertTrue("Expected STOMP Payload=42, got " + payload, payload.contains("42"));
|
||||
assertThat(payload.contains(destHeader)).as("Expected STOMP destination=/app/number, got " + payload).isTrue();
|
||||
assertThat(payload.contains("42")).as("Expected STOMP Payload=42, got " + payload).isTrue();
|
||||
}
|
||||
finally {
|
||||
session.close();
|
||||
@@ -171,11 +171,11 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration
|
||||
WebSocketSession session = doHandshake(clientHandler, "/ws").get();
|
||||
|
||||
try {
|
||||
assertTrue(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS));
|
||||
assertThat(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
|
||||
String payload = clientHandler.actual.get(1).getPayload();
|
||||
assertTrue(payload.startsWith("MESSAGE\n"));
|
||||
assertTrue(payload.contains("destination:/user/queue/error\n"));
|
||||
assertTrue(payload.endsWith("Got error: Bad input\0"));
|
||||
assertThat(payload.startsWith("MESSAGE\n")).isTrue();
|
||||
assertThat(payload.contains("destination:/user/queue/error\n")).isTrue();
|
||||
assertThat(payload.endsWith("Got error: Bad input\0")).isTrue();
|
||||
}
|
||||
finally {
|
||||
session.close();
|
||||
@@ -194,11 +194,11 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration
|
||||
WebSocketSession session = doHandshake(clientHandler, "/ws").get();
|
||||
|
||||
try {
|
||||
assertTrue(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS));
|
||||
assertThat(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
|
||||
String payload = clientHandler.actual.get(1).getPayload();
|
||||
assertTrue(payload.startsWith("MESSAGE\n"));
|
||||
assertTrue(payload.contains("destination:/topic/scopedBeanValue\n"));
|
||||
assertTrue(payload.endsWith("55\0"));
|
||||
assertThat(payload.startsWith("MESSAGE\n")).isTrue();
|
||||
assertThat(payload.contains("destination:/topic/scopedBeanValue\n")).isTrue();
|
||||
assertThat(payload.endsWith("55\0")).isTrue();
|
||||
}
|
||||
finally {
|
||||
session.close();
|
||||
|
||||
@@ -32,12 +32,8 @@ import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator;
|
||||
import org.springframework.web.socket.handler.TestWebSocketSession;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isA;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -184,14 +180,13 @@ public class SubProtocolWebSocketHandlerTests {
|
||||
this.webSocketHandler.start();
|
||||
this.webSocketHandler.handleMessage(session1, new TextMessage("foo"));
|
||||
|
||||
assertTrue(session1.isOpen());
|
||||
assertNull(session1.getCloseStatus());
|
||||
assertThat(session1.isOpen()).isTrue();
|
||||
assertThat(session1.getCloseStatus()).isNull();
|
||||
|
||||
assertFalse(session2.isOpen());
|
||||
assertEquals(CloseStatus.SESSION_NOT_RELIABLE, session2.getCloseStatus());
|
||||
assertThat(session2.isOpen()).isFalse();
|
||||
assertThat(session2.getCloseStatus()).isEqualTo(CloseStatus.SESSION_NOT_RELIABLE);
|
||||
|
||||
assertNotEquals("lastSessionCheckTime not updated", sixtyOneSecondsAgo,
|
||||
handlerAccessor.getPropertyValue("lastSessionCheckTime"));
|
||||
assertThat(handlerAccessor.getPropertyValue("lastSessionCheckTime")).as("lastSessionCheckTime not updated").isNotEqualTo(sixtyOneSecondsAgo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link WebSocketAnnotationMethodMessageHandler}.
|
||||
@@ -73,7 +73,7 @@ public class WebSocketAnnotationMethodMessageHandlerTests {
|
||||
this.messageHandler.handleMessage(message);
|
||||
|
||||
TestControllerAdvice controllerAdvice = this.applicationContext.getBean(TestControllerAdvice.class);
|
||||
assertTrue(controllerAdvice.isExceptionHandled());
|
||||
assertThat(controllerAdvice.isExceptionHandled()).isTrue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ import org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrate
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link WebSocketStompClient}.
|
||||
@@ -119,7 +118,7 @@ public class WebSocketStompClientIntegrationTests {
|
||||
TestHandler testHandler = new TestHandler("/topic/foo", "payload");
|
||||
this.stompClient.connect(url, testHandler);
|
||||
|
||||
assertTrue(testHandler.awaitForMessageCount(1, 5000));
|
||||
assertThat(testHandler.awaitForMessageCount(1, 5000)).isTrue();
|
||||
assertThat(testHandler.getReceived()).containsExactly("payload");
|
||||
}
|
||||
|
||||
|
||||
@@ -46,10 +46,8 @@ import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.client.WebSocketClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.notNull;
|
||||
@@ -139,13 +137,13 @@ public class WebSocketStompClientTests {
|
||||
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
|
||||
verify(this.stompSession).handleMessage(captor.capture());
|
||||
Message<byte[]> message = captor.getValue();
|
||||
assertNotNull(message);
|
||||
assertThat(message).isNotNull();
|
||||
|
||||
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
|
||||
StompHeaders headers = StompHeaders.readOnlyStompHeaders(accessor.toNativeHeaderMap());
|
||||
assertEquals(StompCommand.SEND, accessor.getCommand());
|
||||
assertEquals("alpha", headers.getFirst("a"));
|
||||
assertEquals("Message payload", new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||
assertThat(accessor.getCommand()).isEqualTo(StompCommand.SEND);
|
||||
assertThat(headers.getFirst("a")).isEqualTo("alpha");
|
||||
assertThat(new String(message.getPayload(), StandardCharsets.UTF_8)).isEqualTo("Message payload");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -164,13 +162,13 @@ public class WebSocketStompClientTests {
|
||||
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
|
||||
verify(this.stompSession).handleMessage(captor.capture());
|
||||
Message<byte[]> message = captor.getValue();
|
||||
assertNotNull(message);
|
||||
assertThat(message).isNotNull();
|
||||
|
||||
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
|
||||
StompHeaders headers = StompHeaders.readOnlyStompHeaders(accessor.toNativeHeaderMap());
|
||||
assertEquals(StompCommand.SEND, accessor.getCommand());
|
||||
assertEquals("alpha", headers.getFirst("a"));
|
||||
assertEquals("Message payload", new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||
assertThat(accessor.getCommand()).isEqualTo(StompCommand.SEND);
|
||||
assertThat(headers.getFirst("a")).isEqualTo("alpha");
|
||||
assertThat(new String(message.getPayload(), StandardCharsets.UTF_8)).isEqualTo("Message payload");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -182,13 +180,13 @@ public class WebSocketStompClientTests {
|
||||
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
|
||||
verify(this.stompSession).handleMessage(captor.capture());
|
||||
Message<byte[]> message = captor.getValue();
|
||||
assertNotNull(message);
|
||||
assertThat(message).isNotNull();
|
||||
|
||||
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
|
||||
StompHeaders headers = StompHeaders.readOnlyStompHeaders(accessor.toNativeHeaderMap());
|
||||
assertEquals(StompCommand.SEND, accessor.getCommand());
|
||||
assertEquals("alpha", headers.getFirst("a"));
|
||||
assertEquals("Message payload", new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||
assertThat(accessor.getCommand()).isEqualTo(StompCommand.SEND);
|
||||
assertThat(headers.getFirst("a")).isEqualTo("alpha");
|
||||
assertThat(new String(message.getPayload(), StandardCharsets.UTF_8)).isEqualTo("Message payload");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -208,8 +206,8 @@ public class WebSocketStompClientTests {
|
||||
ArgumentCaptor<TextMessage> textMessageCaptor = ArgumentCaptor.forClass(TextMessage.class);
|
||||
verify(this.webSocketSession).sendMessage(textMessageCaptor.capture());
|
||||
TextMessage textMessage = textMessageCaptor.getValue();
|
||||
assertNotNull(textMessage);
|
||||
assertEquals("SEND\ndestination:/topic/foo\ncontent-length:7\n\npayload\0", textMessage.getPayload());
|
||||
assertThat(textMessage).isNotNull();
|
||||
assertThat(textMessage.getPayload()).isEqualTo("SEND\ndestination:/topic/foo\ncontent-length:7\n\npayload\0");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -224,28 +222,27 @@ public class WebSocketStompClientTests {
|
||||
ArgumentCaptor<BinaryMessage> binaryMessageCaptor = ArgumentCaptor.forClass(BinaryMessage.class);
|
||||
verify(this.webSocketSession).sendMessage(binaryMessageCaptor.capture());
|
||||
BinaryMessage binaryMessage = binaryMessageCaptor.getValue();
|
||||
assertNotNull(binaryMessage);
|
||||
assertEquals("SEND\ndestination:/b\ncontent-type:application/octet-stream\ncontent-length:7\n\npayload\0",
|
||||
new String(binaryMessage.getPayload().array(), StandardCharsets.UTF_8));
|
||||
assertThat(binaryMessage).isNotNull();
|
||||
assertThat(new String(binaryMessage.getPayload().array(), StandardCharsets.UTF_8)).isEqualTo("SEND\ndestination:/b\ncontent-type:application/octet-stream\ncontent-length:7\n\npayload\0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void heartbeatDefaultValue() throws Exception {
|
||||
WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class));
|
||||
assertArrayEquals(new long[] {0, 0}, stompClient.getDefaultHeartbeat());
|
||||
assertThat(stompClient.getDefaultHeartbeat()).isEqualTo(new long[] {0, 0});
|
||||
|
||||
StompHeaders connectHeaders = stompClient.processConnectHeaders(null);
|
||||
assertArrayEquals(new long[] {0, 0}, connectHeaders.getHeartbeat());
|
||||
assertThat(connectHeaders.getHeartbeat()).isEqualTo(new long[] {0, 0});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void heartbeatDefaultValueWithScheduler() throws Exception {
|
||||
WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class));
|
||||
stompClient.setTaskScheduler(mock(TaskScheduler.class));
|
||||
assertArrayEquals(new long[] {10000, 10000}, stompClient.getDefaultHeartbeat());
|
||||
assertThat(stompClient.getDefaultHeartbeat()).isEqualTo(new long[] {10000, 10000});
|
||||
|
||||
StompHeaders connectHeaders = stompClient.processConnectHeaders(null);
|
||||
assertArrayEquals(new long[] {10000, 10000}, connectHeaders.getHeartbeat());
|
||||
assertThat(connectHeaders.getHeartbeat()).isEqualTo(new long[] {10000, 10000});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -317,7 +314,7 @@ public class WebSocketStompClientTests {
|
||||
verifyNoMoreInteractions(this.stompSession);
|
||||
|
||||
WebSocketHandler webSocketHandler = this.webSocketHandlerCaptor.getValue();
|
||||
assertNotNull(webSocketHandler);
|
||||
assertThat(webSocketHandler).isNotNull();
|
||||
return webSocketHandler;
|
||||
}
|
||||
|
||||
@@ -340,7 +337,7 @@ public class WebSocketStompClientTests {
|
||||
}
|
||||
|
||||
Runnable inactivityTask = inactivityTaskCaptor.getValue();
|
||||
assertNotNull(inactivityTask);
|
||||
assertThat(inactivityTask).isNotNull();
|
||||
inactivityTask.run();
|
||||
|
||||
if (sleepTime > 0) {
|
||||
|
||||
@@ -28,8 +28,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link ServerEndpointRegistration}.
|
||||
@@ -50,7 +49,7 @@ public class ServerEndpointRegistrationTests {
|
||||
|
||||
EchoEndpoint endpoint = registration.getConfigurator().getEndpointInstance(EchoEndpoint.class);
|
||||
|
||||
assertNotNull(endpoint);
|
||||
assertThat(endpoint).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,7 +60,7 @@ public class ServerEndpointRegistrationTests {
|
||||
|
||||
EchoEndpoint actual = registration.getConfigurator().getEndpointInstance(EchoEndpoint.class);
|
||||
|
||||
assertSame(endpoint, actual);
|
||||
assertThat(actual).isSameAs(endpoint);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,8 +31,7 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SpringConfiguratorTests {
|
||||
|
||||
@@ -67,21 +66,21 @@ public class SpringConfiguratorTests {
|
||||
@Test
|
||||
public void getEndpointPerConnection() throws Exception {
|
||||
PerConnectionEchoEndpoint endpoint = this.configurator.getEndpointInstance(PerConnectionEchoEndpoint.class);
|
||||
assertNotNull(endpoint);
|
||||
assertThat(endpoint).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointSingletonByType() throws Exception {
|
||||
EchoEndpoint expected = this.webAppContext.getBean(EchoEndpoint.class);
|
||||
EchoEndpoint actual = this.configurator.getEndpointInstance(EchoEndpoint.class);
|
||||
assertSame(expected, actual);
|
||||
assertThat(actual).isSameAs(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointSingletonByComponentName() throws Exception {
|
||||
ComponentEchoEndpoint expected = this.webAppContext.getBean(ComponentEchoEndpoint.class);
|
||||
ComponentEchoEndpoint actual = this.configurator.getEndpointInstance(ComponentEchoEndpoint.class);
|
||||
assertSame(expected, actual);
|
||||
assertThat(actual).isSameAs(expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,8 +28,7 @@ import org.springframework.mock.web.test.MockHttpSession;
|
||||
import org.springframework.web.socket.AbstractHttpRequestTests;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link HttpSessionHandshakeInterceptor}.
|
||||
@@ -51,10 +50,10 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
|
||||
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
|
||||
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
|
||||
|
||||
assertEquals(3, attributes.size());
|
||||
assertEquals("bar", attributes.get("foo"));
|
||||
assertEquals("baz", attributes.get("bar"));
|
||||
assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME));
|
||||
assertThat(attributes.size()).isEqualTo(3);
|
||||
assertThat(attributes.get("foo")).isEqualTo("bar");
|
||||
assertThat(attributes.get("bar")).isEqualTo("baz");
|
||||
assertThat(attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)).isEqualTo("123");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,9 +69,9 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
|
||||
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(names);
|
||||
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
|
||||
|
||||
assertEquals(2, attributes.size());
|
||||
assertEquals("bar", attributes.get("foo"));
|
||||
assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME));
|
||||
assertThat(attributes.size()).isEqualTo(2);
|
||||
assertThat(attributes.get("foo")).isEqualTo("bar");
|
||||
assertThat(attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)).isEqualTo("123");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,8 +86,8 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
|
||||
interceptor.setCopyHttpSessionId(false);
|
||||
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
|
||||
|
||||
assertEquals(1, attributes.size());
|
||||
assertEquals("bar", attributes.get("foo"));
|
||||
assertThat(attributes.size()).isEqualTo(1);
|
||||
assertThat(attributes.get("foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
|
||||
@@ -104,8 +103,8 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
|
||||
interceptor.setCopyAllAttributes(false);
|
||||
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
|
||||
|
||||
assertEquals(1, attributes.size());
|
||||
assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME));
|
||||
assertThat(attributes.size()).isEqualTo(1);
|
||||
assertThat(attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)).isEqualTo("123");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,7 +115,7 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
|
||||
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
|
||||
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
|
||||
|
||||
assertNull(this.servletRequest.getSession(false));
|
||||
assertThat(this.servletRequest.getSession(false)).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,11 +32,8 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.socket.AbstractHttpRequestTests;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link OriginHandshakeInterceptor}.
|
||||
@@ -58,8 +55,8 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
||||
List<String> allowed = Collections.singletonList("https://mydomain1.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
||||
assertTrue(interceptor.beforeHandshake(request, response, wsHandler, attributes));
|
||||
assertNotEquals(servletResponse.getStatus(), HttpStatus.FORBIDDEN.value());
|
||||
assertThat(interceptor.beforeHandshake(request, response, wsHandler, attributes)).isTrue();
|
||||
assertThat(HttpStatus.FORBIDDEN.value()).isNotEqualTo((long) servletResponse.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,8 +66,8 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
||||
List<String> allowed = Collections.singletonList("https://mydomain2.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
||||
assertFalse(interceptor.beforeHandshake(request, response, wsHandler, attributes));
|
||||
assertEquals(servletResponse.getStatus(), HttpStatus.FORBIDDEN.value());
|
||||
assertThat(interceptor.beforeHandshake(request, response, wsHandler, attributes)).isFalse();
|
||||
assertThat(HttpStatus.FORBIDDEN.value()).isEqualTo(servletResponse.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,8 +77,8 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain2.com");
|
||||
List<String> allowed = Arrays.asList("https://mydomain1.com", "https://mydomain2.com", "http://mydomain3.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
||||
assertTrue(interceptor.beforeHandshake(request, response, wsHandler, attributes));
|
||||
assertNotEquals(servletResponse.getStatus(), HttpStatus.FORBIDDEN.value());
|
||||
assertThat(interceptor.beforeHandshake(request, response, wsHandler, attributes)).isTrue();
|
||||
assertThat(HttpStatus.FORBIDDEN.value()).isNotEqualTo((long) servletResponse.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,8 +88,8 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://www.mydomain4.com/");
|
||||
List<String> allowed = Arrays.asList("https://mydomain1.com", "https://mydomain2.com", "http://mydomain3.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
|
||||
assertFalse(interceptor.beforeHandshake(request, response, wsHandler, attributes));
|
||||
assertEquals(servletResponse.getStatus(), HttpStatus.FORBIDDEN.value());
|
||||
assertThat(interceptor.beforeHandshake(request, response, wsHandler, attributes)).isFalse();
|
||||
assertThat(HttpStatus.FORBIDDEN.value()).isEqualTo(servletResponse.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -104,8 +101,8 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||
Set<String> allowedOrigins = new ConcurrentSkipListSet<>();
|
||||
allowedOrigins.add("https://mydomain1.com");
|
||||
interceptor.setAllowedOrigins(allowedOrigins);
|
||||
assertFalse(interceptor.beforeHandshake(request, response, wsHandler, attributes));
|
||||
assertEquals(servletResponse.getStatus(), HttpStatus.FORBIDDEN.value());
|
||||
assertThat(interceptor.beforeHandshake(request, response, wsHandler, attributes)).isFalse();
|
||||
assertThat(HttpStatus.FORBIDDEN.value()).isEqualTo(servletResponse.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,8 +112,8 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor();
|
||||
interceptor.setAllowedOrigins(Collections.singletonList("*"));
|
||||
assertTrue(interceptor.beforeHandshake(request, response, wsHandler, attributes));
|
||||
assertNotEquals(servletResponse.getStatus(), HttpStatus.FORBIDDEN.value());
|
||||
assertThat(interceptor.beforeHandshake(request, response, wsHandler, attributes)).isTrue();
|
||||
assertThat(HttpStatus.FORBIDDEN.value()).isNotEqualTo((long) servletResponse.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,8 +123,8 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.com");
|
||||
this.servletRequest.setServerName("mydomain2.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Collections.emptyList());
|
||||
assertTrue(interceptor.beforeHandshake(request, response, wsHandler, attributes));
|
||||
assertNotEquals(servletResponse.getStatus(), HttpStatus.FORBIDDEN.value());
|
||||
assertThat(interceptor.beforeHandshake(request, response, wsHandler, attributes)).isTrue();
|
||||
assertThat(HttpStatus.FORBIDDEN.value()).isNotEqualTo((long) servletResponse.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,8 +134,8 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.com");
|
||||
this.servletRequest.setServerName("mydomain2.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Arrays.asList("http://mydomain1.com"));
|
||||
assertTrue(interceptor.beforeHandshake(request, response, wsHandler, attributes));
|
||||
assertNotEquals(servletResponse.getStatus(), HttpStatus.FORBIDDEN.value());
|
||||
assertThat(interceptor.beforeHandshake(request, response, wsHandler, attributes)).isTrue();
|
||||
assertThat(HttpStatus.FORBIDDEN.value()).isNotEqualTo((long) servletResponse.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,8 +145,8 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain3.com");
|
||||
this.servletRequest.setServerName("mydomain2.com");
|
||||
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Collections.emptyList());
|
||||
assertFalse(interceptor.beforeHandshake(request, response, wsHandler, attributes));
|
||||
assertEquals(servletResponse.getStatus(), HttpStatus.FORBIDDEN.value());
|
||||
assertThat(interceptor.beforeHandshake(request, response, wsHandler, attributes)).isFalse();
|
||||
assertThat(HttpStatus.FORBIDDEN.value()).isEqualTo(servletResponse.getStatus());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,10 +68,8 @@ import org.springframework.web.socket.server.HandshakeHandler;
|
||||
import org.springframework.web.socket.server.RequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Abstract base class for integration tests using the
|
||||
@@ -196,7 +194,7 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
|
||||
for (Map.Entry<String, HttpHeaders> entry : this.testFilter.requests.entrySet()) {
|
||||
HttpHeaders httpHeaders = entry.getValue();
|
||||
assertEquals("No auth header for: " + entry.getKey(), "123", httpHeaders.getFirst("auth"));
|
||||
assertThat(httpHeaders.getFirst("auth")).as("No auth header for: " + entry.getKey()).isEqualTo("123");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +233,7 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
}
|
||||
}
|
||||
);
|
||||
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
|
||||
assertThat(latch.await(5000, TimeUnit.MILLISECONDS)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -245,7 +243,7 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
TestClientHandler handler = new TestClientHandler();
|
||||
initSockJsClient(createWebSocketTransport(), createXhrTransport());
|
||||
WebSocketSession session = this.sockJsClient.doHandshake(handler, this.baseUrl + "/echo").get();
|
||||
assertEquals("Fallback didn't occur", XhrClientSockJsSession.class, session.getClass());
|
||||
assertThat(session.getClass()).as("Fallback didn't occur").isEqualTo(XhrClientSockJsSession.class);
|
||||
TextMessage message = new TextMessage("message1");
|
||||
session.sendMessage(message);
|
||||
handler.awaitMessage(message, 5000);
|
||||
@@ -259,7 +257,7 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
initSockJsClient(createXhrTransport());
|
||||
this.sockJsClient.setConnectTimeoutScheduler(this.wac.getBean(ThreadPoolTaskScheduler.class));
|
||||
WebSocketSession clientSession = sockJsClient.doHandshake(clientHandler, this.baseUrl + "/echo").get();
|
||||
assertEquals("Fallback didn't occur", XhrClientSockJsSession.class, clientSession.getClass());
|
||||
assertThat(clientSession.getClass()).as("Fallback didn't occur").isEqualTo(XhrClientSockJsSession.class);
|
||||
TextMessage message = new TextMessage("message1");
|
||||
clientSession.sendMessage(message);
|
||||
clientHandler.awaitMessage(message, 5000);
|
||||
@@ -281,9 +279,9 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
}
|
||||
handler.awaitMessageCount(messageCount, 5000);
|
||||
for (TextMessage message : messages) {
|
||||
assertTrue("Message not received: " + message, handler.receivedMessages.remove(message));
|
||||
assertThat(handler.receivedMessages.remove(message)).as("Message not received: " + message).isTrue();
|
||||
}
|
||||
assertEquals("Remaining messages: " + handler.receivedMessages, 0, handler.receivedMessages.size());
|
||||
assertThat(handler.receivedMessages.size()).as("Remaining messages: " + handler.receivedMessages).isEqualTo(0);
|
||||
session.close();
|
||||
}
|
||||
|
||||
@@ -295,7 +293,7 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
this.sockJsClient.doHandshake(clientHandler, headers, new URI(this.baseUrl + "/test")).get();
|
||||
TestServerHandler serverHandler = this.wac.getBean(TestServerHandler.class);
|
||||
|
||||
assertNotNull("afterConnectionEstablished should have been called", clientHandler.session);
|
||||
assertThat(clientHandler.session).as("afterConnectionEstablished should have been called").isNotNull();
|
||||
serverHandler.awaitSession(5000);
|
||||
|
||||
TextMessage message = new TextMessage("message1");
|
||||
@@ -372,7 +370,7 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
public void awaitMessage(TextMessage expected, long timeToWait) throws InterruptedException {
|
||||
TextMessage actual = this.receivedMessages.poll(timeToWait, TimeUnit.MILLISECONDS);
|
||||
if (actual != null) {
|
||||
assertEquals(expected, actual);
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
else if (this.transportError != null) {
|
||||
throw new AssertionError("Transport error", this.transportError);
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
@@ -76,7 +75,7 @@ public class ClientSockJsSessionTests {
|
||||
assertThat(this.session.isOpen()).isFalse();
|
||||
this.session.handleFrame(SockJsFrame.openFrame().getContent());
|
||||
assertThat(this.session.isOpen()).isTrue();
|
||||
assertTrue(this.connectFuture.isDone());
|
||||
assertThat(this.connectFuture.isDone()).isTrue();
|
||||
assertThat(this.connectFuture.get()).isSameAs(this.session);
|
||||
verify(this.handler).afterConnectionEstablished(this.session);
|
||||
verifyNoMoreInteractions(this.handler);
|
||||
|
||||
@@ -33,10 +33,8 @@ import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.sockjs.frame.Jackson2SockJsMessageCodec;
|
||||
import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -78,7 +76,7 @@ public class DefaultTransportRequestTests {
|
||||
request.connect(null, this.connectFuture);
|
||||
WebSocketSession session = mock(WebSocketSession.class);
|
||||
this.webSocketTransport.getConnectCallback().onSuccess(session);
|
||||
assertSame(session, this.connectFuture.get());
|
||||
assertThat(this.connectFuture.get()).isSameAs(session);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,12 +88,12 @@ public class DefaultTransportRequestTests {
|
||||
|
||||
// Transport error => fallback
|
||||
this.webSocketTransport.getConnectCallback().onFailure(new IOException("Fake exception 1"));
|
||||
assertFalse(this.connectFuture.isDone());
|
||||
assertTrue(this.xhrTransport.invoked());
|
||||
assertThat(this.connectFuture.isDone()).isFalse();
|
||||
assertThat(this.xhrTransport.invoked()).isTrue();
|
||||
|
||||
// Transport error => no more fallback
|
||||
this.xhrTransport.getConnectCallback().onFailure(new IOException("Fake exception 2"));
|
||||
assertTrue(this.connectFuture.isDone());
|
||||
assertThat(this.connectFuture.isDone()).isTrue();
|
||||
assertThatExceptionOfType(ExecutionException.class).isThrownBy(
|
||||
this.connectFuture::get)
|
||||
.withMessageContaining("Fake exception 2");
|
||||
@@ -112,8 +110,8 @@ public class DefaultTransportRequestTests {
|
||||
request1.addTimeoutTask(sessionCleanupTask);
|
||||
request1.connect(null, this.connectFuture);
|
||||
|
||||
assertTrue(this.webSocketTransport.invoked());
|
||||
assertFalse(this.xhrTransport.invoked());
|
||||
assertThat(this.webSocketTransport.invoked()).isTrue();
|
||||
assertThat(this.xhrTransport.invoked()).isFalse();
|
||||
|
||||
// Get and invoke the scheduled timeout task
|
||||
ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class);
|
||||
@@ -121,7 +119,7 @@ public class DefaultTransportRequestTests {
|
||||
verifyNoMoreInteractions(scheduler);
|
||||
taskCaptor.getValue().run();
|
||||
|
||||
assertTrue(this.xhrTransport.invoked());
|
||||
assertThat(this.xhrTransport.invoked()).isTrue();
|
||||
verify(sessionCleanupTask).run();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,7 @@ import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.sockjs.client.TestTransport.XhrTestTransport;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -87,7 +85,7 @@ public class SockJsClientTests {
|
||||
public void connectWebSocket() throws Exception {
|
||||
setupInfoRequest(true);
|
||||
this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback);
|
||||
assertTrue(this.webSocketTransport.invoked());
|
||||
assertThat(this.webSocketTransport.invoked()).isTrue();
|
||||
WebSocketSession session = mock(WebSocketSession.class);
|
||||
this.webSocketTransport.getConnectCallback().onSuccess(session);
|
||||
verify(this.connectCallback).onSuccess(session);
|
||||
@@ -98,9 +96,9 @@ public class SockJsClientTests {
|
||||
public void connectWebSocketDisabled() throws URISyntaxException {
|
||||
setupInfoRequest(false);
|
||||
this.sockJsClient.doHandshake(handler, URL);
|
||||
assertFalse(this.webSocketTransport.invoked());
|
||||
assertTrue(this.xhrTransport.invoked());
|
||||
assertTrue(this.xhrTransport.getRequest().getTransportUrl().toString().endsWith("xhr_streaming"));
|
||||
assertThat(this.webSocketTransport.invoked()).isFalse();
|
||||
assertThat(this.xhrTransport.invoked()).isTrue();
|
||||
assertThat(this.xhrTransport.getRequest().getTransportUrl().toString().endsWith("xhr_streaming")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,9 +106,9 @@ public class SockJsClientTests {
|
||||
setupInfoRequest(false);
|
||||
this.xhrTransport.setStreamingDisabled(true);
|
||||
this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback);
|
||||
assertFalse(this.webSocketTransport.invoked());
|
||||
assertTrue(this.xhrTransport.invoked());
|
||||
assertTrue(this.xhrTransport.getRequest().getTransportUrl().toString().endsWith("xhr"));
|
||||
assertThat(this.webSocketTransport.invoked()).isFalse();
|
||||
assertThat(this.xhrTransport.invoked()).isTrue();
|
||||
assertThat(this.xhrTransport.getRequest().getTransportUrl().toString().endsWith("xhr")).isTrue();
|
||||
}
|
||||
|
||||
// SPR-13254
|
||||
@@ -126,14 +124,14 @@ public class SockJsClientTests {
|
||||
this.sockJsClient.doHandshake(handler, headers, new URI(URL)).addCallback(this.connectCallback);
|
||||
|
||||
HttpHeaders httpHeaders = headersCaptor.getValue();
|
||||
assertEquals(2, httpHeaders.size());
|
||||
assertEquals("bar", httpHeaders.getFirst("foo"));
|
||||
assertEquals("123", httpHeaders.getFirst("auth"));
|
||||
assertThat(httpHeaders.size()).isEqualTo(2);
|
||||
assertThat(httpHeaders.getFirst("foo")).isEqualTo("bar");
|
||||
assertThat(httpHeaders.getFirst("auth")).isEqualTo("123");
|
||||
|
||||
httpHeaders = this.xhrTransport.getRequest().getHttpRequestHeaders();
|
||||
assertEquals(2, httpHeaders.size());
|
||||
assertEquals("bar", httpHeaders.getFirst("foo"));
|
||||
assertEquals("123", httpHeaders.getFirst("auth"));
|
||||
assertThat(httpHeaders.size()).isEqualTo(2);
|
||||
assertThat(httpHeaders.getFirst("foo")).isEqualTo("bar");
|
||||
assertThat(httpHeaders.getFirst("auth")).isEqualTo("123");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,10 +145,10 @@ public class SockJsClientTests {
|
||||
this.sockJsClient.setHttpHeaderNames("auth");
|
||||
this.sockJsClient.doHandshake(handler, headers, new URI(URL)).addCallback(this.connectCallback);
|
||||
|
||||
assertEquals(1, headersCaptor.getValue().size());
|
||||
assertEquals("123", headersCaptor.getValue().getFirst("auth"));
|
||||
assertEquals(1, this.xhrTransport.getRequest().getHttpRequestHeaders().size());
|
||||
assertEquals("123", this.xhrTransport.getRequest().getHttpRequestHeaders().getFirst("auth"));
|
||||
assertThat(headersCaptor.getValue().size()).isEqualTo(1);
|
||||
assertThat(headersCaptor.getValue().getFirst("auth")).isEqualTo("123");
|
||||
assertThat(this.xhrTransport.getRequest().getHttpRequestHeaders().size()).isEqualTo(1);
|
||||
assertThat(this.xhrTransport.getRequest().getHttpRequestHeaders().getFirst("auth")).isEqualTo("123");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -175,8 +173,8 @@ public class SockJsClientTests {
|
||||
given(this.infoReceiver.executeInfoRequest(any(), any())).willThrow(exception);
|
||||
this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback);
|
||||
verify(this.connectCallback).onFailure(exception);
|
||||
assertFalse(this.webSocketTransport.invoked());
|
||||
assertFalse(this.xhrTransport.invoked());
|
||||
assertThat(this.webSocketTransport.invoked()).isFalse();
|
||||
assertThat(this.xhrTransport.invoked()).isFalse();
|
||||
}
|
||||
|
||||
private ArgumentCaptor<HttpHeaders> setupInfoRequest(boolean webSocketEnabled) {
|
||||
|
||||
@@ -23,8 +23,6 @@ import org.junit.Test;
|
||||
import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit tests for {@code SockJsUrlInfo}.
|
||||
@@ -37,13 +35,13 @@ public class SockJsUrlInfoTests {
|
||||
public void serverId() throws Exception {
|
||||
SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com"));
|
||||
int serverId = Integer.valueOf(info.getServerId());
|
||||
assertTrue("Invalid serverId: " + serverId, serverId >= 0 && serverId < 1000);
|
||||
assertThat(serverId >= 0 && serverId < 1000).as("Invalid serverId: " + serverId).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sessionId() throws Exception {
|
||||
SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com"));
|
||||
assertEquals("Invalid sessionId: " + info.getSessionId(), 32, info.getSessionId().length());
|
||||
assertThat(info.getSessionId().length()).as("Invalid sessionId: " + info.getSessionId()).isEqualTo(32);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -31,10 +31,8 @@ import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -52,7 +50,7 @@ public class XhrTransportTests {
|
||||
public void infoResponse() throws Exception {
|
||||
TestXhrTransport transport = new TestXhrTransport();
|
||||
transport.infoResponseToReturn = new ResponseEntity<>("body", HttpStatus.OK);
|
||||
assertEquals("body", transport.executeInfoRequest(new URI("https://example.com/info"), null));
|
||||
assertThat(transport.executeInfoRequest(new URI("https://example.com/info"), null)).isEqualTo("body");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,9 +70,9 @@ public class XhrTransportTests {
|
||||
transport.sendMessageResponseToReturn = new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
URI url = new URI("https://example.com");
|
||||
transport.executeSendRequest(url, requestHeaders, new TextMessage("payload"));
|
||||
assertEquals(2, transport.actualSendRequestHeaders.size());
|
||||
assertEquals("bar", transport.actualSendRequestHeaders.getFirst("foo"));
|
||||
assertEquals(MediaType.APPLICATION_JSON, transport.actualSendRequestHeaders.getContentType());
|
||||
assertThat(transport.actualSendRequestHeaders.size()).isEqualTo(2);
|
||||
assertThat(transport.actualSendRequestHeaders.getFirst("foo")).isEqualTo("bar");
|
||||
assertThat(transport.actualSendRequestHeaders.getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,12 +106,12 @@ public class XhrTransportTests {
|
||||
verify(request).getHttpRequestHeaders();
|
||||
verifyNoMoreInteractions(request);
|
||||
|
||||
assertEquals(1, transport.actualHandshakeHeaders.size());
|
||||
assertEquals("foo", transport.actualHandshakeHeaders.getOrigin());
|
||||
assertThat(transport.actualHandshakeHeaders.size()).isEqualTo(1);
|
||||
assertThat(transport.actualHandshakeHeaders.getOrigin()).isEqualTo("foo");
|
||||
|
||||
assertFalse(transport.actualSession.isDisconnected());
|
||||
assertThat(transport.actualSession.isDisconnected()).isFalse();
|
||||
captor.getValue().run();
|
||||
assertTrue(transport.actualSession.isDisconnected());
|
||||
assertThat(transport.actualSession.isDisconnected()).isTrue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@ package org.springframework.web.socket.sockjs.frame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link org.springframework.web.socket.sockjs.frame.SockJsFrame}.
|
||||
@@ -34,66 +33,66 @@ public class SockJsFrameTests {
|
||||
public void openFrame() {
|
||||
SockJsFrame frame = SockJsFrame.openFrame();
|
||||
|
||||
assertEquals("o", frame.getContent());
|
||||
assertEquals(SockJsFrameType.OPEN, frame.getType());
|
||||
assertNull(frame.getFrameData());
|
||||
assertThat(frame.getContent()).isEqualTo("o");
|
||||
assertThat(frame.getType()).isEqualTo(SockJsFrameType.OPEN);
|
||||
assertThat(frame.getFrameData()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void heartbeatFrame() {
|
||||
SockJsFrame frame = SockJsFrame.heartbeatFrame();
|
||||
|
||||
assertEquals("h", frame.getContent());
|
||||
assertEquals(SockJsFrameType.HEARTBEAT, frame.getType());
|
||||
assertNull(frame.getFrameData());
|
||||
assertThat(frame.getContent()).isEqualTo("h");
|
||||
assertThat(frame.getType()).isEqualTo(SockJsFrameType.HEARTBEAT);
|
||||
assertThat(frame.getFrameData()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageArrayFrame() {
|
||||
SockJsFrame frame = SockJsFrame.messageFrame(new Jackson2SockJsMessageCodec(), "m1", "m2");
|
||||
|
||||
assertEquals("a[\"m1\",\"m2\"]", frame.getContent());
|
||||
assertEquals(SockJsFrameType.MESSAGE, frame.getType());
|
||||
assertEquals("[\"m1\",\"m2\"]", frame.getFrameData());
|
||||
assertThat(frame.getContent()).isEqualTo("a[\"m1\",\"m2\"]");
|
||||
assertThat(frame.getType()).isEqualTo(SockJsFrameType.MESSAGE);
|
||||
assertThat(frame.getFrameData()).isEqualTo("[\"m1\",\"m2\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageArrayFrameEmpty() {
|
||||
SockJsFrame frame = new SockJsFrame("a");
|
||||
|
||||
assertEquals("a[]", frame.getContent());
|
||||
assertEquals(SockJsFrameType.MESSAGE, frame.getType());
|
||||
assertEquals("[]", frame.getFrameData());
|
||||
assertThat(frame.getContent()).isEqualTo("a[]");
|
||||
assertThat(frame.getType()).isEqualTo(SockJsFrameType.MESSAGE);
|
||||
assertThat(frame.getFrameData()).isEqualTo("[]");
|
||||
|
||||
frame = new SockJsFrame("a[]");
|
||||
|
||||
assertEquals("a[]", frame.getContent());
|
||||
assertEquals(SockJsFrameType.MESSAGE, frame.getType());
|
||||
assertEquals("[]", frame.getFrameData());
|
||||
assertThat(frame.getContent()).isEqualTo("a[]");
|
||||
assertThat(frame.getType()).isEqualTo(SockJsFrameType.MESSAGE);
|
||||
assertThat(frame.getFrameData()).isEqualTo("[]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closeFrame() {
|
||||
SockJsFrame frame = SockJsFrame.closeFrame(3000, "Go Away!");
|
||||
|
||||
assertEquals("c[3000,\"Go Away!\"]", frame.getContent());
|
||||
assertEquals(SockJsFrameType.CLOSE, frame.getType());
|
||||
assertEquals("[3000,\"Go Away!\"]", frame.getFrameData());
|
||||
assertThat(frame.getContent()).isEqualTo("c[3000,\"Go Away!\"]");
|
||||
assertThat(frame.getType()).isEqualTo(SockJsFrameType.CLOSE);
|
||||
assertThat(frame.getFrameData()).isEqualTo("[3000,\"Go Away!\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closeFrameEmpty() {
|
||||
SockJsFrame frame = new SockJsFrame("c");
|
||||
|
||||
assertEquals("c[]", frame.getContent());
|
||||
assertEquals(SockJsFrameType.CLOSE, frame.getType());
|
||||
assertEquals("[]", frame.getFrameData());
|
||||
assertThat(frame.getContent()).isEqualTo("c[]");
|
||||
assertThat(frame.getType()).isEqualTo(SockJsFrameType.CLOSE);
|
||||
assertThat(frame.getFrameData()).isEqualTo("[]");
|
||||
|
||||
frame = new SockJsFrame("c[]");
|
||||
|
||||
assertEquals("c[]", frame.getContent());
|
||||
assertEquals(SockJsFrameType.CLOSE, frame.getType());
|
||||
assertEquals("[]", frame.getFrameData());
|
||||
assertThat(frame.getContent()).isEqualTo("c[]");
|
||||
assertThat(frame.getType()).isEqualTo(SockJsFrameType.CLOSE);
|
||||
assertThat(frame.getFrameData()).isEqualTo("[]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,11 +37,7 @@ import org.springframework.web.socket.AbstractHttpRequestTests;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.SockJsException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -91,31 +87,29 @@ public class SockJsServiceTests extends AbstractHttpRequestTests {
|
||||
public void handleInfoGet() throws IOException {
|
||||
resetResponseAndHandleRequest("GET", "/echo/info", HttpStatus.OK);
|
||||
|
||||
assertEquals("application/json;charset=UTF-8", this.servletResponse.getContentType());
|
||||
assertThat(this.servletResponse.getContentType()).isEqualTo("application/json;charset=UTF-8");
|
||||
String header = this.servletResponse.getHeader(HttpHeaders.CACHE_CONTROL);
|
||||
assertEquals("no-store, no-cache, must-revalidate, max-age=0", header);
|
||||
assertNull(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||
assertNull(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
|
||||
assertNull(this.servletResponse.getHeader(HttpHeaders.VARY));
|
||||
assertThat(header).isEqualTo("no-store, no-cache, must-revalidate, max-age=0");
|
||||
assertThat(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isNull();
|
||||
assertThat(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS)).isNull();
|
||||
assertThat(this.servletResponse.getHeader(HttpHeaders.VARY)).isNull();
|
||||
|
||||
String body = this.servletResponse.getContentAsString();
|
||||
assertEquals("{\"entropy\"", body.substring(0, body.indexOf(':')));
|
||||
assertEquals(",\"origins\":[\"*:*\"],\"cookie_needed\":true,\"websocket\":true}",
|
||||
body.substring(body.indexOf(',')));
|
||||
assertThat(body.substring(0, body.indexOf(':'))).isEqualTo("{\"entropy\"");
|
||||
assertThat(body.substring(body.indexOf(','))).isEqualTo(",\"origins\":[\"*:*\"],\"cookie_needed\":true,\"websocket\":true}");
|
||||
|
||||
this.service.setSessionCookieNeeded(false);
|
||||
this.service.setWebSocketEnabled(false);
|
||||
resetResponseAndHandleRequest("GET", "/echo/info", HttpStatus.OK);
|
||||
|
||||
body = this.servletResponse.getContentAsString();
|
||||
assertEquals(",\"origins\":[\"*:*\"],\"cookie_needed\":false,\"websocket\":false}",
|
||||
body.substring(body.indexOf(',')));
|
||||
assertThat(body.substring(body.indexOf(','))).isEqualTo(",\"origins\":[\"*:*\"],\"cookie_needed\":false,\"websocket\":false}");
|
||||
|
||||
this.service.setAllowedOrigins(Collections.singletonList("https://mydomain1.com"));
|
||||
resetResponseAndHandleRequest("GET", "/echo/info", HttpStatus.OK);
|
||||
assertNull(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||
assertNull(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
|
||||
assertNull(this.servletResponse.getHeader(HttpHeaders.VARY));
|
||||
assertThat(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isNull();
|
||||
assertThat(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS)).isNull();
|
||||
assertThat(this.servletResponse.getHeader(HttpHeaders.VARY)).isNull();
|
||||
}
|
||||
|
||||
@Test // SPR-12226 and SPR-12660
|
||||
@@ -124,13 +118,12 @@ public class SockJsServiceTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.com");
|
||||
resetResponseAndHandleRequest("GET", "/echo/info", HttpStatus.OK);
|
||||
|
||||
assertEquals("application/json;charset=UTF-8", this.servletResponse.getContentType());
|
||||
assertThat(this.servletResponse.getContentType()).isEqualTo("application/json;charset=UTF-8");
|
||||
String header = this.servletResponse.getHeader(HttpHeaders.CACHE_CONTROL);
|
||||
assertEquals("no-store, no-cache, must-revalidate, max-age=0", header);
|
||||
assertThat(header).isEqualTo("no-store, no-cache, must-revalidate, max-age=0");
|
||||
String body = this.servletResponse.getContentAsString();
|
||||
assertEquals("{\"entropy\"", body.substring(0, body.indexOf(':')));
|
||||
assertEquals(",\"origins\":[\"*:*\"],\"cookie_needed\":true,\"websocket\":true}",
|
||||
body.substring(body.indexOf(',')));
|
||||
assertThat(body.substring(0, body.indexOf(':'))).isEqualTo("{\"entropy\"");
|
||||
assertThat(body.substring(body.indexOf(','))).isEqualTo(",\"origins\":[\"*:*\"],\"cookie_needed\":true,\"websocket\":true}");
|
||||
|
||||
this.service.setAllowedOrigins(Collections.singletonList("http://mydomain1.com"));
|
||||
resetResponseAndHandleRequest("GET", "/echo/info", HttpStatus.OK);
|
||||
@@ -153,7 +146,7 @@ public class SockJsServiceTests extends AbstractHttpRequestTests {
|
||||
|
||||
handleRequest("GET", "/echo/info", HttpStatus.OK);
|
||||
|
||||
assertEquals("foobar:123", this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||
assertThat(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("foobar:123");
|
||||
}
|
||||
|
||||
@Test // SPR-11919
|
||||
@@ -173,11 +166,11 @@ public class SockJsServiceTests extends AbstractHttpRequestTests {
|
||||
public void handleInfoOptions() {
|
||||
this.servletRequest.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Last-Modified");
|
||||
resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.NO_CONTENT);
|
||||
assertNull(this.service.getCorsConfiguration(this.servletRequest));
|
||||
assertThat(this.service.getCorsConfiguration(this.servletRequest)).isNull();
|
||||
|
||||
this.service.setAllowedOrigins(Collections.singletonList("https://mydomain1.com"));
|
||||
resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.NO_CONTENT);
|
||||
assertNull(this.service.getCorsConfiguration(this.servletRequest));
|
||||
assertThat(this.service.getCorsConfiguration(this.servletRequest)).isNull();
|
||||
}
|
||||
|
||||
@Test // SPR-12226 and SPR-12660
|
||||
@@ -187,19 +180,19 @@ public class SockJsServiceTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
|
||||
this.servletRequest.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Last-Modified");
|
||||
resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.NO_CONTENT);
|
||||
assertNotNull(this.service.getCorsConfiguration(this.servletRequest));
|
||||
assertThat(this.service.getCorsConfiguration(this.servletRequest)).isNotNull();
|
||||
|
||||
this.service.setAllowedOrigins(Collections.singletonList("http://mydomain1.com"));
|
||||
resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.NO_CONTENT);
|
||||
assertNotNull(this.service.getCorsConfiguration(this.servletRequest));
|
||||
assertThat(this.service.getCorsConfiguration(this.servletRequest)).isNotNull();
|
||||
|
||||
this.service.setAllowedOrigins(Arrays.asList("http://mydomain1.com", "http://mydomain2.com", "http://mydomain3.com"));
|
||||
resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.NO_CONTENT);
|
||||
assertNotNull(this.service.getCorsConfiguration(this.servletRequest));
|
||||
assertThat(this.service.getCorsConfiguration(this.servletRequest)).isNotNull();
|
||||
|
||||
this.service.setAllowedOrigins(Collections.singletonList("*"));
|
||||
resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.NO_CONTENT);
|
||||
assertNotNull(this.service.getCorsConfiguration(this.servletRequest));
|
||||
assertThat(this.service.getCorsConfiguration(this.servletRequest)).isNotNull();
|
||||
}
|
||||
|
||||
@Test // SPR-16304
|
||||
@@ -210,12 +203,12 @@ public class SockJsServiceTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Last-Modified");
|
||||
resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.FORBIDDEN);
|
||||
CorsConfiguration corsConfiguration = this.service.getCorsConfiguration(this.servletRequest);
|
||||
assertTrue(corsConfiguration.getAllowedOrigins().isEmpty());
|
||||
assertThat(corsConfiguration.getAllowedOrigins().isEmpty()).isTrue();
|
||||
|
||||
this.service.setAllowedOrigins(Collections.singletonList("https://mydomain1.com"));
|
||||
resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.FORBIDDEN);
|
||||
corsConfiguration = this.service.getCorsConfiguration(this.servletRequest);
|
||||
assertEquals(Collections.singletonList("https://mydomain1.com"), corsConfiguration.getAllowedOrigins());
|
||||
assertThat(corsConfiguration.getAllowedOrigins()).isEqualTo(Collections.singletonList("https://mydomain1.com"));
|
||||
}
|
||||
|
||||
@Test // SPR-12283
|
||||
@@ -226,26 +219,26 @@ public class SockJsServiceTests extends AbstractHttpRequestTests {
|
||||
|
||||
this.servletRequest.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Last-Modified");
|
||||
resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.NO_CONTENT);
|
||||
assertNull(this.service.getCorsConfiguration(this.servletRequest));
|
||||
assertThat(this.service.getCorsConfiguration(this.servletRequest)).isNull();
|
||||
|
||||
this.service.setAllowedOrigins(Collections.singletonList("https://mydomain1.com"));
|
||||
resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.FORBIDDEN);
|
||||
assertNull(this.service.getCorsConfiguration(this.servletRequest));
|
||||
assertThat(this.service.getCorsConfiguration(this.servletRequest)).isNull();
|
||||
|
||||
this.service.setAllowedOrigins(Arrays.asList("https://mydomain1.com", "https://mydomain2.com", "http://mydomain3.com"));
|
||||
resetResponseAndHandleRequest("OPTIONS", "/echo/info", HttpStatus.NO_CONTENT);
|
||||
assertNull(this.service.getCorsConfiguration(this.servletRequest));
|
||||
assertThat(this.service.getCorsConfiguration(this.servletRequest)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleIframeRequest() throws IOException {
|
||||
resetResponseAndHandleRequest("GET", "/echo/iframe.html", HttpStatus.OK);
|
||||
|
||||
assertEquals("text/html;charset=UTF-8", this.servletResponse.getContentType());
|
||||
assertTrue(this.servletResponse.getContentAsString().startsWith("<!DOCTYPE html>\n"));
|
||||
assertEquals(490, this.servletResponse.getContentLength());
|
||||
assertEquals("no-store, no-cache, must-revalidate, max-age=0", this.response.getHeaders().getCacheControl());
|
||||
assertEquals("\"0096cbd37f2a5218c33bb0826a7c74cbf\"", this.response.getHeaders().getETag());
|
||||
assertThat(this.servletResponse.getContentType()).isEqualTo("text/html;charset=UTF-8");
|
||||
assertThat(this.servletResponse.getContentAsString().startsWith("<!DOCTYPE html>\n")).isTrue();
|
||||
assertThat(this.servletResponse.getContentLength()).isEqualTo(490);
|
||||
assertThat(this.response.getHeaders().getCacheControl()).isEqualTo("no-store, no-cache, must-revalidate, max-age=0");
|
||||
assertThat(this.response.getHeaders().getETag()).isEqualTo("\"0096cbd37f2a5218c33bb0826a7c74cbf\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -257,11 +250,11 @@ public class SockJsServiceTests extends AbstractHttpRequestTests {
|
||||
@Test
|
||||
public void handleRawWebSocketRequest() throws IOException {
|
||||
resetResponseAndHandleRequest("GET", "/echo", HttpStatus.OK);
|
||||
assertEquals("Welcome to SockJS!\n", this.servletResponse.getContentAsString());
|
||||
assertThat(this.servletResponse.getContentAsString()).isEqualTo("Welcome to SockJS!\n");
|
||||
|
||||
resetResponseAndHandleRequest("GET", "/echo/websocket", HttpStatus.OK);
|
||||
assertNull("Raw WebSocket should not open a SockJS session", this.service.sessionId);
|
||||
assertSame(this.handler, this.service.handler);
|
||||
assertThat(this.service.sessionId).as("Raw WebSocket should not open a SockJS session").isNull();
|
||||
assertThat(this.service.handler).isSameAs(this.handler);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -269,7 +262,7 @@ public class SockJsServiceTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.setContentType("");
|
||||
resetResponseAndHandleRequest("GET", "/echo/info", HttpStatus.OK);
|
||||
|
||||
assertEquals("Invalid/empty content should have been ignored", 200, this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).as("Invalid/empty content should have been ignored").isEqualTo(200);
|
||||
}
|
||||
|
||||
|
||||
@@ -283,7 +276,7 @@ public class SockJsServiceTests extends AbstractHttpRequestTests {
|
||||
String sockJsPath = uri.substring("/echo".length());
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.handler);
|
||||
|
||||
assertEquals(httpStatus.value(), this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(httpStatus.value());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.web.socket.sockjs.transport;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
@@ -27,12 +27,12 @@ public class TransportTypeTests {
|
||||
|
||||
@Test
|
||||
public void testFromValue() {
|
||||
assertEquals(TransportType.WEBSOCKET, TransportType.fromValue("websocket"));
|
||||
assertEquals(TransportType.XHR, TransportType.fromValue("xhr"));
|
||||
assertEquals(TransportType.XHR_SEND, TransportType.fromValue("xhr_send"));
|
||||
assertEquals(TransportType.XHR_STREAMING, TransportType.fromValue("xhr_streaming"));
|
||||
assertEquals(TransportType.EVENT_SOURCE, TransportType.fromValue("eventsource"));
|
||||
assertEquals(TransportType.HTML_FILE, TransportType.fromValue("htmlfile"));
|
||||
assertThat(TransportType.fromValue("websocket")).isEqualTo(TransportType.WEBSOCKET);
|
||||
assertThat(TransportType.fromValue("xhr")).isEqualTo(TransportType.XHR);
|
||||
assertThat(TransportType.fromValue("xhr_send")).isEqualTo(TransportType.XHR_SEND);
|
||||
assertThat(TransportType.fromValue("xhr_streaming")).isEqualTo(TransportType.XHR_STREAMING);
|
||||
assertThat(TransportType.fromValue("eventsource")).isEqualTo(TransportType.EVENT_SOURCE);
|
||||
assertThat(TransportType.fromValue("htmlfile")).isEqualTo(TransportType.HTML_FILE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,12 +40,8 @@ import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
import org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig;
|
||||
import org.springframework.web.socket.sockjs.transport.session.TestSockJsSession;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -107,13 +103,13 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
DefaultSockJsService service = new DefaultSockJsService(mock(TaskScheduler.class));
|
||||
Map<TransportType, TransportHandler> handlers = service.getTransportHandlers();
|
||||
|
||||
assertEquals(6, handlers.size());
|
||||
assertNotNull(handlers.get(TransportType.WEBSOCKET));
|
||||
assertNotNull(handlers.get(TransportType.XHR));
|
||||
assertNotNull(handlers.get(TransportType.XHR_SEND));
|
||||
assertNotNull(handlers.get(TransportType.XHR_STREAMING));
|
||||
assertNotNull(handlers.get(TransportType.HTML_FILE));
|
||||
assertNotNull(handlers.get(TransportType.EVENT_SOURCE));
|
||||
assertThat(handlers.size()).isEqualTo(6);
|
||||
assertThat(handlers.get(TransportType.WEBSOCKET)).isNotNull();
|
||||
assertThat(handlers.get(TransportType.XHR)).isNotNull();
|
||||
assertThat(handlers.get(TransportType.XHR_SEND)).isNotNull();
|
||||
assertThat(handlers.get(TransportType.XHR_STREAMING)).isNotNull();
|
||||
assertThat(handlers.get(TransportType.HTML_FILE)).isNotNull();
|
||||
assertThat(handlers.get(TransportType.EVENT_SOURCE)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,8 +119,8 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
DefaultSockJsService service = new DefaultSockJsService(mock(TaskScheduler.class), xhrHandler);
|
||||
Map<TransportType, TransportHandler> handlers = service.getTransportHandlers();
|
||||
|
||||
assertEquals(6, handlers.size());
|
||||
assertSame(xhrHandler, handlers.get(xhrHandler.getTransportType()));
|
||||
assertThat(handlers.size()).isEqualTo(6);
|
||||
assertThat(handlers.get(xhrHandler.getTransportType())).isSameAs(xhrHandler);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,7 +135,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
mock(TaskScheduler.class), new XhrPollingTransportHandler(), new XhrReceivingTransportHandler());
|
||||
Map<TransportType, TransportHandler> actualHandlers = service.getTransportHandlers();
|
||||
|
||||
assertEquals(2, actualHandlers.size());
|
||||
assertThat(actualHandlers.size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,13 +144,13 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
setRequest("POST", sockJsPrefix + sockJsPath);
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
|
||||
assertEquals(200, this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(200);
|
||||
verify(this.xhrHandler).handleRequest(this.request, this.response, this.wsHandler, this.session);
|
||||
verify(taskScheduler).scheduleAtFixedRate(any(Runnable.class), eq(service.getDisconnectDelay()));
|
||||
|
||||
assertEquals("no-store, no-cache, must-revalidate, max-age=0", this.response.getHeaders().getCacheControl());
|
||||
assertNull(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
|
||||
assertNull(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
|
||||
assertThat(this.response.getHeaders().getCacheControl()).isEqualTo("no-store, no-cache, must-revalidate, max-age=0");
|
||||
assertThat(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isNull();
|
||||
assertThat(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS)).isNull();
|
||||
}
|
||||
|
||||
@Test // SPR-12226
|
||||
@@ -165,7 +161,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
|
||||
assertEquals(200, this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
@Test // SPR-12226
|
||||
@@ -176,7 +172,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain3.com");
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
|
||||
assertEquals(403, this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(403);
|
||||
}
|
||||
|
||||
@Test // SPR-13464
|
||||
@@ -188,7 +184,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.setServerName("mydomain2.com");
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
|
||||
assertEquals(200, this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
@Test // SPR-13545
|
||||
@@ -200,7 +196,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
this.servletRequest.setServerName("mydomain2.com");
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
|
||||
assertEquals(404, this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -209,10 +205,10 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
setRequest("OPTIONS", sockJsPrefix + sockJsPath);
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
|
||||
assertEquals(204, this.servletResponse.getStatus());
|
||||
assertNull(this.servletResponse.getHeader("Access-Control-Allow-Origin"));
|
||||
assertNull(this.servletResponse.getHeader("Access-Control-Allow-Credentials"));
|
||||
assertNull(this.servletResponse.getHeader("Access-Control-Allow-Methods"));
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(204);
|
||||
assertThat(this.servletResponse.getHeader("Access-Control-Allow-Origin")).isNull();
|
||||
assertThat(this.servletResponse.getHeader("Access-Control-Allow-Credentials")).isNull();
|
||||
assertThat(this.servletResponse.getHeader("Access-Control-Allow-Methods")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -221,7 +217,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
setRequest("POST", sockJsPrefix + sockJsPath);
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
|
||||
assertEquals(404, this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -230,14 +226,16 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
setRequest("POST", sockJsPrefix + sockJsPath);
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
|
||||
assertEquals(404, this.servletResponse.getStatus()); // no session yet
|
||||
// no session yet
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(404);
|
||||
|
||||
resetResponse();
|
||||
sockJsPath = sessionUrlPrefix + "xhr";
|
||||
setRequest("POST", sockJsPrefix + sockJsPath);
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
|
||||
assertEquals(200, this.servletResponse.getStatus()); // session created
|
||||
// session created
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(200);
|
||||
verify(this.xhrHandler).handleRequest(this.request, this.response, this.wsHandler, this.session);
|
||||
|
||||
resetResponse();
|
||||
@@ -246,7 +244,8 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
given(this.xhrSendHandler.checkSessionType(this.session)).willReturn(true);
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
|
||||
assertEquals(200, this.servletResponse.getStatus()); // session exists
|
||||
// session exists
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(200);
|
||||
verify(this.xhrSendHandler).handleRequest(this.request, this.response, this.wsHandler, this.session);
|
||||
}
|
||||
|
||||
@@ -256,7 +255,8 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
setRequest("POST", sockJsPrefix + sockJsPath);
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
|
||||
assertEquals(200, this.servletResponse.getStatus()); // session created
|
||||
// session created
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(200);
|
||||
verify(this.xhrHandler).handleRequest(this.request, this.response, this.wsHandler, this.session);
|
||||
|
||||
this.session.setPrincipal(new TestPrincipal("little red riding hood"));
|
||||
@@ -268,7 +268,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
setRequest("POST", sockJsPrefix + sockJsPath);
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
|
||||
assertEquals(404, this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(404);
|
||||
verifyNoMoreInteractions(this.xhrSendHandler);
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
String sockJsPath = "/websocket";
|
||||
setRequest("GET", sockJsPrefix + sockJsPath);
|
||||
wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
assertNotEquals(403, this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).isNotEqualTo((long) 403);
|
||||
|
||||
resetRequestAndResponse();
|
||||
List<String> allowed = Collections.singletonList("https://mydomain1.com");
|
||||
@@ -288,13 +288,13 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
setRequest("GET", sockJsPrefix + sockJsPath);
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.com");
|
||||
wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
assertNotEquals(403, this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).isNotEqualTo((long) 403);
|
||||
|
||||
resetRequestAndResponse();
|
||||
setRequest("GET", sockJsPrefix + sockJsPath);
|
||||
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain2.com");
|
||||
wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
assertEquals(403, this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(403);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -302,22 +302,22 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
String sockJsPath = "/iframe.html";
|
||||
setRequest("GET", sockJsPrefix + sockJsPath);
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
assertNotEquals(404, this.servletResponse.getStatus());
|
||||
assertEquals("SAMEORIGIN", this.servletResponse.getHeader("X-Frame-Options"));
|
||||
assertThat(this.servletResponse.getStatus()).isNotEqualTo((long) 404);
|
||||
assertThat(this.servletResponse.getHeader("X-Frame-Options")).isEqualTo("SAMEORIGIN");
|
||||
|
||||
resetRequestAndResponse();
|
||||
setRequest("GET", sockJsPrefix + sockJsPath);
|
||||
this.service.setAllowedOrigins(Collections.singletonList("https://mydomain1.com"));
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
assertEquals(404, this.servletResponse.getStatus());
|
||||
assertNull(this.servletResponse.getHeader("X-Frame-Options"));
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(404);
|
||||
assertThat(this.servletResponse.getHeader("X-Frame-Options")).isNull();
|
||||
|
||||
resetRequestAndResponse();
|
||||
setRequest("GET", sockJsPrefix + sockJsPath);
|
||||
this.service.setAllowedOrigins(Collections.singletonList("*"));
|
||||
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
|
||||
assertNotEquals(404, this.servletResponse.getStatus());
|
||||
assertNull(this.servletResponse.getHeader("X-Frame-Options"));
|
||||
assertThat(this.servletResponse.getStatus()).isNotEqualTo((long) 404);
|
||||
assertThat(this.servletResponse.getHeader("X-Frame-Options")).isNull();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,10 +26,9 @@ import org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSes
|
||||
import org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig;
|
||||
import org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -48,7 +47,7 @@ public class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
this.servletRequest.setContent("[\"x\"]".getBytes("UTF-8"));
|
||||
handleRequest(new XhrReceivingTransportHandler());
|
||||
|
||||
assertEquals(204, this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,7 +81,7 @@ public class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
transportHandler.initialize(sockJsConfig);
|
||||
assertThatExceptionOfType(SockJsMessageDeliveryException.class).isThrownBy(() ->
|
||||
transportHandler.handleRequest(this.request, this.response, wsHandler, session));
|
||||
assertNull(session.getCloseStatus());
|
||||
assertThat(session.getCloseStatus()).isNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +92,7 @@ public class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
transportHandler.initialize(new StubSockJsServiceConfig());
|
||||
transportHandler.handleRequest(this.request, this.response, wsHandler, session);
|
||||
|
||||
assertEquals("text/plain;charset=UTF-8", this.response.getHeaders().getContentType().toString());
|
||||
assertThat(this.response.getHeaders().getContentType().toString()).isEqualTo("text/plain;charset=UTF-8");
|
||||
verify(wsHandler).handleMessage(session, new TextMessage("x"));
|
||||
}
|
||||
|
||||
@@ -105,7 +104,7 @@ public class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
|
||||
new XhrReceivingTransportHandler().handleRequest(this.request, this.response, wsHandler, session);
|
||||
|
||||
assertEquals(500, this.servletResponse.getStatus());
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(500);
|
||||
verifyNoMoreInteractions(wsHandler);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,7 @@ import org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSes
|
||||
import org.springframework.web.socket.sockjs.transport.session.StreamingSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -74,22 +72,22 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
AbstractSockJsSession session = transportHandler.createSession("1", this.webSocketHandler, null);
|
||||
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
|
||||
|
||||
assertEquals("application/javascript;charset=UTF-8", this.response.getHeaders().getContentType().toString());
|
||||
assertEquals("o\n", this.servletResponse.getContentAsString());
|
||||
assertFalse("Polling request should complete after open frame", this.servletRequest.isAsyncStarted());
|
||||
assertThat(this.response.getHeaders().getContentType().toString()).isEqualTo("application/javascript;charset=UTF-8");
|
||||
assertThat(this.servletResponse.getContentAsString()).isEqualTo("o\n");
|
||||
assertThat(this.servletRequest.isAsyncStarted()).as("Polling request should complete after open frame").isFalse();
|
||||
verify(this.webSocketHandler).afterConnectionEstablished(session);
|
||||
|
||||
resetRequestAndResponse();
|
||||
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
|
||||
|
||||
assertTrue("Polling request should remain open", this.servletRequest.isAsyncStarted());
|
||||
assertThat(this.servletRequest.isAsyncStarted()).as("Polling request should remain open").isTrue();
|
||||
verify(this.taskScheduler).schedule(any(Runnable.class), any(Date.class));
|
||||
|
||||
resetRequestAndResponse();
|
||||
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
|
||||
|
||||
assertFalse("Request should have been rejected", this.servletRequest.isAsyncStarted());
|
||||
assertEquals("c[2010,\"Another connection still open\"]\n", this.servletResponse.getContentAsString());
|
||||
assertThat(this.servletRequest.isAsyncStarted()).as("Request should have been rejected").isFalse();
|
||||
assertThat(this.servletResponse.getContentAsString()).isEqualTo("c[2010,\"Another connection still open\"]\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,8 +98,8 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
|
||||
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
|
||||
|
||||
assertEquals("application/javascript;charset=UTF-8", this.response.getHeaders().getContentType().toString());
|
||||
assertTrue("Streaming request not started", this.servletRequest.isAsyncStarted());
|
||||
assertThat(this.response.getHeaders().getContentType().toString()).isEqualTo("application/javascript;charset=UTF-8");
|
||||
assertThat(this.servletRequest.isAsyncStarted()).as("Streaming request not started").isTrue();
|
||||
verify(this.webSocketHandler).afterConnectionEstablished(session);
|
||||
}
|
||||
|
||||
@@ -113,8 +111,8 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
|
||||
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
|
||||
|
||||
assertEquals(500, this.servletResponse.getStatus());
|
||||
assertEquals("\"callback\" parameter required", this.servletResponse.getContentAsString());
|
||||
assertThat(this.servletResponse.getStatus()).isEqualTo(500);
|
||||
assertThat(this.servletResponse.getContentAsString()).isEqualTo("\"callback\" parameter required");
|
||||
|
||||
resetRequestAndResponse();
|
||||
setRequest("POST", "/");
|
||||
@@ -122,8 +120,8 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
this.servletRequest.addParameter("c", "callback");
|
||||
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
|
||||
|
||||
assertEquals("text/html;charset=UTF-8", this.response.getHeaders().getContentType().toString());
|
||||
assertTrue("Streaming request not started", this.servletRequest.isAsyncStarted());
|
||||
assertThat(this.response.getHeaders().getContentType().toString()).isEqualTo("text/html;charset=UTF-8");
|
||||
assertThat(this.servletRequest.isAsyncStarted()).as("Streaming request not started").isTrue();
|
||||
verify(this.webSocketHandler).afterConnectionEstablished(session);
|
||||
}
|
||||
|
||||
@@ -135,8 +133,8 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
|
||||
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
|
||||
|
||||
assertEquals("text/event-stream;charset=UTF-8", this.response.getHeaders().getContentType().toString());
|
||||
assertTrue("Streaming request not started", this.servletRequest.isAsyncStarted());
|
||||
assertThat(this.response.getHeaders().getContentType().toString()).isEqualTo("text/event-stream;charset=UTF-8");
|
||||
assertThat(this.servletRequest.isAsyncStarted()).as("Streaming request not started").isTrue();
|
||||
verify(this.webSocketHandler).afterConnectionEstablished(session);
|
||||
}
|
||||
|
||||
@@ -149,19 +147,19 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
|
||||
SockJsFrameFormat format = new XhrPollingTransportHandler().getFrameFormat(this.request);
|
||||
String formatted = format.format(frame);
|
||||
assertEquals(frame.getContent() + "\n", formatted);
|
||||
assertThat(formatted).isEqualTo((frame.getContent() + "\n"));
|
||||
|
||||
format = new XhrStreamingTransportHandler().getFrameFormat(this.request);
|
||||
formatted = format.format(frame);
|
||||
assertEquals(frame.getContent() + "\n", formatted);
|
||||
assertThat(formatted).isEqualTo((frame.getContent() + "\n"));
|
||||
|
||||
format = new HtmlFileTransportHandler().getFrameFormat(this.request);
|
||||
formatted = format.format(frame);
|
||||
assertEquals("<script>\np(\"" + frame.getContent() + "\");\n</script>\r\n", formatted);
|
||||
assertThat(formatted).isEqualTo(("<script>\np(\"" + frame.getContent() + "\");\n</script>\r\n"));
|
||||
|
||||
format = new EventSourceTransportHandler().getFrameFormat(this.request);
|
||||
formatted = format.format(frame);
|
||||
assertEquals("data: " + frame.getContent() + "\r\n\r\n", formatted);
|
||||
assertThat(formatted).isEqualTo(("data: " + frame.getContent() + "\r\n\r\n"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.web.socket.messaging.StompSubProtocolHandler;
|
||||
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ public class SockJsWebSocketHandlerTests {
|
||||
WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
|
||||
SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);
|
||||
|
||||
assertEquals(stompHandler.getSupportedProtocols(), sockJsHandler.getSubProtocols());
|
||||
assertThat(sockJsHandler.getSubProtocols()).isEqualTo(stompHandler.getSupportedProtocols());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,7 +61,7 @@ public class SockJsWebSocketHandlerTests {
|
||||
WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
|
||||
SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);
|
||||
|
||||
assertEquals(Collections.emptyList(), sockJsHandler.getSubProtocols());
|
||||
assertThat(sockJsHandler.getSubProtocols()).isEqualTo(Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.junit.Before;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -66,9 +66,9 @@ public abstract class AbstractSockJsSessionTests<S extends AbstractSockJsSession
|
||||
}
|
||||
|
||||
private void assertState(boolean isNew, boolean isOpen, boolean isClosed) {
|
||||
assertEquals(isNew, this.session.isNew());
|
||||
assertEquals(isOpen, this.session.isOpen());
|
||||
assertEquals(isClosed, this.session.isClosed());
|
||||
assertThat(this.session.isNew()).isEqualTo(isNew);
|
||||
assertThat(this.session.isOpen()).isEqualTo(isOpen);
|
||||
assertThat(this.session.isClosed()).isEqualTo(isClosed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ import org.springframework.web.socket.sockjs.frame.SockJsFrameFormat;
|
||||
import org.springframework.web.socket.sockjs.transport.SockJsServiceConfig;
|
||||
import org.springframework.web.socket.sockjs.transport.session.HttpSockJsSessionTests.TestAbstractHttpSockJsSession;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
@@ -83,8 +82,8 @@ public class HttpSockJsSessionTests extends AbstractSockJsSessionTests<TestAbstr
|
||||
|
||||
this.session.handleInitialRequest(this.request, this.response, this.frameFormat);
|
||||
|
||||
assertEquals("hhh\no", this.servletResponse.getContentAsString());
|
||||
assertTrue(this.servletRequest.isAsyncStarted());
|
||||
assertThat(this.servletResponse.getContentAsString()).isEqualTo("hhh\no");
|
||||
assertThat(this.servletRequest.isAsyncStarted()).isTrue();
|
||||
|
||||
verify(this.webSocketHandler).afterConnectionEstablished(this.session);
|
||||
}
|
||||
@@ -95,10 +94,10 @@ public class HttpSockJsSessionTests extends AbstractSockJsSessionTests<TestAbstr
|
||||
this.session.getMessageCache().add("x");
|
||||
this.session.handleSuccessiveRequest(this.request, this.response, this.frameFormat);
|
||||
|
||||
assertTrue(this.servletRequest.isAsyncStarted());
|
||||
assertTrue(this.session.wasHeartbeatScheduled());
|
||||
assertTrue(this.session.wasCacheFlushed());
|
||||
assertEquals("hhh\n", this.servletResponse.getContentAsString());
|
||||
assertThat(this.servletRequest.isAsyncStarted()).isTrue();
|
||||
assertThat(this.session.wasHeartbeatScheduled()).isTrue();
|
||||
assertThat(this.session.wasCacheFlushed()).isTrue();
|
||||
assertThat(this.servletResponse.getContentAsString()).isEqualTo("hhh\n");
|
||||
|
||||
verifyNoMoreInteractions(this.webSocketHandler);
|
||||
}
|
||||
|
||||
@@ -33,9 +33,6 @@ import org.springframework.web.socket.sockjs.frame.SockJsFrame;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.willReturn;
|
||||
@@ -62,22 +59,22 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
|
||||
Thread.sleep(1);
|
||||
|
||||
long time1 = this.session.getTimeSinceLastActive();
|
||||
assertTrue(time1 > 0);
|
||||
assertThat(time1 > 0).isTrue();
|
||||
|
||||
Thread.sleep(1);
|
||||
|
||||
long time2 = this.session.getTimeSinceLastActive();
|
||||
assertTrue(time2 > time1);
|
||||
assertThat(time2 > time1).isTrue();
|
||||
|
||||
this.session.delegateConnectionEstablished();
|
||||
|
||||
Thread.sleep(1);
|
||||
|
||||
this.session.setActive(false);
|
||||
assertTrue(this.session.getTimeSinceLastActive() > 0);
|
||||
assertThat(this.session.getTimeSinceLastActive() > 0).isTrue();
|
||||
|
||||
this.session.setActive(true);
|
||||
assertEquals(0, this.session.getTimeSinceLastActive());
|
||||
assertThat(this.session.getTimeSinceLastActive()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,7 +132,7 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
|
||||
this.session.delegateConnectionClosed(CloseStatus.GOING_AWAY);
|
||||
|
||||
assertClosed();
|
||||
assertEquals(1, this.session.getNumberOfLastActiveTimeUpdates());
|
||||
assertThat(this.session.getNumberOfLastActiveTimeUpdates()).isEqualTo(1);
|
||||
verify(this.webSocketHandler).afterConnectionClosed(this.session, CloseStatus.GOING_AWAY);
|
||||
}
|
||||
|
||||
@@ -144,17 +141,17 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
|
||||
assertNew();
|
||||
|
||||
this.session.close();
|
||||
assertNull("Close not ignored for a new session", this.session.getCloseStatus());
|
||||
assertThat(this.session.getCloseStatus()).as("Close not ignored for a new session").isNull();
|
||||
|
||||
this.session.delegateConnectionEstablished();
|
||||
assertOpen();
|
||||
|
||||
this.session.close();
|
||||
assertClosed();
|
||||
assertEquals(3000, this.session.getCloseStatus().getCode());
|
||||
assertThat(this.session.getCloseStatus().getCode()).isEqualTo(3000);
|
||||
|
||||
this.session.close(CloseStatus.SERVER_ERROR);
|
||||
assertEquals("Close should be ignored if already closed", 3000, this.session.getCloseStatus().getCode());
|
||||
assertThat(this.session.getCloseStatus().getCode()).as("Close should be ignored if already closed").isEqualTo(3000);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,7 +162,7 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
|
||||
this.session.setActive(false);
|
||||
this.session.close();
|
||||
|
||||
assertEquals(Collections.emptyList(), this.session.getSockJsFramesWritten());
|
||||
assertThat(this.session.getSockJsFramesWritten()).isEqualTo(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,13 +173,13 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
|
||||
this.session.setActive(true);
|
||||
this.session.close();
|
||||
|
||||
assertEquals(1, this.session.getSockJsFramesWritten().size());
|
||||
assertEquals(SockJsFrame.closeFrameGoAway(), this.session.getSockJsFramesWritten().get(0));
|
||||
assertThat(this.session.getSockJsFramesWritten().size()).isEqualTo(1);
|
||||
assertThat(this.session.getSockJsFramesWritten().get(0)).isEqualTo(SockJsFrame.closeFrameGoAway());
|
||||
|
||||
assertEquals(1, this.session.getNumberOfLastActiveTimeUpdates());
|
||||
assertTrue(this.session.didCancelHeartbeat());
|
||||
assertThat(this.session.getNumberOfLastActiveTimeUpdates()).isEqualTo(1);
|
||||
assertThat(this.session.didCancelHeartbeat()).isTrue();
|
||||
|
||||
assertEquals(new CloseStatus(3000, "Go away!"), this.session.getCloseStatus());
|
||||
assertThat(this.session.getCloseStatus()).isEqualTo(new CloseStatus(3000, "Go away!"));
|
||||
assertClosed();
|
||||
verify(this.webSocketHandler).afterConnectionClosed(this.session, new CloseStatus(3000, "Go away!"));
|
||||
}
|
||||
@@ -195,7 +192,7 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
|
||||
this.session.setActive(true);
|
||||
this.session.close();
|
||||
|
||||
assertEquals(new CloseStatus(3000, "Go away!"), this.session.getCloseStatus());
|
||||
assertThat(this.session.getCloseStatus()).isEqualTo(new CloseStatus(3000, "Go away!"));
|
||||
assertClosed();
|
||||
}
|
||||
|
||||
@@ -207,7 +204,7 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
|
||||
this.session.setActive(true);
|
||||
this.session.close(CloseStatus.NORMAL);
|
||||
|
||||
assertEquals(CloseStatus.NORMAL, this.session.getCloseStatus());
|
||||
assertThat(this.session.getCloseStatus()).isEqualTo(CloseStatus.NORMAL);
|
||||
assertClosed();
|
||||
}
|
||||
|
||||
@@ -217,7 +214,7 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
|
||||
this.session.setActive(true);
|
||||
this.session.tryCloseWithSockJsTransportError(new Exception(), CloseStatus.BAD_DATA);
|
||||
|
||||
assertEquals(CloseStatus.BAD_DATA, this.session.getCloseStatus());
|
||||
assertThat(this.session.getCloseStatus()).isEqualTo(CloseStatus.BAD_DATA);
|
||||
assertClosed();
|
||||
}
|
||||
|
||||
@@ -225,8 +222,8 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
|
||||
public void writeFrame() throws Exception {
|
||||
this.session.writeFrame(SockJsFrame.openFrame());
|
||||
|
||||
assertEquals(1, this.session.getSockJsFramesWritten().size());
|
||||
assertEquals(SockJsFrame.openFrame(), this.session.getSockJsFramesWritten().get(0));
|
||||
assertThat(this.session.getSockJsFramesWritten().size()).isEqualTo(1);
|
||||
assertThat(this.session.getSockJsFramesWritten().get(0)).isEqualTo(SockJsFrame.openFrame());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -236,7 +233,7 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
|
||||
|
||||
assertThatExceptionOfType(SockJsTransportFailureException.class).isThrownBy(() ->
|
||||
this.session.writeFrame(SockJsFrame.openFrame()));
|
||||
assertEquals(CloseStatus.SERVER_ERROR, this.session.getCloseStatus());
|
||||
assertThat(this.session.getCloseStatus()).isEqualTo(CloseStatus.SERVER_ERROR);
|
||||
verify(this.webSocketHandler).afterConnectionClosed(this.session, CloseStatus.SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -245,8 +242,8 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
|
||||
this.session.setActive(true);
|
||||
this.session.sendHeartbeat();
|
||||
|
||||
assertEquals(1, this.session.getSockJsFramesWritten().size());
|
||||
assertEquals(SockJsFrame.heartbeatFrame(), this.session.getSockJsFramesWritten().get(0));
|
||||
assertThat(this.session.getSockJsFramesWritten().size()).isEqualTo(1);
|
||||
assertThat(this.session.getSockJsFramesWritten().get(0)).isEqualTo(SockJsFrame.heartbeatFrame());
|
||||
|
||||
verify(this.taskScheduler).schedule(any(Runnable.class), any(Date.class));
|
||||
verifyNoMoreInteractions(this.taskScheduler);
|
||||
@@ -266,7 +263,7 @@ public class SockJsSessionTests extends AbstractSockJsSessionTests<TestSockJsSes
|
||||
this.session.setActive(true);
|
||||
this.session.sendHeartbeat();
|
||||
|
||||
assertEquals(Collections.emptyList(), this.session.getSockJsFramesWritten());
|
||||
assertThat(this.session.getSockJsFramesWritten()).isEqualTo(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -35,9 +35,7 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.SockJsServiceConfig;
|
||||
import org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSessionTests.TestWebSocketServerSockJsSession;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -68,20 +66,20 @@ public class WebSocketServerSockJsSessionTests extends AbstractSockJsSessionTest
|
||||
|
||||
@Test
|
||||
public void isActive() throws Exception {
|
||||
assertFalse(this.session.isActive());
|
||||
assertThat(this.session.isActive()).isFalse();
|
||||
|
||||
this.session.initializeDelegateSession(this.webSocketSession);
|
||||
assertTrue(this.session.isActive());
|
||||
assertThat(this.session.isActive()).isTrue();
|
||||
|
||||
this.webSocketSession.setOpen(false);
|
||||
assertFalse(this.session.isActive());
|
||||
assertThat(this.session.isActive()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterSessionInitialized() throws Exception {
|
||||
this.session.initializeDelegateSession(this.webSocketSession);
|
||||
assertEquals(Collections.singletonList(new TextMessage("o")), this.webSocketSession.getSentMessages());
|
||||
assertEquals(Arrays.asList("schedule"), this.session.heartbeatSchedulingEvents);
|
||||
assertThat(this.webSocketSession.getSentMessages()).isEqualTo(Collections.singletonList(new TextMessage("o")));
|
||||
assertThat(this.session.heartbeatSchedulingEvents).isEqualTo(Arrays.asList("schedule"));
|
||||
verify(this.webSocketHandler).afterConnectionEstablished(this.session);
|
||||
verifyNoMoreInteractions(this.taskScheduler, this.webSocketHandler);
|
||||
}
|
||||
@@ -98,7 +96,7 @@ public class WebSocketServerSockJsSessionTests extends AbstractSockJsSessionTest
|
||||
TestWebSocketServerSockJsSession session = new TestWebSocketServerSockJsSession(this.sockJsConfig, handler, null);
|
||||
session.initializeDelegateSession(this.webSocketSession);
|
||||
List<TextMessage> expected = Arrays.asList(new TextMessage("o"), new TextMessage("a[\"go go\"]"));
|
||||
assertEquals(expected, this.webSocketSession.getSentMessages());
|
||||
assertThat(this.webSocketSession.getSentMessages()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,10 +131,9 @@ public class WebSocketServerSockJsSessionTests extends AbstractSockJsSessionTest
|
||||
this.session.initializeDelegateSession(this.webSocketSession);
|
||||
this.session.sendMessageInternal("x");
|
||||
|
||||
assertEquals(Arrays.asList(new TextMessage("o"), new TextMessage("a[\"x\"]")),
|
||||
this.webSocketSession.getSentMessages());
|
||||
assertThat(this.webSocketSession.getSentMessages()).isEqualTo(Arrays.asList(new TextMessage("o"), new TextMessage("a[\"x\"]")));
|
||||
|
||||
assertEquals(Arrays.asList("schedule", "cancel", "schedule"), this.session.heartbeatSchedulingEvents);
|
||||
assertThat(this.session.heartbeatSchedulingEvents).isEqualTo(Arrays.asList("schedule", "cancel", "schedule"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,7 +142,7 @@ public class WebSocketServerSockJsSessionTests extends AbstractSockJsSessionTest
|
||||
this.session.initializeDelegateSession(this.webSocketSession);
|
||||
this.session.close(CloseStatus.NOT_ACCEPTABLE);
|
||||
|
||||
assertEquals(CloseStatus.NOT_ACCEPTABLE, this.webSocketSession.getCloseStatus());
|
||||
assertThat(this.webSocketSession.getCloseStatus()).isEqualTo(CloseStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user