Migrate tests to AssertJ
Mostly thanks to IDEA's plugin: https://plugins.jetbrains.com/plugin/10345-assertions2assertj There is still a lot of work to do when complex and composite matchers are used. * Add `awaitility` dependency and deprecate `EventuallyMatcher` in favor of `awaitility` * Remove Hamcrest from dependencies and disable JUnit & Hamcrest static imports to encourage to use only AssertJ * Migrate JUnit assumptions in rules to AssertJ's assumptions * Deprecate some custom matchers in favor of existing in Hamcrest after upgrading the last to version `2.1` * Replace `ExpectedException` rules with `assertThatThrownBy()` * Mention `MessagePredicate` in the `testing.adoc`
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,13 +17,8 @@
|
||||
package org.springframework.integration.websocket;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
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;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
@@ -107,13 +102,13 @@ public class ClientWebSocketContainerTests {
|
||||
container.start();
|
||||
|
||||
WebSocketSession session = container.getSession(null);
|
||||
assertNotNull(session);
|
||||
assertTrue(session.isOpen());
|
||||
assertEquals("v10.stomp", session.getAcceptedProtocol());
|
||||
assertThat(session).isNotNull();
|
||||
assertThat(session.isOpen()).isTrue();
|
||||
assertThat(session.getAcceptedProtocol()).isEqualTo("v10.stomp");
|
||||
|
||||
session.sendMessage(new PingMessage());
|
||||
|
||||
assertTrue(messageListener.messageLatch.await(10, TimeUnit.SECONDS));
|
||||
assertThat(messageListener.messageLatch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
container.stop();
|
||||
try {
|
||||
@@ -121,15 +116,15 @@ public class ClientWebSocketContainerTests {
|
||||
fail("IllegalStateException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e, instanceOf(IllegalStateException.class));
|
||||
assertEquals(e.getMessage(),
|
||||
"'clientSession' has not been established. Consider to 'start' this container.");
|
||||
assertThat(e).isInstanceOf(IllegalStateException.class);
|
||||
assertThat("'clientSession' has not been established. Consider to 'start' this container.")
|
||||
.isEqualTo(e.getMessage());
|
||||
}
|
||||
|
||||
assertTrue(messageListener.sessionEndedLatch.await(10, TimeUnit.SECONDS));
|
||||
assertFalse(session.isOpen());
|
||||
assertTrue(messageListener.started);
|
||||
assertThat(messageListener.message, instanceOf(PongMessage.class));
|
||||
assertThat(messageListener.sessionEndedLatch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(session.isOpen()).isFalse();
|
||||
assertThat(messageListener.started).isTrue();
|
||||
assertThat(messageListener.message).isInstanceOf(PongMessage.class);
|
||||
|
||||
failure.set(true);
|
||||
|
||||
@@ -140,8 +135,8 @@ public class ClientWebSocketContainerTests {
|
||||
fail("IllegalStateException is expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e, instanceOf(IllegalStateException.class));
|
||||
assertThat(e.getCause(), instanceOf(CancellationException.class));
|
||||
assertThat(e).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(e.getCause()).isInstanceOf(CancellationException.class);
|
||||
}
|
||||
|
||||
failure.set(false);
|
||||
@@ -149,8 +144,8 @@ public class ClientWebSocketContainerTests {
|
||||
container.start();
|
||||
|
||||
session = container.getSession(null);
|
||||
assertNotNull(session);
|
||||
assertTrue(session.isOpen());
|
||||
assertThat(session).isNotNull();
|
||||
assertThat(session.isOpen()).isTrue();
|
||||
}
|
||||
|
||||
private class TestWebSocketListener implements WebSocketListener {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,11 +16,7 @@
|
||||
|
||||
package org.springframework.integration.websocket.client;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -136,12 +132,12 @@ public class StompIntegrationTests {
|
||||
this.webSocketOutputChannel.send(MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build());
|
||||
|
||||
Message<?> receive = this.webSocketEvents.receive(20000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
Object event = receive.getPayload();
|
||||
assertThat(event, instanceOf(SessionConnectedEvent.class));
|
||||
assertThat(event).isInstanceOf(SessionConnectedEvent.class);
|
||||
Message<?> connectedMessage = ((SessionConnectedEvent) event).getMessage();
|
||||
headers = StompHeaderAccessor.wrap(connectedMessage);
|
||||
assertEquals(StompCommand.CONNECTED, headers.getCommand());
|
||||
assertThat(headers.getCommand()).isEqualTo(StompCommand.CONNECTED);
|
||||
|
||||
headers = StompHeaderAccessor.create(StompCommand.SEND);
|
||||
headers.setSubscriptionId("sub1");
|
||||
@@ -151,16 +147,16 @@ public class StompIntegrationTests {
|
||||
this.webSocketOutputChannel.send(message);
|
||||
|
||||
SimpleController controller = this.serverContext.getBean(SimpleController.class);
|
||||
assertTrue(controller.latch.await(20, TimeUnit.SECONDS));
|
||||
assertEquals(StompCommand.SEND.name(), controller.stompCommand);
|
||||
assertThat(controller.latch.await(20, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(controller.stompCommand).isEqualTo(StompCommand.SEND.name());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendMessageToControllerAndReceiveReplyViaTopic() throws Exception {
|
||||
Message<?> receive = this.webSocketEvents.receive(20000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
Object event = receive.getPayload();
|
||||
assertThat(event, instanceOf(SessionConnectedEvent.class));
|
||||
assertThat(event).isInstanceOf(SessionConnectedEvent.class);
|
||||
|
||||
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
|
||||
headers.setSubscriptionId("subs1");
|
||||
@@ -173,13 +169,13 @@ public class StompIntegrationTests {
|
||||
this.webSocketOutputChannel.send(message);
|
||||
|
||||
receive = this.webSocketEvents.receive(20000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
event = receive.getPayload();
|
||||
assertThat(event, instanceOf(ReceiptEvent.class));
|
||||
assertThat(event).isInstanceOf(ReceiptEvent.class);
|
||||
Message<?> receiptMessage = ((ReceiptEvent) event).getMessage();
|
||||
headers = StompHeaderAccessor.wrap(receiptMessage);
|
||||
assertEquals(StompCommand.RECEIPT, headers.getCommand());
|
||||
assertEquals("myReceipt", headers.getReceiptId());
|
||||
assertThat(headers.getCommand()).isEqualTo(StompCommand.RECEIPT);
|
||||
assertThat(headers.getReceiptId()).isEqualTo("myReceipt");
|
||||
|
||||
waitForSubscribe("/topic/increment");
|
||||
|
||||
@@ -191,8 +187,8 @@ public class StompIntegrationTests {
|
||||
this.webSocketOutputChannel.send(message2);
|
||||
|
||||
receive = webSocketInputChannel.receive(20000);
|
||||
assertNotNull(receive);
|
||||
assertEquals("6", receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo("6");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -216,8 +212,8 @@ public class StompIntegrationTests {
|
||||
this.webSocketOutputChannel.send(message2);
|
||||
|
||||
Message<?> receive = webSocketInputChannel.receive(20000);
|
||||
assertNotNull(receive);
|
||||
assertEquals("10", receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo("10");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -234,16 +230,16 @@ public class StompIntegrationTests {
|
||||
this.webSocketOutputChannel.send(message);
|
||||
|
||||
Message<?> receive = webSocketInputChannel.receive(20000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
|
||||
StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(receive);
|
||||
|
||||
assertEquals("Expected STOMP destination=/app/number, got " + stompHeaderAccessor,
|
||||
destHeader, stompHeaderAccessor.getDestination());
|
||||
assertThat(stompHeaderAccessor.getDestination())
|
||||
.as("Expected STOMP destination=/app/number, got " + stompHeaderAccessor).isEqualTo(destHeader);
|
||||
|
||||
Object payload = receive.getPayload();
|
||||
|
||||
assertEquals("Expected STOMP Payload=42, got " + payload, "42", payload);
|
||||
assertThat(payload).as("Expected STOMP Payload=42, got " + payload).isEqualTo("42");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -270,14 +266,14 @@ public class StompIntegrationTests {
|
||||
|
||||
|
||||
Message<?> receive = webSocketInputChannel.receive(20000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
|
||||
StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(receive);
|
||||
|
||||
assertEquals("Expected STOMP destination=/user/queue/error, got " + stompHeaderAccessor,
|
||||
destHeader, stompHeaderAccessor.getDestination());
|
||||
assertThat(stompHeaderAccessor.getDestination())
|
||||
.as("Expected STOMP destination=/user/queue/error, got " + stompHeaderAccessor).isEqualTo(destHeader);
|
||||
|
||||
assertEquals("Got error: Bad input", receive.getPayload());
|
||||
assertThat(receive.getPayload()).isEqualTo("Got error: Bad input");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -301,8 +297,8 @@ public class StompIntegrationTests {
|
||||
this.webSocketOutputChannel.send(message2);
|
||||
|
||||
Message<?> receive = webSocketInputChannel.receive(20000);
|
||||
assertNotNull(receive);
|
||||
assertEquals("Hello Bob", receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo("Hello Bob");
|
||||
}
|
||||
|
||||
private void waitForSubscribe(String destination) throws InterruptedException {
|
||||
@@ -316,7 +312,8 @@ public class StompIntegrationTests {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
assertTrue("The subscription for the '" + destination + "' destination hasn't been registered", n < 100);
|
||||
assertThat(n < 100).as("The subscription for the '" + destination + "' destination hasn't been registered")
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
private boolean containsDestination(String destination, SubscriptionRegistry subscriptionRegistry) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.springframework.integration.websocket.client;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -88,13 +85,13 @@ public class WebSocketClientTests {
|
||||
this.webSocketOutputChannel.send(new GenericMessage<>("Spring"));
|
||||
|
||||
Message<?> received = this.webSocketInputChannel.receive(10000);
|
||||
assertNotNull(received);
|
||||
assertThat(received).isNotNull();
|
||||
StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(received);
|
||||
assertEquals(StompCommand.MESSAGE.getMessageType(), stompHeaderAccessor.getMessageType());
|
||||
assertThat(stompHeaderAccessor.getMessageType()).isEqualTo(StompCommand.MESSAGE.getMessageType());
|
||||
|
||||
Object receivedPayload = received.getPayload();
|
||||
assertThat(receivedPayload, instanceOf(String.class));
|
||||
assertEquals("Hello Spring", receivedPayload);
|
||||
assertThat(receivedPayload).isInstanceOf(String.class);
|
||||
assertThat(receivedPayload).isEqualTo("Hello Spring");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,15 +16,7 @@
|
||||
|
||||
package org.springframework.integration.websocket.config;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
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.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -150,172 +142,181 @@ public class WebSocketParserTests {
|
||||
@SuppressWarnings("unckecked")
|
||||
public void testDefaultInboundChannelAdapterAndServerContainer() {
|
||||
Map<?, ?> urlMap = TestUtils.getPropertyValue(this.handlerMapping, "urlMap", Map.class);
|
||||
assertEquals(1, urlMap.size());
|
||||
assertTrue(urlMap.containsKey("/ws/**"));
|
||||
assertThat(urlMap.size()).isEqualTo(1);
|
||||
assertThat(urlMap.containsKey("/ws/**")).isTrue();
|
||||
Object mappedHandler = urlMap.get("/ws/**");
|
||||
//WebSocketHttpRequestHandler -> ExceptionWebSocketHandlerDecorator - > LoggingWebSocketHandlerDecorator
|
||||
// -> IntegrationWebSocketContainer$IntegrationWebSocketHandler
|
||||
assertSame(TestUtils.getPropertyValue(this.serverWebSocketContainer, "webSocketHandler"),
|
||||
TestUtils.getPropertyValue(mappedHandler, "webSocketHandler.delegate.delegate"));
|
||||
assertSame(this.handshakeHandler,
|
||||
TestUtils.getPropertyValue(this.serverWebSocketContainer, "handshakeHandler"));
|
||||
assertThat(TestUtils.getPropertyValue(mappedHandler, "webSocketHandler.delegate.delegate"))
|
||||
.isSameAs(TestUtils.getPropertyValue(this.serverWebSocketContainer, "webSocketHandler"));
|
||||
assertThat(TestUtils.getPropertyValue(this.serverWebSocketContainer, "handshakeHandler"))
|
||||
.isSameAs(this.handshakeHandler);
|
||||
HandshakeInterceptor[] interceptors =
|
||||
TestUtils.getPropertyValue(this.serverWebSocketContainer, "interceptors", HandshakeInterceptor[].class);
|
||||
assertNotNull(interceptors);
|
||||
assertEquals(1, interceptors.length);
|
||||
assertSame(this.handshakeInterceptor, interceptors[0]);
|
||||
assertEquals(100, TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendTimeLimit"));
|
||||
assertEquals(100000, TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendBufferSizeLimit"));
|
||||
assertArrayEquals(new String[] {"http://foo.com"},
|
||||
TestUtils.getPropertyValue(this.serverWebSocketContainer, "origins", String[].class));
|
||||
assertThat(interceptors).isNotNull();
|
||||
assertThat(interceptors.length).isEqualTo(1);
|
||||
assertThat(interceptors[0]).isSameAs(this.handshakeInterceptor);
|
||||
assertThat(TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendTimeLimit")).isEqualTo(100);
|
||||
assertThat(TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendBufferSizeLimit")).isEqualTo(100000);
|
||||
assertThat(TestUtils.getPropertyValue(this.serverWebSocketContainer, "origins", String[].class))
|
||||
.isEqualTo(new String[] { "http://foo.com" });
|
||||
|
||||
WebSocketHandlerDecoratorFactory[] decoratorFactories =
|
||||
TestUtils.getPropertyValue(this.serverWebSocketContainer, "decoratorFactories",
|
||||
WebSocketHandlerDecoratorFactory[].class);
|
||||
assertNotNull(decoratorFactories);
|
||||
assertEquals(1, decoratorFactories.length);
|
||||
assertSame(this.decoratorFactory, decoratorFactories[0]);
|
||||
assertThat(decoratorFactories).isNotNull();
|
||||
assertThat(decoratorFactories.length).isEqualTo(1);
|
||||
assertThat(decoratorFactories[0]).isSameAs(this.decoratorFactory);
|
||||
|
||||
TransportHandlingSockJsService sockJsService =
|
||||
TestUtils.getPropertyValue(mappedHandler, "sockJsService", TransportHandlingSockJsService.class);
|
||||
assertSame(this.taskScheduler, sockJsService.getTaskScheduler());
|
||||
assertSame(this.sockJsMessageCodec, sockJsService.getMessageCodec());
|
||||
assertThat(sockJsService.getTaskScheduler()).isSameAs(this.taskScheduler);
|
||||
assertThat(sockJsService.getMessageCodec()).isSameAs(this.sockJsMessageCodec);
|
||||
Map<TransportType, TransportHandler> transportHandlers = sockJsService.getTransportHandlers();
|
||||
|
||||
//If "handshake-handler" is provided, "transport-handlers" isn't allowed
|
||||
assertEquals(6, transportHandlers.size());
|
||||
assertSame(this.handshakeHandler,
|
||||
TestUtils.getPropertyValue(transportHandlers.get(TransportType.WEBSOCKET), "handshakeHandler"));
|
||||
assertEquals(4000L, sockJsService.getDisconnectDelay());
|
||||
assertEquals(30000L, sockJsService.getHeartbeatTime());
|
||||
assertEquals(10000, sockJsService.getHttpMessageCacheSize());
|
||||
assertEquals(2000, sockJsService.getStreamBytesLimit());
|
||||
assertEquals("https://foo.sock.js", sockJsService.getSockJsClientLibraryUrl());
|
||||
assertFalse(sockJsService.isSessionCookieNeeded());
|
||||
assertFalse(sockJsService.isWebSocketEnabled());
|
||||
assertTrue(sockJsService.shouldSuppressCors());
|
||||
assertThat(transportHandlers.size()).isEqualTo(6);
|
||||
assertThat(TestUtils.getPropertyValue(transportHandlers.get(TransportType.WEBSOCKET), "handshakeHandler"))
|
||||
.isSameAs(this.handshakeHandler);
|
||||
assertThat(sockJsService.getDisconnectDelay()).isEqualTo(4000L);
|
||||
assertThat(sockJsService.getHeartbeatTime()).isEqualTo(30000L);
|
||||
assertThat(sockJsService.getHttpMessageCacheSize()).isEqualTo(10000);
|
||||
assertThat(sockJsService.getStreamBytesLimit()).isEqualTo(2000);
|
||||
assertThat(sockJsService.getSockJsClientLibraryUrl()).isEqualTo("https://foo.sock.js");
|
||||
assertThat(sockJsService.isSessionCookieNeeded()).isFalse();
|
||||
assertThat(sockJsService.isWebSocketEnabled()).isFalse();
|
||||
assertThat(sockJsService.shouldSuppressCors()).isTrue();
|
||||
|
||||
assertSame(this.serverWebSocketContainer,
|
||||
TestUtils.getPropertyValue(this.defaultInboundAdapter, "webSocketContainer"));
|
||||
assertNull(TestUtils.getPropertyValue(this.defaultInboundAdapter, "messageConverters"));
|
||||
assertEquals(TestUtils.getPropertyValue(this.defaultInboundAdapter, "messageConverter.converters"),
|
||||
TestUtils.getPropertyValue(this.defaultInboundAdapter, "defaultConverters"));
|
||||
assertEquals(String.class,
|
||||
TestUtils.getPropertyValue(this.defaultInboundAdapter, "payloadType", AtomicReference.class).get());
|
||||
assertTrue(TestUtils.getPropertyValue(this.defaultInboundAdapter, "useBroker", Boolean.class));
|
||||
assertSame(this.brokerHandler, TestUtils.getPropertyValue(this.defaultInboundAdapter, "brokerHandler"));
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultInboundAdapter, "webSocketContainer"))
|
||||
.isSameAs(this.serverWebSocketContainer);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultInboundAdapter, "messageConverters")).isNull();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultInboundAdapter, "defaultConverters"))
|
||||
.isEqualTo(TestUtils.getPropertyValue(this.defaultInboundAdapter, "messageConverter.converters"));
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultInboundAdapter, "payloadType", AtomicReference.class).get())
|
||||
.isEqualTo(String.class);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultInboundAdapter, "useBroker", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultInboundAdapter, "brokerHandler"))
|
||||
.isSameAs(this.brokerHandler);
|
||||
|
||||
SubProtocolHandlerRegistry subProtocolHandlerRegistry = TestUtils.getPropertyValue(this.defaultInboundAdapter,
|
||||
"subProtocolHandlerRegistry", SubProtocolHandlerRegistry.class);
|
||||
assertThat(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "defaultProtocolHandler"),
|
||||
instanceOf(PassThruSubProtocolHandler.class));
|
||||
assertTrue(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "protocolHandlers", Map.class).isEmpty());
|
||||
assertThat(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "defaultProtocolHandler"))
|
||||
.isInstanceOf(PassThruSubProtocolHandler.class);
|
||||
assertThat(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "protocolHandlers", Map.class).isEmpty())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomInboundChannelAdapterAndClientContainer() throws URISyntaxException {
|
||||
assertSame(this.clientInboundChannel, TestUtils.getPropertyValue(this.customInboundAdapter, "outputChannel"));
|
||||
assertSame(this.errorChannel, TestUtils.getPropertyValue(this.customInboundAdapter, "errorChannel"));
|
||||
assertSame(this.clientWebSocketContainer,
|
||||
TestUtils.getPropertyValue(this.customInboundAdapter, "webSocketContainer"));
|
||||
assertEquals(2000L, TestUtils.getPropertyValue(this.customInboundAdapter, "messagingTemplate.sendTimeout"));
|
||||
assertEquals(200, TestUtils.getPropertyValue(this.customInboundAdapter, "phase"));
|
||||
assertFalse(TestUtils.getPropertyValue(this.customInboundAdapter, "autoStartup", Boolean.class));
|
||||
assertEquals(Integer.class,
|
||||
TestUtils.getPropertyValue(this.customInboundAdapter, "payloadType", AtomicReference.class).get());
|
||||
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "outputChannel"))
|
||||
.isSameAs(this.clientInboundChannel);
|
||||
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "errorChannel")).isSameAs(this.errorChannel);
|
||||
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "webSocketContainer"))
|
||||
.isSameAs(this.clientWebSocketContainer);
|
||||
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "messagingTemplate.sendTimeout"))
|
||||
.isEqualTo(2000L);
|
||||
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "phase")).isEqualTo(200);
|
||||
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "autoStartup", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "payloadType", AtomicReference.class).get())
|
||||
.isEqualTo(Integer.class);
|
||||
SubProtocolHandlerRegistry subProtocolHandlerRegistry = TestUtils.getPropertyValue(this.customInboundAdapter,
|
||||
"subProtocolHandlerRegistry", SubProtocolHandlerRegistry.class);
|
||||
assertSame(this.stompSubProtocolHandler, TestUtils.getPropertyValue(subProtocolHandlerRegistry,
|
||||
"defaultProtocolHandler"));
|
||||
assertThat(TestUtils.getPropertyValue(subProtocolHandlerRegistry,
|
||||
"defaultProtocolHandler")).isSameAs(this.stompSubProtocolHandler);
|
||||
Map<?, ?> protocolHandlers =
|
||||
TestUtils.getPropertyValue(subProtocolHandlerRegistry, "protocolHandlers", Map.class);
|
||||
assertEquals(3, protocolHandlers.size());
|
||||
assertThat(protocolHandlers.size()).isEqualTo(3);
|
||||
//PassThruSubProtocolHandler is ignored because it doesn't provide any 'protocol' by default.
|
||||
//See warn log message.
|
||||
for (Object handler : protocolHandlers.values()) {
|
||||
assertSame(this.stompSubProtocolHandler, handler);
|
||||
assertThat(handler).isSameAs(this.stompSubProtocolHandler);
|
||||
}
|
||||
|
||||
assertTrue(TestUtils.getPropertyValue(this.customInboundAdapter, "mergeWithDefaultConverters", Boolean.class));
|
||||
assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "mergeWithDefaultConverters", Boolean.class))
|
||||
.isTrue();
|
||||
CompositeMessageConverter compositeMessageConverter = TestUtils.getPropertyValue(this.customInboundAdapter,
|
||||
"messageConverter", CompositeMessageConverter.class);
|
||||
List<MessageConverter> converters = compositeMessageConverter.getConverters();
|
||||
assertEquals(5, converters.size());
|
||||
assertSame(this.simpleMessageConverter, converters.get(0));
|
||||
assertSame(this.mapMessageConverter, converters.get(1));
|
||||
assertThat(converters.get(2), instanceOf(StringMessageConverter.class));
|
||||
assertThat(converters.size()).isEqualTo(5);
|
||||
assertThat(converters.get(0)).isSameAs(this.simpleMessageConverter);
|
||||
assertThat(converters.get(1)).isSameAs(this.mapMessageConverter);
|
||||
assertThat(converters.get(2)).isInstanceOf(StringMessageConverter.class);
|
||||
|
||||
//Test ClientWebSocketContainer parser
|
||||
assertSame(this.customInboundAdapter,
|
||||
TestUtils.getPropertyValue(this.clientWebSocketContainer, "messageListener"));
|
||||
assertEquals(100, TestUtils.getPropertyValue(this.clientWebSocketContainer, "sendTimeLimit"));
|
||||
assertEquals(1000, TestUtils.getPropertyValue(this.clientWebSocketContainer, "sendBufferSizeLimit"));
|
||||
assertEquals(new URI("ws://foo.bar/ws?service=user"),
|
||||
TestUtils.getPropertyValue(this.clientWebSocketContainer, "connectionManager.uri", URI.class));
|
||||
assertSame(this.webSocketClient,
|
||||
TestUtils.getPropertyValue(this.clientWebSocketContainer, "connectionManager.client"));
|
||||
assertEquals(100, TestUtils.getPropertyValue(this.clientWebSocketContainer, "connectionManager.phase"));
|
||||
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "messageListener"))
|
||||
.isSameAs(this.customInboundAdapter);
|
||||
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "sendTimeLimit")).isEqualTo(100);
|
||||
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "sendBufferSizeLimit")).isEqualTo(1000);
|
||||
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "connectionManager.uri", URI.class))
|
||||
.isEqualTo(new URI("ws://foo.bar/ws?service=user"));
|
||||
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "connectionManager.client"))
|
||||
.isSameAs(this.webSocketClient);
|
||||
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "connectionManager.phase")).isEqualTo(100);
|
||||
WebSocketHttpHeaders headers = TestUtils.getPropertyValue(this.clientWebSocketContainer, "headers",
|
||||
WebSocketHttpHeaders.class);
|
||||
assertEquals("FOO", headers.getOrigin());
|
||||
assertEquals(Arrays.asList("BAR", "baz"), headers.get("FOO"));
|
||||
assertThat(headers.getOrigin()).isEqualTo("FOO");
|
||||
assertThat(headers.get("FOO")).isEqualTo(Arrays.asList("BAR", "baz"));
|
||||
|
||||
assertEquals(10 * 1000, TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "sendTimeLimit"));
|
||||
assertEquals(512 * 1024, TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "sendBufferSizeLimit"));
|
||||
assertEquals(new URI("ws://foo.bar"),
|
||||
TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.uri", URI.class));
|
||||
assertSame(this.webSocketClient,
|
||||
TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.client"));
|
||||
assertEquals(Integer.MAX_VALUE,
|
||||
TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.phase"));
|
||||
assertFalse(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer,
|
||||
"connectionManager.autoStartup", Boolean.class));
|
||||
assertTrue(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "headers",
|
||||
WebSocketHttpHeaders.class).isEmpty());
|
||||
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "sendTimeLimit"))
|
||||
.isEqualTo(10 * 1000);
|
||||
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "sendBufferSizeLimit"))
|
||||
.isEqualTo(512 * 1024);
|
||||
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.uri", URI.class))
|
||||
.isEqualTo(new URI("ws://foo.bar"));
|
||||
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.client"))
|
||||
.isSameAs(this.webSocketClient);
|
||||
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.phase"))
|
||||
.isEqualTo(Integer.MAX_VALUE);
|
||||
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer,
|
||||
"connectionManager.autoStartup", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "headers",
|
||||
WebSocketHttpHeaders.class).isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultOutboundChannelAdapter() {
|
||||
assertSame(this.serverWebSocketContainer,
|
||||
TestUtils.getPropertyValue(this.defaultOutboundAdapter, "webSocketContainer"));
|
||||
assertNull(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "messageConverters"));
|
||||
assertEquals(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "messageConverter.converters"),
|
||||
TestUtils.getPropertyValue(this.defaultOutboundAdapter, "defaultConverters"));
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "webSocketContainer"))
|
||||
.isSameAs(this.serverWebSocketContainer);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "messageConverters")).isNull();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "defaultConverters"))
|
||||
.isEqualTo(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "messageConverter.converters"));
|
||||
SubProtocolHandlerRegistry subProtocolHandlerRegistry = TestUtils.getPropertyValue(this.defaultOutboundAdapter,
|
||||
"subProtocolHandlerRegistry", SubProtocolHandlerRegistry.class);
|
||||
assertThat(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "defaultProtocolHandler"),
|
||||
instanceOf(PassThruSubProtocolHandler.class));
|
||||
assertTrue(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "protocolHandlers", Map.class).isEmpty());
|
||||
assertFalse(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "client", Boolean.class));
|
||||
assertThat(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "defaultProtocolHandler"))
|
||||
.isInstanceOf(PassThruSubProtocolHandler.class);
|
||||
assertThat(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "protocolHandlers", Map.class).isEmpty())
|
||||
.isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "client", Boolean.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomOutboundChannelAdapter() throws URISyntaxException {
|
||||
assertSame(this.clientWebSocketContainer,
|
||||
TestUtils.getPropertyValue(this.customOutboundAdapter, "webSocketContainer"));
|
||||
assertThat(TestUtils.getPropertyValue(this.customOutboundAdapter, "webSocketContainer"))
|
||||
.isSameAs(this.clientWebSocketContainer);
|
||||
|
||||
SubProtocolHandlerRegistry subProtocolHandlerRegistry = TestUtils.getPropertyValue(this.customOutboundAdapter,
|
||||
"subProtocolHandlerRegistry", SubProtocolHandlerRegistry.class);
|
||||
assertSame(this.stompSubProtocolHandler, TestUtils.getPropertyValue(subProtocolHandlerRegistry,
|
||||
"defaultProtocolHandler"));
|
||||
assertThat(TestUtils.getPropertyValue(subProtocolHandlerRegistry,
|
||||
"defaultProtocolHandler")).isSameAs(this.stompSubProtocolHandler);
|
||||
Map<?, ?> protocolHandlers =
|
||||
TestUtils.getPropertyValue(subProtocolHandlerRegistry, "protocolHandlers", Map.class);
|
||||
assertEquals(3, protocolHandlers.size());
|
||||
assertThat(protocolHandlers.size()).isEqualTo(3);
|
||||
//PassThruSubProtocolHandler is ignored because it doesn't provide any 'protocol' by default.
|
||||
//See warn log message.
|
||||
for (Object handler : protocolHandlers.values()) {
|
||||
assertSame(this.stompSubProtocolHandler, handler);
|
||||
assertThat(handler).isSameAs(this.stompSubProtocolHandler);
|
||||
}
|
||||
|
||||
assertTrue(TestUtils.getPropertyValue(this.customOutboundAdapter, "mergeWithDefaultConverters", Boolean.class));
|
||||
assertThat(TestUtils.getPropertyValue(this.customOutboundAdapter, "mergeWithDefaultConverters", Boolean.class))
|
||||
.isTrue();
|
||||
CompositeMessageConverter compositeMessageConverter = TestUtils.getPropertyValue(this.customOutboundAdapter,
|
||||
"messageConverter", CompositeMessageConverter.class);
|
||||
List<MessageConverter> converters = compositeMessageConverter.getConverters();
|
||||
assertEquals(5, converters.size());
|
||||
assertSame(this.simpleMessageConverter, converters.get(0));
|
||||
assertSame(this.mapMessageConverter, converters.get(1));
|
||||
assertThat(converters.get(2), instanceOf(StringMessageConverter.class));
|
||||
assertTrue(TestUtils.getPropertyValue(this.customOutboundAdapter, "client", Boolean.class));
|
||||
assertThat(converters.size()).isEqualTo(5);
|
||||
assertThat(converters.get(0)).isSameAs(this.simpleMessageConverter);
|
||||
assertThat(converters.get(1)).isSameAs(this.mapMessageConverter);
|
||||
assertThat(converters.get(2)).isInstanceOf(StringMessageConverter.class);
|
||||
assertThat(TestUtils.getPropertyValue(this.customOutboundAdapter, "client", Boolean.class)).isTrue();
|
||||
}
|
||||
|
||||
private static class TestWebSocketHandlerDecoratorFactory implements WebSocketHandlerDecoratorFactory {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,11 +16,7 @@
|
||||
|
||||
package org.springframework.integration.websocket.inbound;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collections;
|
||||
@@ -88,15 +84,15 @@ public class WebSocketInboundChannelAdapterTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testWebSocketInboundChannelAdapter() throws Exception {
|
||||
WebSocketSession session = clientWebSocketContainer.getSession(null);
|
||||
assertNotNull(session);
|
||||
assertTrue(session.isOpen());
|
||||
assertEquals("v10.stomp", session.getAcceptedProtocol());
|
||||
assertThat(session).isNotNull();
|
||||
assertThat(session.isOpen()).isTrue();
|
||||
assertThat(session.getAcceptedProtocol()).isEqualTo("v10.stomp");
|
||||
|
||||
Map<String, WebSocketSession> sessions =
|
||||
TestUtils.getPropertyValue(this.subProtocolWebSocketHandler, "sessions", Map.class);
|
||||
|
||||
|
||||
assertEquals(1, sessions.size());
|
||||
assertThat(sessions.size()).isEqualTo(1);
|
||||
|
||||
String sessionId = sessions.keySet().iterator().next();
|
||||
|
||||
@@ -108,14 +104,14 @@ public class WebSocketInboundChannelAdapterTests {
|
||||
this.clientOutboundChannel.send(message);
|
||||
|
||||
Message<?> received = this.webSocketChannel.receive(10000);
|
||||
assertNotNull(received);
|
||||
assertThat(received).isNotNull();
|
||||
|
||||
StompHeaderAccessor receivedHeaders = StompHeaderAccessor.wrap(received);
|
||||
assertEquals(StompCommand.MESSAGE, receivedHeaders.getCommand());
|
||||
assertThat(receivedHeaders.getCommand()).isEqualTo(StompCommand.MESSAGE);
|
||||
|
||||
Object receivedPayload = received.getPayload();
|
||||
assertThat(receivedPayload, instanceOf(String.class));
|
||||
assertEquals("", receivedPayload);
|
||||
assertThat(receivedPayload).isInstanceOf(String.class);
|
||||
assertThat(receivedPayload).isEqualTo("");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,11 +16,7 @@
|
||||
|
||||
package org.springframework.integration.websocket.outbound;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -83,16 +79,16 @@ public class WebSocketOutboundMessageHandlerTests {
|
||||
this.messageHandler.handleMessage(message);
|
||||
|
||||
Message<?> received = this.clientInboundChannel.receive(10000);
|
||||
assertNotNull(received);
|
||||
assertThat(received).isNotNull();
|
||||
|
||||
StompHeaderAccessor receivedHeaders = StompHeaderAccessor.wrap(received);
|
||||
assertEquals("mess0", receivedHeaders.getMessageId());
|
||||
assertEquals("sub0", receivedHeaders.getSubscriptionId());
|
||||
assertEquals("/foo", receivedHeaders.getDestination());
|
||||
assertThat(receivedHeaders.getMessageId()).isEqualTo("mess0");
|
||||
assertThat(receivedHeaders.getSubscriptionId()).isEqualTo("sub0");
|
||||
assertThat(receivedHeaders.getDestination()).isEqualTo("/foo");
|
||||
|
||||
Object receivedPayload = received.getPayload();
|
||||
assertThat(receivedPayload, instanceOf(byte[].class));
|
||||
assertArrayEquals((byte[]) receivedPayload, payload.getBytes());
|
||||
assertThat(receivedPayload).isInstanceOf(byte[].class);
|
||||
assertThat(payload.getBytes()).isEqualTo((byte[]) receivedPayload);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,13 +16,8 @@
|
||||
|
||||
package org.springframework.integration.websocket.server;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -139,27 +134,27 @@ public class WebSocketServerTests {
|
||||
this.webSocketOutputChannel.send(message2);
|
||||
|
||||
Message<?> received = this.webSocketInputChannel.receive(10000);
|
||||
assertNotNull(received);
|
||||
assertThat(received).isNotNull();
|
||||
StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(received);
|
||||
assertEquals(StompCommand.MESSAGE.getMessageType(), stompHeaderAccessor.getMessageType());
|
||||
assertThat(stompHeaderAccessor.getMessageType()).isEqualTo(StompCommand.MESSAGE.getMessageType());
|
||||
|
||||
Object receivedPayload = received.getPayload();
|
||||
assertThat(receivedPayload, instanceOf(String.class));
|
||||
assertEquals("Hello Spring", receivedPayload);
|
||||
assertThat(receivedPayload).isInstanceOf(String.class);
|
||||
assertThat(receivedPayload).isEqualTo("Hello Spring");
|
||||
|
||||
SubscriptionRegistry subscriptionRegistry = this.brokerHandler.getSubscriptionRegistry();
|
||||
headers = StompHeaderAccessor.create(StompCommand.MESSAGE);
|
||||
headers.setDestination("/queue/foo");
|
||||
message = MessageBuilder.withPayload(ByteBuffer.allocate(0).array()).setHeaders(headers).build();
|
||||
MultiValueMap<String, String> subscriptions = subscriptionRegistry.findSubscriptions(message);
|
||||
assertFalse(subscriptions.isEmpty());
|
||||
assertThat(subscriptions.isEmpty()).isFalse();
|
||||
List<String> subscription = subscriptions.values().iterator().next();
|
||||
assertEquals(1, subscription.size());
|
||||
assertEquals("subs1", subscription.get(0));
|
||||
assertThat(subscription.size()).isEqualTo(1);
|
||||
assertThat(subscription.get(0)).isEqualTo("subs1");
|
||||
|
||||
Message<?> event = this.webSocketEvents.receive(10000);
|
||||
assertNotNull(event);
|
||||
assertThat(event.getPayload(), instanceOf(WebSocketSession.class));
|
||||
assertThat(event).isNotNull();
|
||||
assertThat(event.getPayload()).isInstanceOf(WebSocketSession.class);
|
||||
|
||||
verify(this.requestUpgradeStrategy).start();
|
||||
}
|
||||
@@ -177,8 +172,8 @@ public class WebSocketServerTests {
|
||||
fail("IllegalStateException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e, instanceOf(IllegalStateException.class));
|
||||
assertThat(e.getMessage(), containsString("WebSocket Broker Relay isn't present in the application context;"));
|
||||
assertThat(e).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(e.getMessage()).contains("WebSocket Broker Relay isn't present in the application context;");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,14 +16,8 @@
|
||||
|
||||
package org.springframework.integration.websocket.support;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
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.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -55,13 +49,14 @@ public class SubProtocolHandlerRegistryTests {
|
||||
WebSocketSession session = mock(WebSocketSession.class);
|
||||
when(session.getAcceptedProtocol()).thenReturn("v10.stomp", (String) null);
|
||||
SubProtocolHandler protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
|
||||
assertNotNull(protocolHandler);
|
||||
assertThat(protocolHandler, instanceOf(StompSubProtocolHandler.class));
|
||||
assertThat(protocolHandler).isNotNull();
|
||||
assertThat(protocolHandler).isInstanceOf(StompSubProtocolHandler.class);
|
||||
protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
|
||||
assertNotNull(protocolHandler);
|
||||
assertSame(protocolHandler, defaultProtocolHandler);
|
||||
assertThat(protocolHandler).isNotNull();
|
||||
assertThat(defaultProtocolHandler).isSameAs(protocolHandler);
|
||||
|
||||
assertEquals(subProtocolHandlerRegistry.getSubProtocols(), new StompSubProtocolHandler().getSupportedProtocols());
|
||||
assertThat(new StompSubProtocolHandler().getSupportedProtocols())
|
||||
.isEqualTo(subProtocolHandlerRegistry.getSubProtocols());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,12 +68,12 @@ public class SubProtocolHandlerRegistryTests {
|
||||
WebSocketSession session = mock(WebSocketSession.class);
|
||||
when(session.getAcceptedProtocol()).thenReturn("foo", (String) null);
|
||||
SubProtocolHandler protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
|
||||
assertNotNull(protocolHandler);
|
||||
assertSame(protocolHandler, testProtocolHandler);
|
||||
assertThat(protocolHandler).isNotNull();
|
||||
assertThat(testProtocolHandler).isSameAs(protocolHandler);
|
||||
|
||||
protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
|
||||
assertNotNull(protocolHandler);
|
||||
assertSame(protocolHandler, testProtocolHandler);
|
||||
assertThat(protocolHandler).isNotNull();
|
||||
assertThat(testProtocolHandler).isSameAs(protocolHandler);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,17 +89,17 @@ public class SubProtocolHandlerRegistryTests {
|
||||
fail("IllegalStateException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e, instanceOf(IllegalStateException.class));
|
||||
assertThat(e.getMessage(), containsString("No handler for sub-protocol 'foo'"));
|
||||
assertThat(e).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(e.getMessage()).contains("No handler for sub-protocol 'foo'");
|
||||
}
|
||||
|
||||
SubProtocolHandler protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
|
||||
assertNotNull(protocolHandler);
|
||||
assertSame(protocolHandler, testProtocolHandler);
|
||||
assertThat(protocolHandler).isNotNull();
|
||||
assertThat(testProtocolHandler).isSameAs(protocolHandler);
|
||||
|
||||
protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
|
||||
assertNotNull(protocolHandler);
|
||||
assertSame(protocolHandler, testProtocolHandler);
|
||||
assertThat(protocolHandler).isNotNull();
|
||||
assertThat(testProtocolHandler).isSameAs(protocolHandler);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,14 +112,14 @@ public class SubProtocolHandlerRegistryTests {
|
||||
.build();
|
||||
|
||||
String sessionId = subProtocolHandlerRegistry.resolveSessionId(message);
|
||||
assertEquals(sessionId, "TEST_SESSION");
|
||||
assertThat("TEST_SESSION").isEqualTo(sessionId);
|
||||
|
||||
message = MessageBuilder.withPayload("foo")
|
||||
.setHeader("MY_SESSION_ID", "TEST_SESSION")
|
||||
.build();
|
||||
|
||||
sessionId = subProtocolHandlerRegistry.resolveSessionId(message);
|
||||
assertNull(sessionId);
|
||||
assertThat(sessionId).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user