From fb517dbba6ab73294a331198ef23f6b6ae9da67c Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 24 Apr 2017 17:17:45 -0400 Subject: [PATCH] Add `@DirtiesContext` for some JMX tests https://build.spring.io/browse/INT-B41X-121/ --- .../jmx/MBeanAttributeFilterTests.java | 2 ++ ...ficationListeningMessageProducerTests.java | 6 ++++- ...ibutePollingChannelAdapterParserTests.java | 5 ++++- .../jmx/config/DynamicRouterTests.java | 16 +++++++------- ...nTreePollingChannelAdapterParserTests.java | 22 +++++++++---------- ...ionListeningChannelAdapterParserTests.java | 2 ++ .../jmx/config/PollingAdapterMBeanTests.java | 4 +++- .../jmx/config/PriorityChannelTests.java | 4 +++- .../monitor/RemoteMBeanServerTests.java | 5 ++++- .../mbeanexporterhelper/Int2307Tests.java | 9 ++++++-- 10 files changed, 49 insertions(+), 26 deletions(-) diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/MBeanAttributeFilterTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/MBeanAttributeFilterTests.java index d4fb4add20..085e1de168 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/MBeanAttributeFilterTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/MBeanAttributeFilterTests.java @@ -31,6 +31,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; import org.springframework.messaging.Message; import org.springframework.messaging.PollableChannel; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -40,6 +41,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration +@DirtiesContext public class MBeanAttributeFilterTests { @Autowired diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/NotificationListeningMessageProducerTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/NotificationListeningMessageProducerTests.java index ac38c9cf36..cdcfd00441 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/NotificationListeningMessageProducerTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/NotificationListeningMessageProducerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2017 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. @@ -96,6 +96,7 @@ public class NotificationListeningMessageProducerTests { assertEquals("foo", notification.getMessage()); assertEquals(objectName, notification.getSource()); assertNull(message.getHeaders().get(JmxHeaders.NOTIFICATION_HANDBACK)); + adapter.stop(); } @Test @@ -119,6 +120,7 @@ public class NotificationListeningMessageProducerTests { assertEquals("foo", notification.getMessage()); assertEquals(objectName, notification.getSource()); assertEquals(handback, message.getHeaders().get(JmxHeaders.NOTIFICATION_HANDBACK)); + adapter.stop(); } @Test @@ -148,6 +150,7 @@ public class NotificationListeningMessageProducerTests { assertTrue(message.getPayload() instanceof Notification); Notification notification = (Notification) message.getPayload(); assertEquals("okay", notification.getMessage()); + adapter.stop(); } @@ -176,6 +179,7 @@ public class NotificationListeningMessageProducerTests { Notification notification = new Notification("testType", this, sequence.getAndIncrement(), message); this.notificationPublisher.sendNotification(notification); } + } } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests.java index 2822822323..85989afe62 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 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. @@ -29,6 +29,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; import org.springframework.integration.test.util.TestUtils; +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 AttributePollingChannelAdapterParserTests { @Autowired @@ -63,6 +65,7 @@ public class AttributePollingChannelAdapterParserTests { Message result = channel.receive(1000); assertNotNull(result); assertEquals("foo", result.getPayload()); + adapter.stop(); } @Test diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/DynamicRouterTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/DynamicRouterTests.java index dfee72fdb1..d67cd76423 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/DynamicRouterTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/DynamicRouterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2017 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. @@ -21,16 +21,15 @@ import static org.junit.Assert.assertEquals; import java.util.HashMap; import java.util.Map; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.messaging.MessageChannel; import org.springframework.integration.channel.QueueChannel; -import org.springframework.messaging.support.GenericMessage; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.MessageChannel; +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; @@ -38,10 +37,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Oleg Zhurakousky * @author Gary Russell + * @author Artem Bilan * */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class DynamicRouterTests { @Autowired @@ -65,7 +66,7 @@ public class DynamicRouterTests { private QueueChannel processCChannel; - @Test @DirtiesContext + @Test public void testRouteChange() throws Exception { routingChannel.send(new GenericMessage("123")); assertEquals("123", processAChannel.receive(0).getPayload()); @@ -78,7 +79,7 @@ public class DynamicRouterTests { assertEquals("123", processCChannel.receive(0).getPayload()); } - @Test @DirtiesContext + @Test public void testRouteChangeMap() throws Exception { routingChannel.send(new GenericMessage("123")); assertEquals("123", processAChannel.receive(0).getPayload()); @@ -94,8 +95,7 @@ public class DynamicRouterTests { assertEquals("123", processCChannel.receive(0).getPayload()); } - @Test @DirtiesContext - @Ignore // Requires Spring 3.2.3 TODO: Remove when minimum SF is >= 3.2.3 + @Test public void testRouteChangeMapNamedArgs() throws Exception { routingChannel.send(new GenericMessage("123")); assertEquals("123", processAChannel.receive(0).getPayload()); diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanTreePollingChannelAdapterParserTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanTreePollingChannelAdapterParserTests.java index 71c0c05469..09815ef685 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanTreePollingChannelAdapterParserTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanTreePollingChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 201302017 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.jmx.config; import static org.junit.Assert.assertEquals; @@ -24,12 +25,12 @@ import static org.junit.Assert.assertTrue; import java.util.HashMap; import java.util.Map; -import javax.management.MBeanServer; import javax.management.ObjectName; import javax.management.QueryExp; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; @@ -37,6 +38,7 @@ import org.springframework.integration.jmx.MBeanObjectConverter; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.PollableChannel; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -47,6 +49,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration +@DirtiesContext public class MBeanTreePollingChannelAdapterParserTests { @Autowired @@ -100,10 +103,7 @@ public class MBeanTreePollingChannelAdapterParserTests { @Autowired private MBeanObjectConverter converter; - @Autowired - private MBeanServer mbeanServer; - - private final long testTimeout = 2000L; + private final long testTimeout = 20000L; @Test public void pollDefaultAdapter() throws Exception { @@ -140,7 +140,7 @@ public class MBeanTreePollingChannelAdapterParserTests { assertTrue(beans.containsKey("java.lang:type=OperatingSystem")); assertTrue(beans.containsKey("java.lang:type=Runtime")); - adapterDefault.stop(); + adapterInner.stop(); } @Test @@ -165,7 +165,7 @@ public class MBeanTreePollingChannelAdapterParserTests { assertFalse(beans.containsKey("java.lang:type=OperatingSystem")); assertTrue(beans.containsKey("java.lang:type=Runtime")); - adapterDefault.stop(); + adapterQueryName.stop(); } @Test @@ -184,7 +184,7 @@ public class MBeanTreePollingChannelAdapterParserTests { assertTrue(beans.containsKey("java.lang:type=OperatingSystem")); assertFalse(beans.containsKey("java.lang:type=Runtime")); - adapterDefault.stop(); + adapterQueryNameBean.stop(); } @Test @@ -203,7 +203,7 @@ public class MBeanTreePollingChannelAdapterParserTests { assertFalse(beans.containsKey("java.lang:type=OperatingSystem")); assertTrue(beans.containsKey("java.lang:type=Runtime")); - adapterDefault.stop(); + adapterQueryExprBean.stop(); } @Test @@ -222,7 +222,7 @@ public class MBeanTreePollingChannelAdapterParserTests { assertTrue(beans.containsKey("java.lang:type=OperatingSystem")); assertTrue(beans.containsKey("java.lang:type=Runtime")); - adapterDefault.stop(); + adapterConverter.stop(); assertSame(converter, TestUtils.getPropertyValue(adapterConverter, "source.converter")); } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests.java index c9ace1652b..5f7fcb19d3 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests.java @@ -33,6 +33,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.integration.jmx.NotificationListeningMessageProducer; import org.springframework.integration.test.util.TestUtils; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -43,6 +44,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext public class NotificationListeningChannelAdapterParserTests { @Autowired diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PollingAdapterMBeanTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PollingAdapterMBeanTests.java index 535f8b12ec..c6224e0137 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PollingAdapterMBeanTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PollingAdapterMBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2017 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. You may obtain a copy of the License at @@ -23,6 +23,7 @@ import javax.management.ObjectName; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -32,6 +33,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext public class PollingAdapterMBeanTests { @Autowired diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PriorityChannelTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PriorityChannelTests.java index 429573dba8..8df5fa3788 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PriorityChannelTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PriorityChannelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2017 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. You may obtain a copy of the License at @@ -25,6 +25,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.channel.QueueChannelOperations; import org.springframework.messaging.PollableChannel; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -35,6 +36,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext public class PriorityChannelTests { @Autowired diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/RemoteMBeanServerTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/RemoteMBeanServerTests.java index 43086caa11..cd9c836d24 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/RemoteMBeanServerTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/RemoteMBeanServerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2017 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.monitor; import static org.junit.Assert.assertEquals; @@ -28,6 +29,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; @@ -45,6 +47,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext public class RemoteMBeanServerTests { @Autowired diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java b/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java index 7ce8d37637..690f3627ae 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2017 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. You may obtain a copy of the License at @@ -10,6 +10,7 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ + package org.springframework.integration_.mbeanexporterhelper; import static org.junit.Assert.assertEquals; @@ -85,7 +86,9 @@ public class Int2307Tests { assertTrue(TestUtils.getPropertyValue(mBeanExporterHelper, "siBeanNames", Set.class).contains("zz")); // make sure there are no duplicate MBean ObjectNames if 2 contexts loaded from same config - new ClassPathXmlApplicationContext("single-config.xml", this.getClass()); + new ClassPathXmlApplicationContext("single-config.xml", this.getClass()).close(); + + context.close(); } @SuppressWarnings("unchecked") @@ -110,7 +113,9 @@ public class Int2307Tests { } assertNotNull(mBeanExporterHelper); assertTrue(TestUtils.getPropertyValue(mBeanExporterHelper, "siBeanNames", Set.class).contains("z")); + context.close(); } public static class Foo{} + }