From 705be107cabcb459224f9380cb545cca61d72ab1 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 11 Aug 2014 11:19:02 +0300 Subject: [PATCH] INT-3470: Fix SF 4.1 Compatibility JIRA: https://jira.spring.io/browse/INT-3470 According to the commit https://github.com/spring-projects/spring-framework/commit/c06ac06, the `MessagingException` is now `NestedRuntimeException` including nested StackTrace. Hence test-cases have to be changed to the `Mathers.containsString` instead of `equals` for the `e.getMessage()` **Cherry-pick to the 4.0.x** Conflicts: spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/DispatcherHasNoSubscribersTests.java spring-integration-core/src/test/java/org/springframework/integration/handler/advice/AdvisedMessageHandlerTests.java --- .../DispatcherHasNoSubscribersTests.java | 18 ++++++++----- .../DispatcherHasNoSubscribersTests.java | 26 +++++++++++++------ .../registry/HeaderChannelRegistryTests.java | 8 +++--- .../advice/AdvisedMessageHandlerTests.java | 3 +++ .../transformer/ContentEnricherTests.java | 4 ++- .../jms/SubscribableJmsChannelTests.java | 5 +++- .../AbstractMongoDbMessageStoreTests.java | 13 +++++++--- .../SubscribableRedisChannelTests.java | 7 ++--- .../integration/rmi/BackToBackTests.java | 8 ++++-- 9 files changed, 65 insertions(+), 27 deletions(-) diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/DispatcherHasNoSubscribersTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/DispatcherHasNoSubscribersTests.java index b01290c3f7..dab27c29c2 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/DispatcherHasNoSubscribersTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/DispatcherHasNoSubscribersTests.java @@ -15,8 +15,9 @@ */ package org.springframework.integration.amqp.channel; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; @@ -71,7 +72,8 @@ public class DispatcherHasNoSubscribersTests { @Override public Channel answer(InvocationOnMock invocation) throws Throwable { return channel; - }}).when(connection).createChannel(anyBoolean()); + } + }).when(connection).createChannel(anyBoolean()); ConnectionFactory connectionFactory = mock(ConnectionFactory.class); when(connectionFactory.createConnection()).thenReturn(connection); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); @@ -90,7 +92,8 @@ public class DispatcherHasNoSubscribersTests { fail("Exception expected"); } catch (MessageDeliveryException e) { - assertEquals("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'.", e.getMessage()); + assertThat(e.getMessage(), + containsString("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'.")); } } @@ -102,7 +105,8 @@ public class DispatcherHasNoSubscribersTests { @Override public Channel answer(InvocationOnMock invocation) throws Throwable { return channel; - }}).when(connection).createChannel(anyBoolean()); + } + }).when(connection).createChannel(anyBoolean()); ConnectionFactory connectionFactory = mock(ConnectionFactory.class); when(connectionFactory.createConnection()).thenReturn(connection); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); @@ -141,7 +145,8 @@ public class DispatcherHasNoSubscribersTests { logList.add(message); } return null; - }}).when(logger).warn(anyString(), any(Exception.class)); + } + }).when(logger).warn(anyString(), any(Exception.class)); when(logger.isWarnEnabled()).thenReturn(true); Object listener = container.getMessageListener(); DirectFieldAccessor dfa = new DirectFieldAccessor(listener); @@ -157,7 +162,8 @@ public class DispatcherHasNoSubscribersTests { assertNotNull("Failed to get expected exception", message); if (message.startsWith("Dispatcher has no subscribers")) { expectedExceptionFound = true; - assertEquals("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'.", message); + assertThat(message, + containsString("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'.")); break; } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/DispatcherHasNoSubscribersTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/DispatcherHasNoSubscribersTests.java index 84556c7aef..73fe15d375 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/DispatcherHasNoSubscribersTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/DispatcherHasNoSubscribersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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,14 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.channel; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.messaging.MessageChannel; @@ -31,6 +34,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Gary Russell + * @author Artem Bilan * @since 2.1 * */ @@ -57,8 +61,10 @@ public class DispatcherHasNoSubscribersTests { try { noSubscribersChannel.send(new GenericMessage("Hello, world!")); fail("Exception expected"); - } catch (MessagingException e) { - assertEquals("Dispatcher has no subscribers for channel 'foo.noSubscribersChannel'.", e.getMessage()); + } + catch (MessagingException e) { + assertThat(e.getMessage(), + containsString("Dispatcher has no subscribers for channel 'foo.noSubscribersChannel'.")); } } @@ -67,8 +73,10 @@ public class DispatcherHasNoSubscribersTests { try { subscribedChannel.send(new GenericMessage("Hello, world!")); fail("Exception expected"); - } catch (MessagingException e) { - assertEquals("Dispatcher has no subscribers for channel 'foo.noSubscribersChannel'.", e.getMessage()); + } + catch (MessagingException e) { + assertThat(e.getMessage(), + containsString("Dispatcher has no subscribers for channel 'foo.noSubscribersChannel'.")); } } @@ -79,8 +87,10 @@ public class DispatcherHasNoSubscribersTests { try { channel.send(new GenericMessage("Hello, world!")); fail("Exception expected"); - } catch (MessagingException e) { - assertEquals("Dispatcher has no subscribers for channel 'bar'.", e.getMessage()); + } + catch (MessagingException e) { + assertThat(e.getMessage(), + containsString("Dispatcher has no subscribers for channel 'bar'.")); } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/registry/HeaderChannelRegistryTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/registry/HeaderChannelRegistryTests.java index 9a3d1511a9..350ba12fae 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/registry/HeaderChannelRegistryTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/registry/HeaderChannelRegistryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2014 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.channel.registry; import static org.hamcrest.Matchers.instanceOf; @@ -179,7 +180,7 @@ public class HeaderChannelRegistryTests { } catch (DestinationResolutionException e){ assertThat(e.getMessage(), - Matchers.equalTo("failed to look up MessageChannel with name 'foo' in the BeanFactory.")); + Matchers.containsString("failed to look up MessageChannel with name 'foo' in the BeanFactory.")); } } @@ -201,7 +202,8 @@ public class HeaderChannelRegistryTests { } catch (DestinationResolutionException e){ assertThat(e.getMessage(), - Matchers.equalTo("failed to look up MessageChannel with name 'foo' in the BeanFactory (and there is no HeaderChannelRegistry present).")); + Matchers.containsString("failed to look up MessageChannel with name 'foo' in the BeanFactory " + + "(and there is no HeaderChannelRegistry present).")); } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/AdvisedMessageHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/AdvisedMessageHandlerTests.java index 1e5894a694..0e89571f9b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/AdvisedMessageHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/AdvisedMessageHandlerTests.java @@ -13,8 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.handler.advice; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.endsWith; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/transformer/ContentEnricherTests.java b/spring-integration-core/src/test/java/org/springframework/integration/transformer/ContentEnricherTests.java index 6793924edd..7a387e8934 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/transformer/ContentEnricherTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/transformer/ContentEnricherTests.java @@ -16,10 +16,12 @@ package org.springframework.integration.transformer; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; @@ -414,7 +416,7 @@ public class ContentEnricherTests { try { enricher.handleMessage(requestMessage); } catch (MessageHandlingException e) { - assertEquals("Failed to clone payload object", e.getMessage()); + assertThat(e.getMessage(), containsString("Failed to clone payload object")); return; } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/SubscribableJmsChannelTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/SubscribableJmsChannelTests.java index 3fc26e69aa..af8fa5d812 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/SubscribableJmsChannelTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/SubscribableJmsChannelTests.java @@ -16,9 +16,11 @@ package org.springframework.integration.jms; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; @@ -307,7 +309,8 @@ public class SubscribableJmsChannelTests { fail("Exception expected"); } catch (MessageDeliveryException e) { - assertEquals("Dispatcher has no subscribers for jms-channel 'noSubscribersChannel'.", e.getMessage()); + assertThat(e.getMessage(), + containsString("Dispatcher has no subscribers for jms-channel 'noSubscribersChannel'.")); } } diff --git a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/AbstractMongoDbMessageStoreTests.java b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/AbstractMongoDbMessageStoreTests.java index 1ea390cbd1..163c3f1936 100644 --- a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/AbstractMongoDbMessageStoreTests.java +++ b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/AbstractMongoDbMessageStoreTests.java @@ -15,13 +15,17 @@ */ package org.springframework.integration.mongodb.store; -import static org.junit.Assert.*; +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import java.io.Serializable; import java.util.Properties; import java.util.UUID; -import com.mongodb.MongoClient; import org.hamcrest.Matchers; import org.junit.Test; @@ -39,6 +43,8 @@ import org.springframework.messaging.MessagingException; import org.springframework.messaging.support.ErrorMessage; import org.springframework.messaging.support.GenericMessage; +import com.mongodb.MongoClient; + /** * * @author Mark Fisher @@ -249,7 +255,8 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT assertNotNull(retrievedMessage); assertTrue(retrievedMessage instanceof ErrorMessage); assertThat(retrievedMessage.getPayload(), Matchers.instanceOf(MessagingException.class)); - assertEquals("intentional MessagingException", ((MessagingException) retrievedMessage.getPayload()).getMessage()); + assertThat(((MessagingException) retrievedMessage.getPayload()).getMessage(), + containsString("intentional MessagingException")); assertEquals(failedMessage, ((MessagingException) retrievedMessage.getPayload()).getFailedMessage()); assertEquals(messageToStore.getHeaders(), retrievedMessage.getHeaders()); } diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/channel/SubscribableRedisChannelTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/channel/SubscribableRedisChannelTests.java index c29a1277be..f14c7cd67d 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/channel/SubscribableRedisChannelTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/channel/SubscribableRedisChannelTests.java @@ -15,8 +15,9 @@ */ package org.springframework.integration.redis.channel; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; @@ -104,8 +105,8 @@ public class SubscribableRedisChannelTests extends RedisAvailableTests { catch (InvocationTargetException e) { Throwable cause = e.getCause(); assertNotNull(cause); - assertEquals("Dispatcher has no subscribers for redis-channel 'si.test.channel.no.subs' (dhnsChannel).", - cause.getMessage()); + assertThat(cause.getMessage(), + containsString("Dispatcher has no subscribers for redis-channel 'si.test.channel.no.subs' (dhnsChannel).")); } } diff --git a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/BackToBackTests.java b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/BackToBackTests.java index d98d05b87e..d5c513b8b1 100644 --- a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/BackToBackTests.java +++ b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/BackToBackTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2014 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,10 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.rmi; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import org.junit.Test; @@ -78,7 +81,8 @@ public class BackToBackTests { fail("Expected exception"); } catch (Exception e) { - assertEquals("Dispatcher has no subscribers for channel 'context.baz'.", e.getCause().getMessage()); + assertThat(e.getCause().getMessage(), + containsString("Dispatcher has no subscribers for channel 'context.baz'.")); } }