Rework more JMS tests to common CF resource
* Refactor STOMP and WebSocket tests into JUnit 5 * Close a server application context in those tests when Tomcat is destroyed
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -18,7 +18,7 @@ package org.springframework.integration.websocket;
|
||||
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
@@ -31,9 +31,9 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.tomcat.websocket.Constants;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
@@ -55,12 +55,12 @@ public class ClientWebSocketContainerTests {
|
||||
|
||||
private static final TomcatWebSocketTestServer server = new TomcatWebSocketTestServer(TestServerConfig.class);
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
server.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void tearDown() throws Exception {
|
||||
server.destroy();
|
||||
}
|
||||
@@ -111,15 +111,10 @@ public class ClientWebSocketContainerTests {
|
||||
assertThat(messageListener.messageLatch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
container.stop();
|
||||
try {
|
||||
container.getSession(null);
|
||||
fail("IllegalStateException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e).isInstanceOf(IllegalStateException.class);
|
||||
assertThat("'clientSession' has not been established. Consider to 'start' this container.")
|
||||
.isEqualTo(e.getMessage());
|
||||
}
|
||||
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> container.getSession(null))
|
||||
.withMessage("'clientSession' has not been established. Consider to 'start' this container.");
|
||||
|
||||
assertThat(messageListener.sessionEndedLatch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(session.isOpen()).isFalse();
|
||||
@@ -130,14 +125,9 @@ public class ClientWebSocketContainerTests {
|
||||
|
||||
container.start();
|
||||
|
||||
try {
|
||||
container.getSession(null);
|
||||
fail("IllegalStateException is expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(e.getCause()).isInstanceOf(CancellationException.class);
|
||||
}
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> container.getSession(null))
|
||||
.withCauseInstanceOf(CancellationException.class);
|
||||
|
||||
failure.set(false);
|
||||
|
||||
@@ -148,15 +138,18 @@ public class ClientWebSocketContainerTests {
|
||||
assertThat(session.isOpen()).isTrue();
|
||||
}
|
||||
|
||||
private class TestWebSocketListener implements WebSocketListener {
|
||||
|
||||
public boolean started;
|
||||
private static class TestWebSocketListener implements WebSocketListener {
|
||||
|
||||
public final CountDownLatch messageLatch = new CountDownLatch(1);
|
||||
|
||||
public final CountDownLatch sessionEndedLatch = new CountDownLatch(1);
|
||||
|
||||
public WebSocketMessage<?> message;
|
||||
|
||||
public final CountDownLatch sessionEndedLatch = new CountDownLatch(1);
|
||||
public boolean started;
|
||||
|
||||
TestWebSocketListener() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(WebSocketSession session, WebSocketMessage<?> message) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -31,6 +31,7 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
public class TomcatWebSocketTestServer implements InitializingBean, DisposableBean {
|
||||
@@ -81,6 +82,7 @@ public class TomcatWebSocketTestServer implements InitializingBean, DisposableBe
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
this.serverContext.close();
|
||||
this.tomcatServer.stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2020 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -78,7 +78,6 @@ import org.springframework.messaging.support.AbstractSubscribableChannel;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.socket.client.WebSocketClient;
|
||||
@@ -94,7 +93,6 @@ import org.springframework.web.socket.messaging.SubProtocolHandler;
|
||||
import org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
import org.springframework.web.socket.sockjs.client.SockJsClient;
|
||||
import org.springframework.web.socket.sockjs.client.Transport;
|
||||
import org.springframework.web.socket.sockjs.client.WebSocketTransport;
|
||||
|
||||
/**
|
||||
@@ -102,8 +100,7 @@ import org.springframework.web.socket.sockjs.client.WebSocketTransport;
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@ContextConfiguration(classes = StompIntegrationTests.ClientConfig.class)
|
||||
@SpringJUnitConfig
|
||||
@SpringJUnitConfig(classes = StompIntegrationTests.ClientConfig.class)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class StompIntegrationTests {
|
||||
|
||||
@@ -334,7 +331,7 @@ public class StompIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public WebSocketClient webSocketClient() {
|
||||
return new SockJsClient(Collections.<Transport>singletonList(new WebSocketTransport(new StandardWebSocketClient())));
|
||||
return new SockJsClient(Collections.singletonList(new WebSocketTransport(new StandardWebSocketClient())));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -23,8 +23,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.tomcat.websocket.Constants;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -53,8 +52,7 @@ import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.web.socket.client.WebSocketClient;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
|
||||
@@ -67,8 +65,7 @@ import org.springframework.web.socket.sockjs.client.WebSocketTransport;
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@ContextConfiguration(classes = WebSocketClientTests.ClientConfig.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig(classes = WebSocketClientTests.ClientConfig.class)
|
||||
@DirtiesContext
|
||||
public class WebSocketClientTests {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -25,8 +25,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -45,8 +44,7 @@ import org.springframework.messaging.converter.StringMessageConverter;
|
||||
import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||
@@ -65,8 +63,7 @@ import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class WebSocketParserTests {
|
||||
|
||||
@@ -159,7 +156,7 @@ public class WebSocketParserTests {
|
||||
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[] { "https://foo.com" });
|
||||
.isEqualTo(new String[]{ "https://foo.com" });
|
||||
|
||||
WebSocketHandlerDecoratorFactory[] decoratorFactories =
|
||||
TestUtils.getPropertyValue(this.serverWebSocketContainer, "decoratorFactories",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -22,8 +22,7 @@ import java.nio.ByteBuffer;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -46,8 +45,7 @@ import org.springframework.messaging.simp.stomp.StompCommand;
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.client.WebSocketClient;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
@@ -60,10 +58,10 @@ import org.springframework.web.socket.sockjs.client.WebSocketTransport;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class WebSocketInboundChannelAdapterTests {
|
||||
|
||||
@@ -82,7 +80,7 @@ public class WebSocketInboundChannelAdapterTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testWebSocketInboundChannelAdapter() throws Exception {
|
||||
public void testWebSocketInboundChannelAdapter() {
|
||||
WebSocketSession session = clientWebSocketContainer.getSession(null);
|
||||
assertThat(session).isNotNull();
|
||||
assertThat(session.isOpen()).isTrue();
|
||||
@@ -99,7 +97,8 @@ public class WebSocketInboundChannelAdapterTests {
|
||||
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.MESSAGE);
|
||||
headers.setLeaveMutable(true);
|
||||
headers.setSessionId(sessionId);
|
||||
Message<byte[]> message = MessageBuilder.createMessage(ByteBuffer.allocate(0).array(), headers.getMessageHeaders());
|
||||
Message<byte[]> message =
|
||||
MessageBuilder.createMessage(ByteBuffer.allocate(0).array(), headers.getMessageHeaders());
|
||||
|
||||
this.clientOutboundChannel.send(message);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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.
|
||||
@@ -20,8 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -41,8 +40,7 @@ import org.springframework.messaging.simp.stomp.StompCommand;
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.web.socket.client.WebSocketClient;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
|
||||
@@ -53,10 +51,10 @@ import org.springframework.web.socket.sockjs.client.WebSocketTransport;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class WebSocketOutboundMessageHandlerTests {
|
||||
|
||||
@@ -68,7 +66,7 @@ public class WebSocketOutboundMessageHandlerTests {
|
||||
private QueueChannel clientInboundChannel;
|
||||
|
||||
@Test
|
||||
public void testWebSocketOutboundMessageHandler() throws Exception {
|
||||
public void testWebSocketOutboundMessageHandler() {
|
||||
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
|
||||
headers.setMessageId("mess0");
|
||||
headers.setSubscriptionId("sub0");
|
||||
@@ -88,7 +86,7 @@ public class WebSocketOutboundMessageHandlerTests {
|
||||
|
||||
Object receivedPayload = received.getPayload();
|
||||
assertThat(receivedPayload).isInstanceOf(byte[].class);
|
||||
assertThat(payload.getBytes()).isEqualTo((byte[]) receivedPayload);
|
||||
assertThat(payload.getBytes()).isEqualTo(receivedPayload);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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,7 +17,7 @@
|
||||
package org.springframework.integration.websocket.server;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -25,8 +25,7 @@ import java.nio.ByteBuffer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -69,8 +68,7 @@ import org.springframework.messaging.simp.stomp.StompCommand;
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.WebSocketMessage;
|
||||
@@ -95,8 +93,7 @@ import org.springframework.web.socket.sockjs.client.WebSocketTransport;
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@ContextConfiguration(classes = WebSocketServerTests.ClientConfig.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig(classes = WebSocketServerTests.ClientConfig.class)
|
||||
@DirtiesContext
|
||||
public class WebSocketServerTests {
|
||||
|
||||
@@ -167,15 +164,10 @@ public class WebSocketServerTests {
|
||||
webSocketInboundChannelAdapter.setUseBroker(true);
|
||||
webSocketInboundChannelAdapter.setBeanFactory(Mockito.mock(BeanFactory.class));
|
||||
webSocketInboundChannelAdapter.setApplicationContext(Mockito.mock(ApplicationContext.class));
|
||||
try {
|
||||
webSocketInboundChannelAdapter.afterPropertiesSet();
|
||||
fail("IllegalStateException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(e.getMessage()).contains("WebSocket Broker Relay isn't present in the application context;");
|
||||
}
|
||||
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(webSocketInboundChannelAdapter::afterPropertiesSet)
|
||||
.withMessageContaining("WebSocket Broker Relay isn't present in the application context;");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -319,7 +311,6 @@ public class WebSocketServerTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings("unchecked")
|
||||
public ApplicationListener<ApplicationEvent> webSocketEventListener() {
|
||||
ApplicationEventListeningMessageProducer producer = new ApplicationEventListeningMessageProducer();
|
||||
producer.setEventTypes(PayloadApplicationEvent.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 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,14 +17,14 @@
|
||||
package org.springframework.integration.websocket.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
@@ -35,6 +35,7 @@ import org.springframework.web.socket.messaging.SubProtocolHandler;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
public class SubProtocolHandlerRegistryTests {
|
||||
@@ -44,7 +45,7 @@ public class SubProtocolHandlerRegistryTests {
|
||||
SubProtocolHandler defaultProtocolHandler = mock(SubProtocolHandler.class);
|
||||
SubProtocolHandlerRegistry subProtocolHandlerRegistry =
|
||||
new SubProtocolHandlerRegistry(
|
||||
Collections.<SubProtocolHandler>singletonList(new StompSubProtocolHandler()),
|
||||
Collections.singletonList(new StompSubProtocolHandler()),
|
||||
defaultProtocolHandler);
|
||||
WebSocketSession session = mock(WebSocketSession.class);
|
||||
when(session.getAcceptedProtocol()).thenReturn("v10.stomp", (String) null);
|
||||
@@ -64,7 +65,7 @@ public class SubProtocolHandlerRegistryTests {
|
||||
SubProtocolHandler testProtocolHandler = spy(new StompSubProtocolHandler());
|
||||
when(testProtocolHandler.getSupportedProtocols()).thenReturn(Collections.singletonList("foo"));
|
||||
SubProtocolHandlerRegistry subProtocolHandlerRegistry =
|
||||
new SubProtocolHandlerRegistry(Collections.<SubProtocolHandler>singletonList(testProtocolHandler));
|
||||
new SubProtocolHandlerRegistry(Collections.singletonList(testProtocolHandler));
|
||||
WebSocketSession session = mock(WebSocketSession.class);
|
||||
when(session.getAcceptedProtocol()).thenReturn("foo", (String) null);
|
||||
SubProtocolHandler protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
|
||||
@@ -84,14 +85,9 @@ public class SubProtocolHandlerRegistryTests {
|
||||
WebSocketSession session = mock(WebSocketSession.class);
|
||||
when(session.getAcceptedProtocol()).thenReturn("foo", "", null);
|
||||
|
||||
try {
|
||||
subProtocolHandlerRegistry.findProtocolHandler(session);
|
||||
fail("IllegalStateException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(e.getMessage()).contains("No handler for sub-protocol 'foo'");
|
||||
}
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> subProtocolHandlerRegistry.findProtocolHandler(session))
|
||||
.withMessageContaining("No handler for sub-protocol 'foo'");
|
||||
|
||||
SubProtocolHandler protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
|
||||
assertThat(protocolHandler).isNotNull();
|
||||
|
||||
Reference in New Issue
Block a user