From e3885063218b32b65702a8a92c56cd2f695f54db Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 12 May 2016 10:48:13 -0400 Subject: [PATCH] Some fixes and improvements https://build.spring.io/browse/INT-MJATS41-629 * Revert to SF and SA BUILD-SNAPSHOTs * Upgrade to Spring Security 4.1 * Fix `RedisQueueMessageDrivenEndpointTests.testInt3442ProperlyStop()` for `atLeastOnce()` verification because in between stop and the last `rightPush` there might be one more `pop` and push again because of `listening = false` state * There is still sporadic `OutboundGatewayFunctionTests.testLazyContainerWithDest()`, so revise all the JMS tests for: - proper `ApplicationContext.stop()` in the end of test - `@DirtiesContext` if `SpringJUnit4ClassRunner` is in use - `TaskScheduler.destroy()` if that The JMS fix might relate to the https://jira.spring.io/browse/INT-4030, therefore consider this fix for cherry-picking into `4.2.x` (excluding `build.gradle` changes) --- build.gradle | 6 +++--- ...nnelPublishingJmsMessageListenerTests.java | 7 +++++-- .../jms/JmsOutboundGatewayTests.java | 5 +++-- .../jms/JmsOutboundInsideChainTests.java | 2 ++ .../jms/OutboundGatewayConnectionTests.java | 4 +++- .../jms/OutboundGatewayFunctionTests.java | 15 +++++++++++--- .../jms/config/DefaultConfigurationTests.java | 2 ++ .../config/GlobalChannelInterceptorTests.java | 7 ++++--- .../jms/config/JmsChannelHistoryTests.java | 10 +++++++--- .../config/JmsDynamicDestinationTests.java | 5 ++++- .../jms/config/JmsHeaderEnricherTests.java | 2 ++ .../JmsInboundChannelAdapterParserTests.java | 20 ++++++------------- .../jms/config/JmsMessageHistoryTests.java | 10 ++++++++-- .../jms/config/JmsPriorityTests.java | 2 ++ ...sWithMarshallingMessageConverterTests.java | 9 ++++++--- .../GatewaySerializedReplyChannelTests.java | 2 ++ .../RedisQueueMessageDrivenEndpointTests.java | 12 ++++++----- 17 files changed, 78 insertions(+), 42 deletions(-) diff --git a/build.gradle b/build.gradle index b2601aac4c..154a6fe109 100644 --- a/build.gradle +++ b/build.gradle @@ -133,15 +133,15 @@ subprojects { subproject -> slf4jVersion = "1.7.21" tomcatVersion = "8.0.33" smackVersion = '4.1.7' - springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '1.6.0.RC1' + springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '1.6.0.BUILD-SNAPSHOT' springDataJpaVersion = '1.10.1.RELEASE' springDataMongoVersion = '1.9.1.RELEASE' springDataRedisVersion = '1.7.1.RELEASE' springGemfireVersion = '1.8.1.RELEASE' - springSecurityVersion = project.hasProperty('springSecurityVersion') ? project.springSecurityVersion : '4.0.3.RELEASE' + springSecurityVersion = '4.1.0.RELEASE' springSocialTwitterVersion = '1.1.2.RELEASE' springRetryVersion = '1.1.2.RELEASE' - springVersion = project.hasProperty('springVersion') ? project.springVersion : '4.3.0.RC2' + springVersion = project.hasProperty('springVersion') ? project.springVersion : '4.3.0.BUILD-SNAPSHOT' springWsVersion = '2.3.0.RELEASE' xmlUnitVersion = '1.6' xstreamVersion = '1.4.7' diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListenerTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListenerTests.java index 7b732812e8..2ad053bdc9 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListenerTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -93,6 +93,7 @@ public class ChannelPublishingJmsMessageListenerTests { ErrorMessage received = (ErrorMessage) errorChannel.receive(0); assertNotNull(received); assertThat(received.getPayload().getMessage(), startsWith("Inbound conversion failed")); + listener.stop(); } private void startBackgroundReplier(final PollableChannel channel) { @@ -114,9 +115,11 @@ public class ChannelPublishingJmsMessageListenerTests { } @Override - public javax.jms.Message toMessage(Object object, Session session) throws JMSException, MessageConversionException { + public javax.jms.Message toMessage(Object object, Session session) + throws JMSException, MessageConversionException { return new StubTextMessage("test-to"); } + } } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java index e954612b7d..4118a778f1 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -71,7 +71,7 @@ import org.springframework.util.ObjectUtils; */ public class JmsOutboundGatewayTests extends LogAdjustingTestSupport { - final Log logger = LogFactory.getLog(this.getClass()); + private final Log logger = LogFactory.getLog(this.getClass()); @Test public void testContainerBeanNameWhenNoGatewayBeanName() { @@ -268,6 +268,7 @@ public class JmsOutboundGatewayTests extends LogAdjustingTestSupport { org.springframework.messaging.Message received = queueChannel.receive(20000); assertNotNull(received); assertEquals("bar", received.getPayload()); + gateway.stop(); connectionFactory1.destroy(); connectionFactory2.destroy(); } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundInsideChainTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundInsideChainTests.java index c66fb6f1a1..665342aba4 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundInsideChainTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundInsideChainTests.java @@ -28,6 +28,7 @@ import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -38,6 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration +@DirtiesContext public class JmsOutboundInsideChainTests { @Autowired diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/OutboundGatewayConnectionTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/OutboundGatewayConnectionTests.java index 7fb9394589..b27ff85829 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/OutboundGatewayConnectionTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/OutboundGatewayConnectionTests.java @@ -143,8 +143,10 @@ public class OutboundGatewayConnectionTests { assertTrue(latch4.await(10, TimeUnit.SECONDS)); assertNotNull(reply.get()); - broker.stop(); gateway.stop(); + broker.stop(); + + scheduler.destroy(); } } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/OutboundGatewayFunctionTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/OutboundGatewayFunctionTests.java index 3d733b858a..1ec1de32ed 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/OutboundGatewayFunctionTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/OutboundGatewayFunctionTests.java @@ -88,7 +88,8 @@ public class OutboundGatewayFunctionTests extends LogAdjustingTestSupport { .thenReturn(scheduler); final JmsOutboundGateway gateway = new JmsOutboundGateway(); gateway.setBeanFactory(beanFactory); - gateway.setConnectionFactory(getConnectionFactory()); + ConnectionFactory connectionFactory = getConnectionFactory(); + gateway.setConnectionFactory(connectionFactory); gateway.setRequestDestination(requestQueue1); gateway.setReplyDestination(replyQueue1); gateway.setCorrelationKey("JMSCorrelationID"); @@ -112,7 +113,7 @@ public class OutboundGatewayFunctionTests extends LogAdjustingTestSupport { }); assertTrue(latch1.await(10, TimeUnit.SECONDS)); JmsTemplate template = new JmsTemplate(); - template.setConnectionFactory(getConnectionFactory()); + template.setConnectionFactory(connectionFactory); template.setReceiveTimeout(5000); javax.jms.Message request = template.receive(requestQueue1); assertNotNull(request); @@ -128,6 +129,7 @@ public class OutboundGatewayFunctionTests extends LogAdjustingTestSupport { assertNotNull(reply.get()); gateway.stop(); + scheduler.destroy(); } @Test @@ -180,6 +182,7 @@ public class OutboundGatewayFunctionTests extends LogAdjustingTestSupport { assertNotNull(reply.get()); gateway.stop(); + scheduler.destroy(); } @Test @@ -232,6 +235,7 @@ public class OutboundGatewayFunctionTests extends LogAdjustingTestSupport { assertNotNull(reply.get()); gateway.stop(); + scheduler.destroy(); } @Test @@ -284,6 +288,7 @@ public class OutboundGatewayFunctionTests extends LogAdjustingTestSupport { assertNotNull(reply.get()); gateway.stop(); + scheduler.destroy(); } @Test @@ -336,6 +341,7 @@ public class OutboundGatewayFunctionTests extends LogAdjustingTestSupport { assertNotNull(reply.get()); gateway.stop(); + scheduler.destroy(); } @Test @@ -388,6 +394,7 @@ public class OutboundGatewayFunctionTests extends LogAdjustingTestSupport { assertNotNull(reply.get()); gateway.stop(); + scheduler.destroy(); } @Test @@ -452,10 +459,12 @@ public class OutboundGatewayFunctionTests extends LogAdjustingTestSupport { gateway.stop(); assertFalse(container.isRunning()); + scheduler.destroy(); } private ConnectionFactory getConnectionFactory() { - ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); + ActiveMQConnectionFactory activeMQConnectionFactory = + new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(activeMQConnectionFactory); cachingConnectionFactory.setCacheConsumers(false); return cachingConnectionFactory; diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/DefaultConfigurationTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/DefaultConfigurationTests.java index ad1f37b16c..ee537a09df 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/DefaultConfigurationTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/DefaultConfigurationTests.java @@ -32,6 +32,7 @@ import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.MessageChannel; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.ErrorHandler; @@ -43,6 +44,7 @@ import org.springframework.util.ErrorHandler; */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration +@DirtiesContext public class DefaultConfigurationTests { @Autowired diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/GlobalChannelInterceptorTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/GlobalChannelInterceptorTests.java index 74ba183536..314fe5b33e 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/GlobalChannelInterceptorTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/GlobalChannelInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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,7 +24,7 @@ import java.util.List; import org.junit.Test; -import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.channel.AbstractMessageChannel; import org.springframework.integration.channel.ChannelInterceptorAware; @@ -43,13 +43,14 @@ public class GlobalChannelInterceptorTests { @Test public void testJmsChannel() { ActiveMqTestUtils.prepare(); - ApplicationContext context = new ClassPathXmlApplicationContext( + ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( "GlobalChannelInterceptorTests-context.xml", GlobalChannelInterceptorTests.class); ChannelInterceptorAware jmsChannel = context.getBean("jmsChannel", AbstractMessageChannel.class); List interceptors = jmsChannel.getChannelInterceptors(); assertNotNull(interceptors); assertEquals(1, interceptors.size()); assertTrue(interceptors.get(0) instanceof SampleInterceptor); + context.close(); } 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 80cfd49971..9b7e96d1c4 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 @@ -27,7 +27,7 @@ import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.history.MessageHistory; import org.springframework.integration.jms.SubscribableJmsChannel; @@ -67,17 +67,21 @@ public class JmsChannelHistoryTests { }).when(template).convertAndSend(Mockito.any(Message.class)); channel.send(message); verify(template, times(1)).convertAndSend(Mockito.any(Message.class)); + channel.stop(); } @Test public void testFullConfig() throws Exception { ActiveMqTestUtils.prepare(); - ApplicationContext ac = new ClassPathXmlApplicationContext("JmsChannelHistoryTests-context.xml", this.getClass()); + 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(5000); + Message resultMessage = resultChannel.receive(10000); MessageHistory history = MessageHistory.read(resultMessage); assertTrue(history.get(0).contains("jmsChannel")); + ac.close(); } + } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsDynamicDestinationTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsDynamicDestinationTests.java index d821a87c4d..c4c619bb2f 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsDynamicDestinationTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsDynamicDestinationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2016 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. @@ -30,6 +30,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.integration.core.MessagingTemplate; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -39,6 +40,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext public class JmsDynamicDestinationTests { @Autowired @@ -100,6 +102,7 @@ public class JmsDynamicDestinationTests { public String two(String message) { return message + "!!"; } + } } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests.java index b10ab867cc..238c458647 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsHeaderEnricherTests.java @@ -31,6 +31,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; 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; @@ -41,6 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext public class JmsHeaderEnricherTests { @Autowired diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java index dca37790b4..71b007563e 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java @@ -38,10 +38,11 @@ import org.springframework.messaging.PollableChannel; /** * @author Mark Fisher * @author Gary Russell + * @author Artem Bilan */ public class JmsInboundChannelAdapterParserTests { - long timeoutOnReceive = 3000; + private long timeoutOnReceive = 3000; @Test public void adapterWithJmsTemplate() { @@ -56,7 +57,6 @@ public class JmsInboundChannelAdapterParserTests { assertEquals("jms:inbound-channel-adapter", componentHistoryRecord.get("type")); assertNotNull("message should not be null", message); assertEquals("polling-test", message.getPayload()); - context.stop(); context.close(); } @@ -65,9 +65,9 @@ public class JmsInboundChannelAdapterParserTests { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "jmsInboundWithJmsTemplate.xml", this.getClass()); JmsTemplate jmsTemplate = - TestUtils.getPropertyValue(context.getBean("inboundAdapterWithoutJmsTemplate"), "source.jmsTemplate", JmsTemplate.class); + TestUtils.getPropertyValue(context.getBean("inboundAdapterWithoutJmsTemplate"), + "source.jmsTemplate", JmsTemplate.class); assertTrue(jmsTemplate.isSessionTransacted()); - context.stop(); context.close(); } @@ -81,7 +81,6 @@ public class JmsInboundChannelAdapterParserTests { assertEquals("polling-test", message.getPayload()); assertFalse(TestUtils.getPropertyValue(context.getBean("adapter"), "source.jmsTemplate", JmsTemplate.class) .isSessionTransacted()); - context.stop(); context.close(); } @@ -93,7 +92,6 @@ public class JmsInboundChannelAdapterParserTests { Message message = output.receive(timeoutOnReceive); assertNotNull("message should not be null", message); assertEquals("polling-test", message.getPayload()); - context.stop(); context.close(); } @@ -115,14 +113,13 @@ public class JmsInboundChannelAdapterParserTests { } @Test - public void adpaterWithDestinationAndDefaultConnectionFactory() { + public void testAdapterWithDestinationAndDefaultConnectionFactory() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "jmsInboundWithDestinationAndDefaultConnectionFactory.xml", this.getClass()); PollableChannel output = (PollableChannel) context.getBean("output"); Message message = output.receive(timeoutOnReceive); assertNotNull("message should not be null", message); assertEquals("polling-test", message.getPayload()); - context.stop(); context.close(); } @@ -139,7 +136,6 @@ public class JmsInboundChannelAdapterParserTests { Message message = output.receive(timeoutOnReceive); assertNotNull("message should not be null", message); assertEquals("polling-test", message.getPayload()); - context.stop(); context.close(); } @@ -152,8 +148,7 @@ public class JmsInboundChannelAdapterParserTests { assertNotNull("message should not be null", message); assertEquals("polling-test", message.getPayload()); assertEquals("foo", message.getHeaders().get("testProperty")); - assertEquals(new Integer(123), message.getHeaders().get("testAttribute")); - context.stop(); + assertEquals(123, message.getHeaders().get("testAttribute")); context.close(); } @@ -165,7 +160,6 @@ public class JmsInboundChannelAdapterParserTests { Message message = output.receive(timeoutOnReceive); assertNotNull("message should not be null", message); assertEquals("test [with selector: TestProperty = 'foo']", message.getPayload()); - context.stop(); context.close(); } @@ -187,7 +181,6 @@ public class JmsInboundChannelAdapterParserTests { Message message = output.receive(timeoutOnReceive); assertNotNull("message should not be null", message); assertEquals("converted-test", message.getPayload()); - context.stop(); context.close(); } @@ -199,7 +192,6 @@ public class JmsInboundChannelAdapterParserTests { Message message = output.receive(timeoutOnReceive); assertNotNull("message should not be null", message); assertEquals("converted-test", message.getPayload()); - context.stop(); context.close(); } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java index 0ff491a846..9441d29ee8 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java @@ -48,18 +48,22 @@ public class JmsMessageHistoryTests { @Test public void testInboundAdapter() throws Exception { ActiveMqTestUtils.prepare(); - ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("MessageHistoryTests-context.xml", JmsMessageHistoryTests.class); + ConfigurableApplicationContext applicationContext = + new ClassPathXmlApplicationContext("MessageHistoryTests-context.xml", JmsMessageHistoryTests.class); SampleGateway gateway = applicationContext.getBean("sampleGateway", SampleGateway.class); PollableChannel jmsInputChannel = applicationContext.getBean("jmsInputChannel", PollableChannel.class); gateway.send("hello"); Message message = jmsInputChannel.receive(5000); - Iterator historyIterator = message.getHeaders().get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator(); + Iterator historyIterator = message.getHeaders() + .get(MessageHistory.HEADER_NAME, MessageHistory.class) + .iterator(); Properties event1 = historyIterator.next(); assertEquals("jms:inbound-channel-adapter", event1.getProperty(MessageHistory.TYPE_PROPERTY)); assertEquals("sampleJmsInboundAdapter", event1.getProperty(MessageHistory.NAME_PROPERTY)); Properties event2 = historyIterator.next(); assertEquals("channel", event2.getProperty(MessageHistory.TYPE_PROPERTY)); assertEquals("jmsInputChannel", event2.getProperty(MessageHistory.NAME_PROPERTY)); + applicationContext.close(); } @@ -115,6 +119,7 @@ public class JmsMessageHistoryTests { headers.remove("outbound_history"); return headers; } + } @@ -136,6 +141,7 @@ public class JmsMessageHistoryTests { public String getComponentType() { return type; } + } } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsPriorityTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsPriorityTests.java index 4da43b38e7..50dc7bc6c8 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsPriorityTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsPriorityTests.java @@ -35,6 +35,7 @@ import org.springframework.integration.channel.QueueChannel; import org.springframework.messaging.PollableChannel; import org.springframework.integration.support.MessageBuilder; import org.springframework.jms.listener.SessionAwareMessageListener; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -44,6 +45,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext public class JmsPriorityTests { @Autowired diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsWithMarshallingMessageConverterTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsWithMarshallingMessageConverterTests.java index cdc7e9526c..7d2df59214 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsWithMarshallingMessageConverterTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsWithMarshallingMessageConverterTests.java @@ -16,8 +16,8 @@ package org.springframework.integration.jms.config; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.io.InputStream; @@ -29,7 +29,7 @@ import javax.xml.transform.stream.StreamSource; import org.junit.Test; -import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; @@ -50,7 +50,7 @@ public class JmsWithMarshallingMessageConverterTests { @SuppressWarnings("unchecked") public void demoWithMarshallingConverter() { ActiveMqTestUtils.prepare(); - ApplicationContext ac = new ClassPathXmlApplicationContext( + ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext( "JmsWithMarshallingMessageConverterTests-context.xml", JmsWithMarshallingMessageConverterTests.class); MessageChannel input = ac.getBean("outbound-gateway-channel", MessageChannel.class); PollableChannel output = ac.getBean("output", PollableChannel.class); @@ -60,6 +60,7 @@ public class JmsWithMarshallingMessageConverterTests { // check for couple of JMS headers, make sure they are present assertNotNull(headers.get("jms_redelivered")); assertEquals("HELLO", replyMessage.getPayload()); + ac.close(); } @@ -87,6 +88,7 @@ public class JmsWithMarshallingMessageConverterTests { public boolean supports(Class clazz) { return true; } + } @@ -102,6 +104,7 @@ public class JmsWithMarshallingMessageConverterTests { io.read(bytes); return new GenericMessage(new String(bytes)); } + } } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/GatewaySerializedReplyChannelTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/GatewaySerializedReplyChannelTests.java index d16f5656b7..7a9c33b4ea 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/GatewaySerializedReplyChannelTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/GatewaySerializedReplyChannelTests.java @@ -27,6 +27,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; 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; @@ -37,6 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext public class GatewaySerializedReplyChannelTests { @Autowired diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/inbound/RedisQueueMessageDrivenEndpointTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/inbound/RedisQueueMessageDrivenEndpointTests.java index d91dc31d9a..a9aaffb30f 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/inbound/RedisQueueMessageDrivenEndpointTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/inbound/RedisQueueMessageDrivenEndpointTests.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.mockito.internal.verification.VerificationModeFactory.atLeastOnce; import java.util.ArrayList; import java.util.Arrays; @@ -116,7 +117,8 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests { PollableChannel channel = new QueueChannel(); - RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint(queueName, this.connectionFactory); + RedisQueueMessageDrivenEndpoint endpoint = + new RedisQueueMessageDrivenEndpoint(queueName, this.connectionFactory); endpoint.setBeanFactory(Mockito.mock(BeanFactory.class)); endpoint.setOutputChannel(channel); endpoint.setReceiveTimeout(1000); @@ -274,15 +276,14 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests { assertTrue(stopLatch.await(10, TimeUnit.SECONDS)); - Mockito.verify(boundListOperations).rightPush(Mockito.any(byte[].class)); + Mockito.verify(boundListOperations, atLeastOnce()).rightPush(Mockito.any(byte[].class)); } @Test @RedisAvailable @SuppressWarnings("unchecked") - @Ignore - //JedisConnectionFactory doesn't support proper 'destroy()' and allows to create new fresh Redis connection + @Ignore("JedisConnectionFactory doesn't support proper 'destroy()' and allows to create new fresh Redis connection") public void testInt3196Recovery() throws Exception { String queueName = "test.si.Int3196Recovery"; QueueChannel channel = new QueueChannel(); @@ -398,7 +399,8 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests { break; } Thread.sleep(100); - } while (!endpoint.isListening()); + } + while (!endpoint.isListening()); assertTrue(n < 100); }