From 6e0b730e63a7dee70df1e933cbab1c2f9adf6993 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 21 Jan 2016 10:33:23 -0500 Subject: [PATCH] Fix failing tests --- .../GatewayInvokingMessageHandlerTests.java | 40 ++++++++++--------- .../splitter/SplitterIntegrationTests.java | 5 ++- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessageHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessageHandlerTests.java index 7355c60d18..725d69e206 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessageHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessageHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 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. @@ -16,8 +16,6 @@ package org.springframework.integration.gateway; -import junit.framework.Assert; - import org.junit.Test; import org.junit.runner.RunWith; @@ -29,29 +27,33 @@ import org.springframework.integration.core.MessageHandler; import org.springframework.integration.core.SubscribableChannel; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.support.MessageBuilder; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import junit.framework.Assert; + /** * @author Oleg Zhurakousky * @since 2.0 */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext(classMode= DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class GatewayInvokingMessageHandlerTests { @Autowired @Qualifier("inputA") SubscribableChannel channel; - + @Autowired @Qualifier("simpleGateway") SimpleGateway gateway; - + @Autowired @Qualifier("gatewayWithError") SimpleGateway gatewayWithError; - + @Autowired @Qualifier("gatewayWithErrorAsync") SimpleGateway gatewayWithErrorAsync; @@ -77,7 +79,7 @@ public class GatewayInvokingMessageHandlerTests { } @Test - public void validateGatewayInTheChainViaAnotherGateway() { + public void validateGatewayInTheChainViaAnotherGateway() { output.subscribe(new MessageHandler() { public void handleMessage(Message message) { Assert.assertEquals("echo:echo:echo:hello", message.getPayload()); @@ -88,9 +90,9 @@ public class GatewayInvokingMessageHandlerTests { String result = gateway.process("hello"); Assert.assertEquals("echo:echo:echo:hello", result); } - + @Test - public void validateGatewayWithErrorMessageReturned() { + public void validateGatewayWithErrorMessageReturned() { try { String result = gatewayWithErrorChannelAndTransformer.process("echoWithRuntimeExceptionChannel"); Assert.assertNotNull(result); @@ -99,7 +101,7 @@ public class GatewayInvokingMessageHandlerTests { catch (Exception e) { Assert.fail(); } - + try { gatewayWithError.process("echoWithRuntimeExceptionChannel"); Assert.fail(); @@ -107,7 +109,7 @@ public class GatewayInvokingMessageHandlerTests { catch (SampleRuntimeException e) { Assert.assertEquals("echoWithRuntimeExceptionChannel", e.getMessage()); } - + try { gatewayWithError.process("echoWithMessagingExceptionChannel"); Assert.fail(); @@ -115,7 +117,7 @@ public class GatewayInvokingMessageHandlerTests { catch (MessageHandlingException e) { Assert.assertEquals("echoWithMessagingExceptionChannel", e.getFailedMessage().getPayload()); } - + try { String result = gatewayWithErrorChannelAndTransformer.process("echoWithMessagingExceptionChannel"); Assert.assertNotNull(result); @@ -125,9 +127,9 @@ public class GatewayInvokingMessageHandlerTests { Assert.fail(); } } - + @Test - public void validateGatewayWithErrorAsync() { + public void validateGatewayWithErrorAsync() { try { gatewayWithErrorAsync.process("echoWithErrorAsyncChannel"); Assert.fail(); @@ -136,9 +138,9 @@ public class GatewayInvokingMessageHandlerTests { Assert.assertEquals(SampleRuntimeException.class, e.getClass()); } } - + @Test - public void validateGatewayWithErrorFlowReturningMessage() { + public void validateGatewayWithErrorFlowReturningMessage() { try { Object result = gatewayWithErrorChannelAndTransformer.process("echoWithErrorAsyncChannel"); Assert.assertEquals("Error happened in message: echoWithErrorAsyncChannel", result); @@ -151,10 +153,10 @@ public class GatewayInvokingMessageHandlerTests { public static class SampleErrorTransformer { public Message toMessage(Throwable object) throws Exception { - MessageHandlingException ex = (MessageHandlingException) object; + MessageHandlingException ex = (MessageHandlingException) object; return MessageBuilder.withPayload("Error happened in message: " + ex.getFailedMessage().getPayload()).build(); } - + } @@ -195,7 +197,7 @@ public class GatewayInvokingMessageHandlerTests { public static class SampleRuntimeException extends RuntimeException { public SampleRuntimeException(String message) { super(message); - } + } } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/splitter/SplitterIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/splitter/SplitterIntegrationTests.java index 4cbcc33a14..80f910f61e 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/splitter/SplitterIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/splitter/SplitterIntegrationTests.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. @@ -29,6 +29,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; @@ -37,6 +38,7 @@ import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.annotation.Splitter; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.support.MessageBuilder; +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; */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext(classMode= DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class SplitterIntegrationTests { @Autowired