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:
Artem Bilan
2021-03-15 12:03:27 -04:00
parent 78a0ae8a04
commit bb608d8922
26 changed files with 230 additions and 367 deletions

View File

@@ -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">
<int:channel id="outboundChannel"/>
@@ -32,14 +34,8 @@
<bean id="extractRecRepQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="request.queue.req.rep"/>
</bean>
<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
<property name="trustAllPackages" value="true"/>
</bean>
</property>
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
<util:constant id="jmsConnectionFactory"
static-field="org.springframework.integration.jms.ActiveMQMultiContextTests.connectionFactory"/>
</beans>

View File

@@ -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<String>("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<String>("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<String>("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<String>("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<String>("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<String>("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<String>("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<String>("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<String>("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<String>(payload));
template.send(new GenericMessage<>(payload));
};
}

View File

@@ -1,19 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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:jms="http://www.springframework.org/schema/jms"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
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/jms https://www.springframework.org/schema/jms/spring-jms.xsd
http://www.springframework.org/schema/task https://www.springframework.org/schema/task/spring-task.xsd">
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<int-jms:message-driven-channel-adapter channel="jmsInputChannel" container="container"/>
<int-jms:message-driven-channel-adapter channel="jmsInputChannel" destination="queueB" error-channel="testErrorChannel"/>
<int-jms:message-driven-channel-adapter channel="jmsInputChannel" destination="queueB"
error-channel="testErrorChannel"/>
<int:service-activator input-channel="jmsInputChannel">
<bean id="testService" class="org.springframework.integration.jms.config.InboundOneWayErrorTests$TestService"/>
@@ -23,7 +22,7 @@
<int:queue/>
</int:channel>
<bean id="queueA" class="org.apache.activemq.command.ActiveMQQueue">
<bean id="queueA" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="oneway.a"/>
</bean>
@@ -37,16 +36,10 @@
<property name="errorHandler" ref="testErrorHandler"/>
</bean>
<bean id="testErrorHandler" class="org.springframework.integration.jms.config.InboundOneWayErrorTests$TestErrorHandler"/>
<bean id="testErrorHandler"
class="org.springframework.integration.jms.config.InboundOneWayErrorTests$TestErrorHandler"/>
<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
</property>
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
<util:constant id="jmsConnectionFactory"
static-field="org.springframework.integration.jms.ActiveMQMultiContextTests.connectionFactory"/>
</beans>

View File

@@ -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();
}
}
}

View File

@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="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/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
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">
<int:message-history/>
@@ -21,14 +23,7 @@
<constructor-arg value="request.queue."/>
</bean>
<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
<property name="trustAllPackages" value="true"/>
</bean>
</property>
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
<util:constant id="jmsConnectionFactory"
static-field="org.springframework.integration.jms.ActiveMQMultiContextTests.connectionFactory"/>
</beans>

View File

@@ -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();
}
}

View File

@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/jms https://www.springframework.org/schema/jms/spring-jms.xsd
http://www.springframework.org/schema/integration/jms https://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/integration/jms https://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
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">
<context:property-placeholder location="classpath:org/springframework/integration/jms/config/channel.properties"/>
@@ -63,9 +64,8 @@
<bean id="destinationResolver"
class="org.springframework.integration.jms.config.JmsChannelParserTests$TestDestinationResolver"/>
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
<util:constant id="jmsConnectionFactory"
static-field="org.springframework.integration.jms.ActiveMQMultiContextTests.amqFactory"/>
<alias name="jmsConnectionFactory" alias="connFact"/>

View File

@@ -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 {

View File

@@ -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() {

View File

@@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd
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"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms">
<int:gateway id="sampleGateway" default-request-channel="channel-a" service-interface="org.springframework.integration.jms.config.JmsMessageHistoryTests.SampleGateway"/>
<int:publish-subscribe-channel id="channel-a"/>
<int-jms:outbound-gateway id="jmsOutbound" request-channel="channel-a" request-destination-name="request.queue_b" header-mapper="headerMapper"/>
<int-jms:inbound-gateway id="jmsInbound" request-channel="inbound-jms-channel" request-destination-name="request.queue_b" header-mapper="headerMapper"/>
<int:publish-subscribe-channel id="inbound-jms-channel"/>
<int:service-activator id="sampleService-a" input-channel="inbound-jms-channel">
<bean class="org.springframework.integration.jms.config.JmsMessageHistoryTests.SampleService"/>
</int:service-activator>
<bean id="historyWriter" class="org.springframework.integration.history.MessageHistoryWriter"/>
<bean id="headerMapper" class="org.springframework.integration.jms.config.JmsMessageHistoryTests$SampleHeaderMapper"/>
<int:poller id="poller" default="true">
<int:interval-trigger interval="10"/>
</int:poller>
<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
</property>
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
</beans>

View File

@@ -1,42 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/jms https://www.springframework.org/schema/jms/spring-jms.xsd
http://www.springframework.org/schema/task https://www.springframework.org/schema/task/spring-task.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:task="http://www.springframework.org/schema/task">
<int:channel id="outbound-channel"/>
<int-jms:outbound-channel-adapter id="jmsOutbound" channel="outbound-channel" destination-name="request.queue_a" header-mapper="headerMapper"/>
<int-jms:inbound-channel-adapter id="sampleJmsInboundAdapter" channel="jmsInputChannel" destination-name="request.queue_a" header-mapper="headerMapper"/>
<int:channel id="jmsInputChannel">
<int:queue capacity="2"/>
</int:channel>
<int:poller id="poller" default="true">
<int:interval-trigger interval="10"/>
</int:poller>
<bean id="headerMapper" class="org.springframework.integration.jms.config.JmsMessageHistoryTests$SampleHeaderMapper"/>
<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
</property>
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
<bean id="historyWriter" class="org.springframework.integration.history.MessageHistoryWriter"/>
</beans>

View File

@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
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"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms">
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">
<int:message-history/>
@@ -68,16 +70,8 @@
<constructor-arg value="reply.queueB"/>
</bean>
<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
</property>
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
<util:constant id="jmsConnectionFactory"
static-field="org.springframework.integration.jms.ActiveMQMultiContextTests.connectionFactory"/>
<int-jms:inbound-gateway id="inboundGateway" request-channel="jmsInput" request-destination="requestQueueA"/>

View File

@@ -1,14 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns: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">
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">
<si:channel id="requests"/>
@@ -29,12 +31,8 @@
<bean id="testReplyDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="testReplyDestination"/>
</bean>
<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
</property>
</bean>
<util:constant id="jmsConnectionFactory"
static-field="org.springframework.integration.jms.ActiveMQMultiContextTests.amqFactory"/>
</beans>

View File

@@ -1,10 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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: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">
<int:gateway id="explicitCorrelationKeyGateway" default-request-channel="explicitCorrelationIn"/>
@@ -93,15 +96,7 @@
<bean class="org.springframework.integration.jms.request_reply.RequestReplyScenariosWithCorrelationKeyProvidedTests.DelayedService"/>
</int:transformer>
<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
</property>
<property name="cacheProducers" value="true" />
<property name="cacheConsumers" value="true" />
<property name="sessionCacheSize" value="10" />
</bean>
<util:constant id="jmsConnectionFactory"
static-field="org.springframework.integration.jms.ActiveMQMultiContextTests.amqFactory"/>
</beans>

View File

@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
xsi:schemaLocation="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/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
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">
<int:gateway default-request-channel="in" default-request-timeout="20000" default-reply-timeout="20000"/>
@@ -28,14 +30,7 @@
<int:transformer expression="payload"/>
</int:chain>
<bean id="jmsConnectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
</property>
<property name="cacheConsumers" value="false"/>
</bean>
<util:constant id="jmsConnectionFactory"
static-field="org.springframework.integration.jms.ActiveMQMultiContextTests.amqFactory"/>
</beans>

View File

@@ -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<StompSession> future = new SettableListenableFuture<StompSession>();
SettableListenableFuture<StompSession> 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<StompSession> stompSessionFuture = new SettableListenableFuture<StompSession>();
final SettableListenableFuture<StompSession> stompSessionFuture = new SettableListenableFuture<>();
sessionManager.connect(new StompSessionHandlerAdapter() {
@Override

View File

@@ -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<String, Object> attributes) throws Exception {
WebSocketHandler wsHandler, Map<String, Object> attributes) {
return request.getHeaders().getOrigin() != null;
}

View File

@@ -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) {

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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 {

View File

@@ -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",

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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();