diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/ExtractRequestReplyPayloadTests-context.xml b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/ExtractRequestReplyPayloadTests-context.xml
index 1106a3f205..43eba224d7 100644
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/ExtractRequestReplyPayloadTests-context.xml
+++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/ExtractRequestReplyPayloadTests-context.xml
@@ -3,9 +3,11 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
+ xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
- http://www.springframework.org/schema/integration/jms https://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd">
+ http://www.springframework.org/schema/integration/jms https://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
+ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
@@ -32,14 +34,8 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/ExtractRequestReplyPayloadTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/ExtractRequestReplyPayloadTests.java
index 3de6e6557a..93d55da0a4 100644
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/ExtractRequestReplyPayloadTests.java
+++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/ExtractRequestReplyPayloadTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2019 the original author or authors.
+ * Copyright 2002-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,14 +23,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.jms.JMSException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestName;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.core.MessagingTemplate;
+import org.springframework.integration.jms.ActiveMQMultiContextTests;
import org.springframework.integration.jms.ChannelPublishingJmsMessageListener;
import org.springframework.integration.jms.JmsOutboundGateway;
import org.springframework.messaging.Message;
@@ -40,21 +39,17 @@ import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.support.GenericMessage;
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;
/**
- * @author ozhurakousky
+ * @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Gary Russell
+ * @author Artem Bilan
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
+@SpringJUnitConfig
@DirtiesContext
-public class ExtractRequestReplyPayloadTests {
-
- @Rule
- public TestName testName = new TestName();
+public class ExtractRequestReplyPayloadTests extends ActiveMQMultiContextTests {
@Autowired
ApplicationContext applicationContext;
@@ -75,7 +70,7 @@ public class ExtractRequestReplyPayloadTests {
ChannelPublishingJmsMessageListener inboundGateway;
@Test
- public void testOutboundInboundDefault() {
+ public void testOutboundInboundDefault(TestInfo testInfo) {
this.outboundGateway.setExtractRequestPayload(true);
this.outboundGateway.setExtractReplyPayload(true);
@@ -84,15 +79,15 @@ public class ExtractRequestReplyPayloadTests {
MessageHandler handler = echoInboundStringHandler();
this.jmsInputChannel.subscribe(handler);
- this.outboundChannel.send(new GenericMessage("Hello " + this.testName.getMethodName()));
+ this.outboundChannel.send(new GenericMessage<>("Hello " + testInfo.getDisplayName()));
Message> replyMessage = this.replyChannel.receive(10000);
- assertThat(replyMessage.getPayload() instanceof String).isTrue();
+ assertThat(replyMessage.getPayload()).isInstanceOf(String.class);
this.jmsInputChannel.unsubscribe(handler);
}
@Test
- public void testOutboundInboundDefaultIsTx() {
+ public void testOutboundInboundDefaultIsTx(TestInfo testInfo) {
this.outboundGateway.setExtractRequestPayload(true);
this.outboundGateway.setExtractReplyPayload(true);
@@ -110,15 +105,15 @@ public class ExtractRequestReplyPayloadTests {
template.send(message);
};
this.jmsInputChannel.subscribe(handler);
- this.outboundChannel.send(new GenericMessage("Hello " + this.testName.getMethodName()));
+ this.outboundChannel.send(new GenericMessage<>("Hello " + testInfo.getDisplayName()));
Message> replyMessage = this.replyChannel.receive(10000);
- assertThat(replyMessage.getPayload() instanceof String).isTrue();
+ assertThat(replyMessage.getPayload()).isInstanceOf(String.class);
this.jmsInputChannel.unsubscribe(handler);
}
@Test
- public void testOutboundBothFalseInboundDefault() {
+ public void testOutboundBothFalseInboundDefault(TestInfo testInfo) {
this.outboundGateway.setExtractRequestPayload(false);
this.outboundGateway.setExtractReplyPayload(false);
@@ -127,7 +122,7 @@ public class ExtractRequestReplyPayloadTests {
MessageHandler handler = echoInboundStringHandler();
this.jmsInputChannel.subscribe(handler);
- this.outboundChannel.send(new GenericMessage("Hello " + this.testName.getMethodName()));
+ this.outboundChannel.send(new GenericMessage<>("Hello " + testInfo.getDisplayName()));
Message> replyMessage = this.replyChannel.receive(10000);
assertThat(replyMessage.getPayload()).isInstanceOf(javax.jms.TextMessage.class);
@@ -135,7 +130,7 @@ public class ExtractRequestReplyPayloadTests {
}
@Test
- public void testOutboundDefaultInboundBothFalse() throws Exception {
+ public void testOutboundDefaultInboundBothFalse(TestInfo testInfo) {
this.outboundGateway.setExtractRequestPayload(true);
this.outboundGateway.setExtractReplyPayload(true);
@@ -144,14 +139,14 @@ public class ExtractRequestReplyPayloadTests {
MessageHandler handler = unwrapTextMessageAndEchoHandler();
this.jmsInputChannel.subscribe(handler);
- this.outboundChannel.send(new GenericMessage("Hello " + this.testName.getMethodName()));
+ this.outboundChannel.send(new GenericMessage<>("Hello " + testInfo.getDisplayName()));
Message> replyMessage = this.replyChannel.receive(10000);
assertThat(replyMessage.getPayload()).isInstanceOf(String.class);
this.jmsInputChannel.unsubscribe(handler);
}
@Test
- public void testOutboundDefaultInboundReplyTrueRequestFalse() {
+ public void testOutboundDefaultInboundReplyTrueRequestFalse(TestInfo testInfo) {
this.outboundGateway.setExtractRequestPayload(true);
this.outboundGateway.setExtractReplyPayload(true);
@@ -160,14 +155,14 @@ public class ExtractRequestReplyPayloadTests {
MessageHandler handler = unwrapTextMessageAndEchoHandler();
this.jmsInputChannel.subscribe(handler);
- this.outboundChannel.send(new GenericMessage("Hello " + this.testName.getMethodName()));
+ this.outboundChannel.send(new GenericMessage<>("Hello " + testInfo.getDisplayName()));
Message> replyMessage = this.replyChannel.receive(10000);
assertThat(replyMessage.getPayload()).isInstanceOf(String.class);
this.jmsInputChannel.unsubscribe(handler);
}
@Test
- public void testOutboundDefaultInboundReplyFalseRequestTrue() {
+ public void testOutboundDefaultInboundReplyFalseRequestTrue(TestInfo testInfo) {
this.outboundGateway.setExtractRequestPayload(true);
this.outboundGateway.setExtractReplyPayload(true);
@@ -176,14 +171,14 @@ public class ExtractRequestReplyPayloadTests {
MessageHandler handler = echoInboundStringHandler();
this.jmsInputChannel.subscribe(handler);
- this.outboundChannel.send(new GenericMessage("Hello " + this.testName.getMethodName()));
+ this.outboundChannel.send(new GenericMessage<>("Hello " + testInfo.getDisplayName()));
Message> replyMessage = this.replyChannel.receive(10000);
- assertThat(replyMessage.getPayload() instanceof String).isTrue();
+ assertThat(replyMessage.getPayload()).isInstanceOf(String.class);
this.jmsInputChannel.unsubscribe(handler);
}
@Test
- public void testOutboundRequestTrueReplyFalseInboundDefault() {
+ public void testOutboundRequestTrueReplyFalseInboundDefault(TestInfo testInfo) {
this.outboundGateway.setExtractRequestPayload(true);
this.outboundGateway.setExtractReplyPayload(false);
@@ -192,14 +187,14 @@ public class ExtractRequestReplyPayloadTests {
MessageHandler handler = echoInboundStringHandler();
this.jmsInputChannel.subscribe(handler);
- this.outboundChannel.send(new GenericMessage("Hello " + this.testName.getMethodName()));
+ this.outboundChannel.send(new GenericMessage<>("Hello " + testInfo.getDisplayName()));
Message> replyMessage = this.replyChannel.receive(10000);
- assertThat(replyMessage.getPayload() instanceof javax.jms.Message).isTrue();
+ assertThat(replyMessage.getPayload()).isInstanceOf(javax.jms.Message.class);
this.jmsInputChannel.unsubscribe(handler);
}
@Test
- public void testOutboundRequestFalseReplyTrueInboundDefault() {
+ public void testOutboundRequestFalseReplyTrueInboundDefault(TestInfo testInfo) {
this.outboundGateway.setExtractRequestPayload(false);
this.outboundGateway.setExtractReplyPayload(true);
@@ -208,14 +203,14 @@ public class ExtractRequestReplyPayloadTests {
MessageHandler handler = echoInboundStringHandler();
this.jmsInputChannel.subscribe(handler);
- this.outboundChannel.send(new GenericMessage("Hello " + this.testName.getMethodName()));
+ this.outboundChannel.send(new GenericMessage<>("Hello " + testInfo.getDisplayName()));
Message> replyMessage = this.replyChannel.receive(10000);
assertThat(replyMessage.getPayload()).isInstanceOf(String.class);
this.jmsInputChannel.unsubscribe(handler);
}
@Test
- public void testAllFalse() throws Exception {
+ public void testAllFalse(TestInfo testInfo) {
this.outboundGateway.setExtractRequestPayload(false);
this.outboundGateway.setExtractReplyPayload(false);
@@ -224,7 +219,7 @@ public class ExtractRequestReplyPayloadTests {
MessageHandler handler = unwrapObjectMessageAndEchoHandler();
this.jmsInputChannel.subscribe(handler);
- this.outboundChannel.send(new GenericMessage("Hello " + this.testName.getMethodName()));
+ this.outboundChannel.send(new GenericMessage<>("Hello " + testInfo.getDisplayName()));
Message> replyMessage = this.replyChannel.receive(10000);
assertThat(replyMessage.getPayload()).isInstanceOf(javax.jms.Message.class);
this.jmsInputChannel.unsubscribe(handler);
@@ -267,7 +262,7 @@ public class ExtractRequestReplyPayloadTests {
catch (JMSException e) {
fail("failed to deserialize message");
}
- template.send(new GenericMessage(payload));
+ template.send(new GenericMessage<>(payload));
};
}
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/InboundOneWayErrorTests-context.xml b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/InboundOneWayErrorTests-context.xml
index 3fb80e6a7f..32ec125108 100644
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/InboundOneWayErrorTests-context.xml
+++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/InboundOneWayErrorTests-context.xml
@@ -1,19 +1,18 @@
+ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
-
+
@@ -23,7 +22,7 @@
-
+
@@ -37,16 +36,10 @@
-
+
-
-
-
-
-
-
-
-
-
+
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/InboundOneWayErrorTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/InboundOneWayErrorTests.java
index 9082246e2b..7fbd22ca20 100644
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/InboundOneWayErrorTests.java
+++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/InboundOneWayErrorTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2019 the original author or authors.
+ * Copyright 2002-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.
@@ -24,28 +24,36 @@ import java.util.concurrent.TimeUnit;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.integration.jms.ActiveMQMultiContextTests;
import org.springframework.jms.core.JmsTemplate;
-import org.springframework.jms.core.MessageCreator;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.PollableChannel;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.util.ErrorHandler;
/**
* @author Mark Fisher
* @author Gary Russell
+ * @author Artem Bilan
*/
-public class InboundOneWayErrorTests {
+@SpringJUnitConfig
+@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
+public class InboundOneWayErrorTests extends ActiveMQMultiContextTests {
+
+ @Autowired
+ ApplicationContext context;
@Test
public void noErrorChannel() throws Exception {
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("InboundOneWayErrorTests-context.xml", getClass());
JmsTemplate jmsTemplate = new JmsTemplate(context.getBean("jmsConnectionFactory", ConnectionFactory.class));
Destination queue = context.getBean("queueA", Destination.class);
- jmsTemplate.send(queue, (MessageCreator) session -> session.createTextMessage("test-A"));
+ jmsTemplate.send(queue, session -> session.createTextMessage("test-A"));
TestErrorHandler errorHandler = context.getBean("testErrorHandler", TestErrorHandler.class);
errorHandler.latch.await(3000, TimeUnit.MILLISECONDS);
assertThat(errorHandler.lastError).isNotNull();
@@ -53,15 +61,13 @@ public class InboundOneWayErrorTests {
assertThat(errorHandler.lastError.getCause().getMessage()).isEqualTo("failed to process: test-A");
PollableChannel testErrorChannel = context.getBean("testErrorChannel", PollableChannel.class);
assertThat(testErrorChannel.receive(0)).isNull();
- context.close();
}
@Test
- public void errorChannel() throws Exception {
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("InboundOneWayErrorTests-context.xml", getClass());
+ public void errorChannel() {
JmsTemplate jmsTemplate = new JmsTemplate(context.getBean("jmsConnectionFactory", ConnectionFactory.class));
Destination queue = context.getBean("queueB", Destination.class);
- jmsTemplate.send(queue, (MessageCreator) session -> session.createTextMessage("test-B"));
+ jmsTemplate.send(queue, session -> session.createTextMessage("test-B"));
PollableChannel errorChannel = context.getBean("testErrorChannel", PollableChannel.class);
Message> errorMessage = errorChannel.receive(3000);
assertThat(errorMessage).isNotNull();
@@ -72,22 +78,25 @@ public class InboundOneWayErrorTests {
assertThat(exception.getCause().getMessage()).isEqualTo("failed to process: test-B");
TestErrorHandler errorHandler = context.getBean("testErrorHandler", TestErrorHandler.class);
assertThat(errorHandler.lastError).isNull();
- context.close();
}
public static class TestService {
+
public void process(Object o) {
throw new TestException("failed to process: " + o);
}
+
}
@SuppressWarnings("serial")
private static class TestException extends RuntimeException {
+
TestException(String message) {
super(message);
}
+
}
private static class TestErrorHandler implements ErrorHandler {
@@ -101,6 +110,7 @@ public class InboundOneWayErrorTests {
this.lastError = t;
this.latch.countDown();
}
+
}
}
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelHistoryTests-context.xml b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelHistoryTests-context.xml
index 735a4aff36..7e83fd0969 100644
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelHistoryTests-context.xml
+++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelHistoryTests-context.xml
@@ -1,11 +1,13 @@
+ http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
@@ -21,14 +23,7 @@
-
-
-
-
-
-
-
-
-
-
+
+
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelHistoryTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelHistoryTests.java
index 187cdcc550..c937192665 100644
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelHistoryTests.java
+++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelHistoryTests.java
@@ -25,9 +25,10 @@ import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
import org.springframework.integration.history.MessageHistory;
+import org.springframework.integration.jms.ActiveMQMultiContextTests;
import org.springframework.integration.jms.SubscribableJmsChannel;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.AbstractMessageListenerContainer;
@@ -35,6 +36,8 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.support.GenericMessage;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Oleg Zhurakousky
@@ -42,7 +45,12 @@ import org.springframework.messaging.support.GenericMessage;
* @author Gary Russell
* @author Artem Bilan
*/
-public class JmsChannelHistoryTests {
+@SpringJUnitConfig
+@DirtiesContext
+public class JmsChannelHistoryTests extends ActiveMQMultiContextTests {
+
+ @Autowired
+ ApplicationContext context;
@Test
public void testMessageHistory() {
@@ -66,16 +74,12 @@ public class JmsChannelHistoryTests {
@Test
public void testFullConfig() {
- try (ConfigurableApplicationContext ac =
- new ClassPathXmlApplicationContext("JmsChannelHistoryTests-context.xml", this.getClass())) {
-
- SubscribableChannel channel = ac.getBean("jmsChannel", SubscribableChannel.class);
- PollableChannel resultChannel = ac.getBean("resultChannel", PollableChannel.class);
- channel.send(new GenericMessage<>("hello"));
- Message> resultMessage = resultChannel.receive(10000);
- MessageHistory history = MessageHistory.read(resultMessage);
- assertThat(history.get(0).contains("jmsChannel")).isTrue();
- }
+ SubscribableChannel channel = context.getBean("jmsChannel", SubscribableChannel.class);
+ PollableChannel resultChannel = context.getBean("resultChannel", PollableChannel.class);
+ channel.send(new GenericMessage<>("hello"));
+ Message> resultMessage = resultChannel.receive(10000);
+ MessageHistory history = MessageHistory.read(resultMessage);
+ assertThat(history.get(0).contains("jmsChannel")).isTrue();
}
}
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests-context.xml b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests-context.xml
index 0a1172fdff..b7e8466ed0 100644
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests-context.xml
+++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests-context.xml
@@ -1,12 +1,13 @@
+ http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd
+ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
@@ -63,9 +64,8 @@
-
-
-
+
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests.java
index 39165e9b1a..2dfccf3e2e 100644
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests.java
+++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2019 the original author or authors.
+ * Copyright 2002-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.
@@ -27,11 +27,11 @@ import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.Topic;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.integration.jms.ActiveMQMultiContextTests;
import org.springframework.integration.jms.PollableJmsChannel;
import org.springframework.integration.jms.SubscribableJmsChannel;
import org.springframework.integration.support.MessageBuilderFactory;
@@ -44,17 +44,16 @@ import org.springframework.jms.support.destination.DestinationResolver;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.ChannelInterceptor;
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;
/**
* @author Mark Fisher
* @author Gary Russell
+ * @author Artem Bilan
*/
-@ContextConfiguration
-@RunWith(SpringJUnit4ClassRunner.class)
+@SpringJUnitConfig
@DirtiesContext
-public class JmsChannelParserTests {
+public class JmsChannelParserTests extends ActiveMQMultiContextTests {
@Autowired
private MessageChannel queueReferenceChannel;
@@ -125,7 +124,8 @@ public class JmsChannelParserTests {
SubscribableJmsChannel channel = (SubscribableJmsChannel) queueReferenceChannel;
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
JmsTemplate jmsTemplate = (JmsTemplate) accessor.getPropertyValue("jmsTemplate");
- AbstractMessageListenerContainer container = (AbstractMessageListenerContainer) accessor.getPropertyValue("container");
+ AbstractMessageListenerContainer container =
+ (AbstractMessageListenerContainer) accessor.getPropertyValue("container");
assertThat(jmsTemplate.getDefaultDestination()).isEqualTo(queue);
assertThat(container.getDestination()).isEqualTo(queue);
assertThat(TestUtils.getPropertyValue(jmsTemplate, "explicitQosEnabled")).isEqualTo(true);
@@ -336,10 +336,12 @@ public class JmsChannelParserTests {
}
return pubSubDomain ? topic : queue;
}
+
}
static class TestInterceptor implements ChannelInterceptor {
+
}
static class CustomTestMessageListenerContainer extends DefaultMessageListenerContainer {
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundGatewayParserTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundGatewayParserTests.java
index 32d20f09bd..fafee86de9 100644
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundGatewayParserTests.java
+++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundGatewayParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2019 the original author or authors.
+ * Copyright 2002-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.beans.factory.BeanDefinitionStoreException;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.history.MessageHistory;
+import org.springframework.integration.jms.ActiveMQMultiContextTests;
import org.springframework.integration.jms.JmsMessageDrivenEndpoint;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.integration.test.util.TestUtils;
@@ -48,7 +49,7 @@ import org.springframework.util.MultiValueMap;
* @author Gary Russell
* @author Artem Bilan
*/
-public class JmsInboundGatewayParserTests {
+public class JmsInboundGatewayParserTests extends ActiveMQMultiContextTests {
@Test
public void testGatewayWithConnectionFactoryAndDestination() {
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/MessageHistoryTests-gateways.xml b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/MessageHistoryTests-gateways.xml
deleted file mode 100644
index a63523f9cb..0000000000
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/MessageHistoryTests-gateways.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/MessageHistoryTests-withHeaderMapper.xml b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/MessageHistoryTests-withHeaderMapper.xml
deleted file mode 100644
index 697945c371..0000000000
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/MessageHistoryTests-withHeaderMapper.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/gatewayMaintainsReplyChannel.xml b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/gatewayMaintainsReplyChannel.xml
index f2a6ad14f6..9de8841bee 100644
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/gatewayMaintainsReplyChannel.xml
+++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/gatewayMaintainsReplyChannel.xml
@@ -1,11 +1,13 @@
+ http://www.springframework.org/schema/integration/jms https://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
+ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
@@ -68,16 +70,8 @@
-
-
-
-
-
-
-
-
-
-
+
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/jmsGatewayWithReplyChannel.xml b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/jmsGatewayWithReplyChannel.xml
index 9e90534020..20c0e35892 100644
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/jmsGatewayWithReplyChannel.xml
+++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/jmsGatewayWithReplyChannel.xml
@@ -1,14 +1,16 @@
+ https://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
+ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
@@ -29,12 +31,8 @@
-
-
-
-
-
-
-
+
+
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/explicit-correlation-key.xml b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/explicit-correlation-key.xml
index 589cf4d6f2..e06bee5c2c 100644
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/explicit-correlation-key.xml
+++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/explicit-correlation-key.xml
@@ -1,10 +1,13 @@
+ http://www.springframework.org/schema/integration/jms https://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
+ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
@@ -93,15 +96,7 @@
-
-
-
-
-
-
-
-
-
-
+
diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/honor-timeout.xml b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/honor-timeout.xml
index bc51b577ed..0c3a5392c0 100644
--- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/honor-timeout.xml
+++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/honor-timeout.xml
@@ -1,11 +1,13 @@
+ http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
@@ -28,14 +30,7 @@
-
-
-
-
-
-
-
-
+
diff --git a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/StompSessionManagerTests.java b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/StompSessionManagerTests.java
index 59df502980..89d3893967 100644
--- a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/StompSessionManagerTests.java
+++ b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/StompSessionManagerTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2020 the original author or authors.
+ * Copyright 2016-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.
@@ -54,7 +54,7 @@ public class StompSessionManagerTests {
throw new RuntimeException("intentional");
}
else {
- SettableListenableFuture future = new SettableListenableFuture();
+ SettableListenableFuture future = new SettableListenableFuture<>();
StompSession stompSession = mock(StompSession.class);
future.set(stompSession);
handler.afterConnected(stompSession, getConnectHeaders());
@@ -66,7 +66,7 @@ public class StompSessionManagerTests {
sessionManager.start();
- final SettableListenableFuture stompSessionFuture = new SettableListenableFuture();
+ final SettableListenableFuture stompSessionFuture = new SettableListenableFuture<>();
sessionManager.connect(new StompSessionHandlerAdapter() {
@Override
diff --git a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java
index d77e3ee4e5..26cc6f11e5 100644
--- a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java
+++ b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2020 the original author or authors.
+ * Copyright 2015-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.
@@ -323,7 +323,8 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests {
@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response,
- WebSocketHandler wsHandler, Map attributes) throws Exception {
+ WebSocketHandler wsHandler, Map attributes) {
+
return request.getHeaders().getOrigin() != null;
}
diff --git a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/ClientWebSocketContainerTests.java b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/ClientWebSocketContainerTests.java
index a2b3a8c66a..33719181c4 100644
--- a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/ClientWebSocketContainerTests.java
+++ b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/ClientWebSocketContainerTests.java
@@ -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) {
diff --git a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/TomcatWebSocketTestServer.java b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/TomcatWebSocketTestServer.java
index d7dc2f4dec..aa5e9810c6 100644
--- a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/TomcatWebSocketTestServer.java
+++ b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/TomcatWebSocketTestServer.java
@@ -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();
}
diff --git a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/StompIntegrationTests.java b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/StompIntegrationTests.java
index 302c86d2a8..d4c14b5cf7 100644
--- a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/StompIntegrationTests.java
+++ b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/StompIntegrationTests.java
@@ -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.singletonList(new WebSocketTransport(new StandardWebSocketClient())));
+ return new SockJsClient(Collections.singletonList(new WebSocketTransport(new StandardWebSocketClient())));
}
@Bean
diff --git a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/WebSocketClientTests.java b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/WebSocketClientTests.java
index 1acf1e522b..89a3d60aa6 100644
--- a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/WebSocketClientTests.java
+++ b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/WebSocketClientTests.java
@@ -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 {
diff --git a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/config/WebSocketParserTests.java b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/config/WebSocketParserTests.java
index a558af26e8..fd501db04e 100644
--- a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/config/WebSocketParserTests.java
+++ b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/config/WebSocketParserTests.java
@@ -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",
diff --git a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/inbound/WebSocketInboundChannelAdapterTests.java b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/inbound/WebSocketInboundChannelAdapterTests.java
index 34e493a63f..f4e6156ece 100644
--- a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/inbound/WebSocketInboundChannelAdapterTests.java
+++ b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/inbound/WebSocketInboundChannelAdapterTests.java
@@ -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 message = MessageBuilder.createMessage(ByteBuffer.allocate(0).array(), headers.getMessageHeaders());
+ Message message =
+ MessageBuilder.createMessage(ByteBuffer.allocate(0).array(), headers.getMessageHeaders());
this.clientOutboundChannel.send(message);
diff --git a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/outbound/WebSocketOutboundMessageHandlerTests.java b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/outbound/WebSocketOutboundMessageHandlerTests.java
index 12c028cd30..87d7e7fff3 100644
--- a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/outbound/WebSocketOutboundMessageHandlerTests.java
+++ b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/outbound/WebSocketOutboundMessageHandlerTests.java
@@ -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);
}
diff --git a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/server/WebSocketServerTests.java b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/server/WebSocketServerTests.java
index 18b1eb9fcd..b9cdd339a7 100644
--- a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/server/WebSocketServerTests.java
+++ b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/server/WebSocketServerTests.java
@@ -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 webSocketEventListener() {
ApplicationEventListeningMessageProducer producer = new ApplicationEventListeningMessageProducer();
producer.setEventTypes(PayloadApplicationEvent.class);
diff --git a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/support/SubProtocolHandlerRegistryTests.java b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/support/SubProtocolHandlerRegistryTests.java
index 3db529f907..9ba86bb075 100644
--- a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/support/SubProtocolHandlerRegistryTests.java
+++ b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/support/SubProtocolHandlerRegistryTests.java
@@ -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.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.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();