diff --git a/build.gradle b/build.gradle index 0333a63068..9b9fcfd755 100644 --- a/build.gradle +++ b/build.gradle @@ -166,16 +166,7 @@ subprojects { subproject -> // dependencies that are common across all java projects dependencies { - testCompile ("junit:junit:$junitVersion") { - exclude group: 'org.hamcrest' - } - testCompile "log4j:log4j:$log4jVersion" - testCompile "org.hamcrest:hamcrest-all:$hamcrestVersion" - testCompile ("org.mockito:mockito-core:$mockitoVersion") { - exclude group: 'org.hamcrest' - } - testCompile "org.springframework:spring-test:$springVersion" - if (!(subproject.name ==~ /.*-(core|test)/)) { + if (!(subproject.name ==~ /.*-test/)) { testCompile project(":spring-integration-test") } @@ -256,9 +247,8 @@ subprojects { subproject -> } project('spring-integration-test') { - description = 'Spring Integration Test Support' + description = 'Spring Integration Test Support - **No SI Dependencies Allowed**' dependencies { - compile project(":spring-integration-core") compile ("junit:junit:$junitVersion") { exclude group: 'org.hamcrest', module: 'hamcrest-core' } @@ -266,8 +256,10 @@ project('spring-integration-test') { compile ("org.mockito:mockito-core:$mockitoVersion") { exclude group: 'org.hamcrest', module: 'hamcrest-core' } + compile "org.springframework:spring-context:$springVersion" + compile "org.springframework:spring-messaging:$springVersion" compile "org.springframework:spring-test:$springVersion" - compile "log4j:log4j:$log4jVersion" // TEMPORARY - DO NOT RELEASE + compile ("log4j:log4j:$log4jVersion", optional) } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests.java index af20dce5d5..6a1681a26b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests.java @@ -103,7 +103,6 @@ import org.springframework.integration.scheduling.PollerMetadata; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.support.MutableMessageBuilder; import org.springframework.integration.support.SmartLifecycleRoleController; -import org.springframework.integration.test.util.LogAdjustingTestSupport; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; diff --git a/spring-integration-test/src/test/java/org/springframework/integration/test/mockito/ServiceActivatorOnMockitoMockTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorOnMockitoMockTests-context.xml similarity index 84% rename from spring-integration-test/src/test/java/org/springframework/integration/test/mockito/ServiceActivatorOnMockitoMockTests-context.xml rename to spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorOnMockitoMockTests-context.xml index c9bcc9353f..886e4d77b2 100644 --- a/spring-integration-test/src/test/java/org/springframework/integration/test/mockito/ServiceActivatorOnMockitoMockTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorOnMockitoMockTests-context.xml @@ -20,7 +20,7 @@ + value="org.springframework.integration.handler.ServiceActivatorOnMockitoMockTests.SingleAnnotatedMethodOnClass" /> @@ -31,7 +31,7 @@ + value="org.springframework.integration.handler.ServiceActivatorOnMockitoMockTests.SingleMethodOnClass" /> @@ -42,7 +42,7 @@ + value="org.springframework.integration.handler.ServiceActivatorOnMockitoMockTests.SingleMethodAcceptingHeaderOnClass" /> diff --git a/spring-integration-test/src/test/java/org/springframework/integration/test/mockito/ServiceActivatorOnMockitoMockTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorOnMockitoMockTests.java similarity index 93% rename from spring-integration-test/src/test/java/org/springframework/integration/test/mockito/ServiceActivatorOnMockitoMockTests.java rename to spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorOnMockitoMockTests.java index 0786cc1b37..9c38380b11 100644 --- a/spring-integration-test/src/test/java/org/springframework/integration/test/mockito/ServiceActivatorOnMockitoMockTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorOnMockitoMockTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.test.mockito; +package org.springframework.integration.handler; import static org.mockito.Mockito.verify; @@ -27,6 +27,7 @@ import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; +import org.springframework.messaging.handler.annotation.Header; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -79,10 +80,9 @@ public class ServiceActivatorOnMockitoMockTests { verify(singleMethodOnClass).move("SingleMethodOnClass"); } - @SuppressWarnings("deprecation") public static class SingleMethodAcceptingHeaderOnClass { - public String move(@org.springframework.integration.annotation.Header("s") String s) { + public String move(@Header("s") String s) { return s; } diff --git a/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/HeaderMatcherTests.java b/spring-integration-core/src/test/java/org/springframework/integration/message/HeaderMatcherTests.java similarity index 99% rename from spring-integration-test/src/test/java/org/springframework/integration/test/matcher/HeaderMatcherTests.java rename to spring-integration-core/src/test/java/org/springframework/integration/message/HeaderMatcherTests.java index e15d3d158b..ef0a1b66d1 100644 --- a/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/HeaderMatcherTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/message/HeaderMatcherTests.java @@ -14,15 +14,14 @@ * limitations under the License. */ -package org.springframework.integration.test.matcher; +package org.springframework.integration.message; -import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.any; +import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; - import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.springframework.integration.test.matcher.HeaderMatcher.hasAllHeaders; @@ -43,8 +42,9 @@ import java.util.UUID; import org.hamcrest.Matcher; import org.junit.Before; import org.junit.Test; -import org.springframework.messaging.Message; + import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; /** * @author Alex Peters diff --git a/spring-integration-core/src/test/java/org/springframework/integration/support/MessageScenariosTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/support/MessageScenariosTests-context.xml new file mode 100644 index 0000000000..bff885438d --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/integration/support/MessageScenariosTests-context.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/support/MessageScenariosTests.java b/spring-integration-core/src/test/java/org/springframework/integration/support/MessageScenariosTests.java new file mode 100644 index 0000000000..00db40a674 --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/integration/support/MessageScenariosTests.java @@ -0,0 +1,82 @@ +/* + * Copyright 2002-2015 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on 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.support; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.springframework.integration.test.matcher.HeaderMatcher.hasHeader; +import static org.springframework.integration.test.matcher.PayloadMatcher.hasPayload; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.integration.test.support.AbstractRequestResponseScenarioTests; +import org.springframework.integration.test.support.MessageValidator; +import org.springframework.integration.test.support.PayloadValidator; +import org.springframework.integration.test.support.RequestResponseScenario; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.MessageBuilder; +import org.springframework.test.context.ContextConfiguration; + +@ContextConfiguration +public class MessageScenariosTests extends AbstractRequestResponseScenarioTests { + + @Override + protected List defineRequestResponseScenarios() { + List scenarios= new ArrayList(); + RequestResponseScenario scenario1 = new RequestResponseScenario( + "inputChannel","outputChannel") + .setPayload("hello") + .setResponseValidator(new PayloadValidator() { + @Override + protected void validateResponse(String response) { + assertEquals("HELLO",response); + } + }); + + scenarios.add(scenario1); + + RequestResponseScenario scenario2 = new RequestResponseScenario( + "inputChannel","outputChannel") + .setMessage(MessageBuilder.withPayload("hello").setHeader("foo", "bar").build()) + .setResponseValidator(new MessageValidator() { + @Override + protected void validateMessage(Message message) { + assertThat(message,hasPayload("HELLO")); + assertThat(message,hasHeader("foo","bar")); + } + }); + + scenarios.add(scenario2); + + RequestResponseScenario scenario3 = new RequestResponseScenario( + "inputChannel2","outputChannel2") + .setMessage(MessageBuilder.withPayload("hello").setHeader("foo", "bar").build()) + .setResponseValidator(new MessageValidator() { + @Override + protected void validateMessage(Message message) { + assertThat(message,hasPayload("HELLO")); + assertThat(message,hasHeader("foo","bar")); + } + }); + + scenarios.add(scenario3); + + return scenarios; + } + +} diff --git a/spring-integration-test/src/test/java/org/springframework/integration/test/support/SingleScenarioTests.java b/spring-integration-core/src/test/java/org/springframework/integration/support/SingleScenarioTests.java similarity index 55% rename from spring-integration-test/src/test/java/org/springframework/integration/test/support/SingleScenarioTests.java rename to spring-integration-core/src/test/java/org/springframework/integration/support/SingleScenarioTests.java index 87c2000515..2bcf5ea6d8 100644 --- a/spring-integration-test/src/test/java/org/springframework/integration/test/support/SingleScenarioTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/support/SingleScenarioTests.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2015 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,29 +14,29 @@ * limitations under the License. */ -package org.springframework.integration.test.support; +package org.springframework.integration.support; import static org.junit.Assert.assertEquals; +import org.springframework.integration.test.support.PayloadValidator; +import org.springframework.integration.test.support.RequestResponseScenario; +import org.springframework.integration.test.support.SingleRequestResponseScenarioTests; import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration("MessageScenariosTests-context.xml") +@ContextConfiguration("MessageScenariosTests-context.xml") public class SingleScenarioTests extends SingleRequestResponseScenarioTests { - - /* (non-Javadoc) - * @see org.springframework.integration.test.support.SingleRequestResponseScenarioTest#defineRequestResponseScenario() - */ + @Override protected RequestResponseScenario defineRequestResponseScenario() { RequestResponseScenario scenario = new RequestResponseScenario( - "inputChannel","outputChannel") - .setPayload("hello") - .setResponseValidator(new PayloadValidator() { - @Override - protected void validateResponse(String response) { - assertEquals("HELLO",response); - } - }); + "inputChannel","outputChannel") + .setPayload("hello") + .setResponseValidator(new PayloadValidator() { + @Override + protected void validateResponse(String response) { + assertEquals("HELLO",response); + } + }); return scenario; } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/test/util/LogAdjustingTestSupport.java b/spring-integration-core/src/test/java/org/springframework/integration/test/util/LogAdjustingTestSupport.java deleted file mode 100644 index e5bca80d9d..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/test/util/LogAdjustingTestSupport.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2015 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on 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.test.util; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.log4j.Level; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.TestName; - -/** - * Base class for module tests where logging is set to TRACE for the duration - * of the test and reverted to the previous value. Also logs a start/end - * message. Duplicated from s-i-test to avoid circular dep. - * @author Artem Bilan - * @author Gary Russell - * @since 4.2.2 - * - */ -public class LogAdjustingTestSupport { - - @Rule - public TestName testName = new TestName(); - - protected final Log logger = LogFactory.getLog(this.getClass()); - - private final Collection loggersToAdjust = new ArrayList(); - - private final Collection oldCategories = new ArrayList(); - - - public LogAdjustingTestSupport() { - this("org.springframework.integration"); - } - - public LogAdjustingTestSupport(String... loggersToAdjust) { - for (String loggerToAdjust : loggersToAdjust) { - this.loggersToAdjust.add(LogManager.getLogger(loggerToAdjust)); - } - } - - @Before - public void beforeTest() { - for (Logger loggerToAdjust : this.loggersToAdjust) { - this.oldCategories.add(loggerToAdjust.getEffectiveLevel()); - loggerToAdjust.setLevel(Level.TRACE); - } - this.logger.debug("!!!! Starting test: " + this.testName.getMethodName() + " !!!!"); - } - - @After - public void afterTest() { - logger.debug("!!!! Finished test: " + this.testName.getMethodName() + " !!!!"); - Iterator oldCategory = this.oldCategories.iterator(); - for (Logger loggerToAdjust : this.loggersToAdjust) { - loggerToAdjust.setLevel(oldCategory.next()); - } - } - -} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/test/util/TestUtils.java b/spring-integration-core/src/test/java/org/springframework/integration/test/util/TestUtils.java deleted file mode 100644 index 00fb5d894e..0000000000 --- a/spring-integration-core/src/test/java/org/springframework/integration/test/util/TestUtils.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on 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.test.util; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.io.File; -import java.util.Properties; -import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy; - -import org.hamcrest.Matcher; - -import org.springframework.beans.DirectFieldAccessor; -import org.springframework.beans.FatalBeanException; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.beans.factory.BeanNameAware; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.context.support.GenericApplicationContext; -import org.springframework.integration.MessageRejectedException; -import org.springframework.integration.channel.MessagePublishingErrorHandler; -import org.springframework.integration.context.IntegrationContextUtils; -import org.springframework.integration.endpoint.AbstractEndpoint; -import org.springframework.integration.history.MessageHistory; -import org.springframework.integration.support.channel.BeanFactoryChannelResolver; -import org.springframework.integration.support.context.NamedComponent; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.MessageDeliveryException; -import org.springframework.messaging.MessageHandler; -import org.springframework.messaging.MessageHandlingException; -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; -import org.springframework.util.Assert; -import org.springframework.util.ErrorHandler; -import org.springframework.util.StringUtils; - -/** - * @author Mark Fisher - * @author Iwein Fuld - * @author Oleg Zhurakousky - * @author Artem Bilan - * @author Gary Russell - */ -public abstract class TestUtils { - - public static Object getPropertyValue(Object root, String propertyPath) { - Object value = null; - DirectFieldAccessor accessor = new DirectFieldAccessor(root); - String[] tokens = propertyPath.split("\\."); - for (int i = 0; i < tokens.length; i++) { - value = accessor.getPropertyValue(tokens[i]); - if (value != null) { - accessor = new DirectFieldAccessor(value); - } else if (i == tokens.length - 1) { - return null; - } else { - throw new IllegalArgumentException( - "intermediate property '" + tokens[i] + "' is null"); - } - } - return value; - } - - @SuppressWarnings("unchecked") - public static T getPropertyValue(Object root, String propertyPath, Class type) { - Object value = getPropertyValue(root, propertyPath); - if (value != null) { - Assert.isAssignable(type, value.getClass()); - } - return (T) value; - } - - public static TestApplicationContext createTestApplicationContext() { - TestApplicationContext context = new TestApplicationContext(); - ErrorHandler errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(context)); - ThreadPoolTaskScheduler scheduler = createTaskScheduler(10); - scheduler.setErrorHandler(errorHandler); - registerBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, scheduler, context); - return context; - } - - public static ThreadPoolTaskScheduler createTaskScheduler(int poolSize) { - ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); - scheduler.setPoolSize(poolSize); - scheduler.setRejectedExecutionHandler(new CallerRunsPolicy()); - scheduler.afterPropertiesSet(); - return scheduler; - } - - private static void registerBean(String beanName, Object bean, BeanFactory beanFactory) { - Assert.notNull(beanName, "bean name must not be null"); - ConfigurableListableBeanFactory configurableListableBeanFactory = null; - if (beanFactory instanceof ConfigurableListableBeanFactory) { - configurableListableBeanFactory = (ConfigurableListableBeanFactory) beanFactory; - } else if (beanFactory instanceof GenericApplicationContext) { - configurableListableBeanFactory = ((GenericApplicationContext) beanFactory).getBeanFactory(); - } - if (bean instanceof BeanNameAware) { - ((BeanNameAware) bean).setBeanName(beanName); - } - if (bean instanceof BeanFactoryAware) { - ((BeanFactoryAware) bean).setBeanFactory(beanFactory); - } - if (bean instanceof InitializingBean) { - try { - ((InitializingBean) bean).afterPropertiesSet(); - } - catch (Exception e) { - throw new FatalBeanException("failed to register bean with test context", e); - } - } - configurableListableBeanFactory.registerSingleton(beanName, bean); - } - - - public static class TestApplicationContext extends GenericApplicationContext { - - private TestApplicationContext() { - super(); - } - - public void registerChannel(String channelName, MessageChannel channel) { - if (channel instanceof NamedComponent && ((NamedComponent) channel).getComponentName() != null) { - if (channelName == null) { - channelName = ((NamedComponent) channel).getComponentName(); - } - else { - Assert.isTrue(((NamedComponent) channel).getComponentName().equals(channelName), - "channel name has already been set with a conflicting value"); - } - } - TestUtils.registerBean(channelName, channel, this); - } - - public void registerEndpoint(String endpointName, AbstractEndpoint endpoint) { - TestUtils.registerBean(endpointName, endpoint, this); - } - - public void registerBean(String beanName, Object bean) { - TestUtils.registerBean(beanName, bean, this); - } - } - - @SuppressWarnings("rawtypes") - public static MessageHandler handlerExpecting(final Matcher messageMatcher) { - return new MessageHandler() { - @Override - public void handleMessage(Message message) throws MessageRejectedException, MessageHandlingException, MessageDeliveryException { - assertThat(message, is(messageMatcher)); - } - }; - } - - /** - * @param history a message history - * @param componentName the name of a component to scan for - * @param startingIndex the index to start scanning - * @return the properties provided by the named component or null if none available - */ - public static Properties locateComponentInHistory(MessageHistory history, String componentName, int startingIndex){ - Assert.notNull(history, "'history' must not be null"); - Assert.isTrue(StringUtils.hasText(componentName), "'componentName' must be provided"); - Assert.isTrue(startingIndex < history.size(), "'startingIndex' can not be greater then size of history"); - Properties component = null; - for (int i = startingIndex; i < history.size(); i++) { - Properties properties = history.get(i); - if (componentName.equals(properties.get("name"))){ - component = properties; - break; - } - } - return component; - } - - /** - * Update file path by replacing any '/' with the system's file separator. - * @param s The file path containing '/'. - * @return The updated file path (if necessary). - */ - public static String applySystemFileSeparator(String s) { - return s.replaceAll("/", java.util.regex.Matcher.quoteReplacement(File.separator)); - } -} diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests.java index 84839646e9..b818d067d7 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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,25 +16,26 @@ package org.springframework.integration.file.config; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.messaging.Message; -import org.springframework.messaging.PollableChannel; -import org.springframework.integration.history.MessageHistory; -import org.springframework.integration.test.util.TestUtils; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.util.Properties; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.history.MessageHistory; +import org.springframework.integration.test.util.TestUtils; +import org.springframework.messaging.Message; +import org.springframework.messaging.PollableChannel; /** * @author Oleg Zhurakousky diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java index 18c1b87aa1..7b45adabae 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -42,9 +42,6 @@ import org.springframework.expression.Expression; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.PollableChannel; import org.springframework.integration.history.MessageHistory; import org.springframework.integration.http.AbstractHttpInboundTests; import org.springframework.integration.http.converter.SerializingHttpMessageConverter; @@ -52,6 +49,9 @@ import org.springframework.integration.http.inbound.HttpRequestHandlingControlle import org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway; import org.springframework.integration.http.support.DefaultHttpHeaderMapper; import org.springframework.integration.test.util.TestUtils; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.annotation.DirtiesContext; diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundGatewayParserTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundGatewayParserTests.java index 7d22f0ba00..159c85f4f2 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundGatewayParserTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundGatewayParserTests.java @@ -26,7 +26,6 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.springframework.integration.test.util.TestUtils.getPropertyValue; -import static org.springframework.integration.test.util.TestUtils.handlerExpecting; import java.util.ArrayList; import java.util.HashMap; @@ -35,6 +34,7 @@ import java.util.Map; import javax.servlet.http.HttpServletResponse; +import org.hamcrest.Matcher; import org.junit.Test; import org.junit.runner.RunWith; @@ -46,16 +46,20 @@ import org.springframework.expression.common.LiteralExpression; import org.springframework.expression.spel.standard.SpelExpression; import org.springframework.http.HttpHeaders; import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.integration.MessageRejectedException; +import org.springframework.integration.core.MessagingTemplate; import org.springframework.integration.http.converter.SerializingHttpMessageConverter; import org.springframework.integration.http.inbound.HttpRequestHandlingController; import org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway; import org.springframework.integration.http.support.DefaultHttpHeaderMapper; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; +import org.springframework.messaging.MessageDeliveryException; +import org.springframework.messaging.MessageHandler; +import org.springframework.messaging.MessageHandlingException; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.SubscribableChannel; -import org.springframework.integration.core.MessagingTemplate; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.annotation.DirtiesContext; @@ -259,6 +263,17 @@ public class HttpInboundGatewayParserTests { messageConverters.size() > 1); } + @SuppressWarnings("rawtypes") + private MessageHandler handlerExpecting(final Matcher messageMatcher) { + return new MessageHandler() { + @Override + public void handleMessage(Message message) throws MessageRejectedException, MessageHandlingException, MessageDeliveryException { + assertThat(message, is(messageMatcher)); + } + }; + } + + public static class Person { private String name; @@ -275,6 +290,7 @@ public class HttpInboundGatewayParserTests { public static class PersonConverter implements Converter { + @Override public String convert(Person source) { return source.getName(); } diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/SharedConnectionTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/SharedConnectionTests.java index e8bf90971a..eed6e067de 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/SharedConnectionTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/SharedConnectionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2015 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. @@ -28,12 +28,12 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.history.MessageHistory; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.test.util.TestUtils; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -44,22 +44,22 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) public class SharedConnectionTests { - + @Autowired AbstractApplicationContext ctx; - + @Autowired @Qualifier(value="inboundServer") TcpReceivingChannelAdapter listener; - + /** * Tests a loopback. The client-side outbound adapter sends a message over - * a connection from the client connection factory; the server side + * a connection from the client connection factory; the server side * receives the message, puts in on a channel which is the input channel - * for the outbound adapter that's sharing the connections. The response - * comes back to an inbound adapter that is sharing the client's + * for the outbound adapter that's sharing the connections. The response + * comes back to an inbound adapter that is sharing the client's * connection and we verify we get the echo back as expected. - * + * * @throws Exception */ @Test diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/UdpUnicastEndToEndTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/UdpUnicastEndToEndTests.java index 2ad7786b2f..9e4273d45f 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/UdpUnicastEndToEndTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/UdpUnicastEndToEndTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. 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 aa502f8007..a405848ebf 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java b/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java index 0c298fa4a5..374a917b46 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java @@ -54,8 +54,6 @@ import javax.mail.search.FlagTerm; import javax.mail.search.FromTerm; import javax.mail.search.SearchTerm; -import com.sun.mail.imap.IMAPFolder; -import com.sun.mail.imap.IMAPMessage; import org.apache.commons.logging.Log; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -89,6 +87,9 @@ import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.util.FileCopyUtils; +import com.sun.mail.imap.IMAPFolder; +import com.sun.mail.imap.IMAPMessage; + /** * @author Oleg Zhurakousky * @author Gary Russell diff --git a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/outbound/StompMessageHandlerWebSocketIntegrationTests.java b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/outbound/StompMessageHandlerWebSocketIntegrationTests.java index ff36b1ce79..c319f5f99b 100644 --- a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/outbound/StompMessageHandlerWebSocketIntegrationTests.java +++ b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/outbound/StompMessageHandlerWebSocketIntegrationTests.java @@ -57,7 +57,6 @@ import org.springframework.integration.stomp.event.StompReceiptEvent; import org.springframework.integration.stomp.event.StompSessionConnectedEvent; import org.springframework.integration.test.support.LogAdjustingTestSupport; import org.springframework.integration.test.support.LongRunningIntegrationTest; -import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.websocket.TomcatWebSocketTestServer; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; diff --git a/spring-integration-test/src/main/java/org/springframework/integration/test/matcher/EqualsResultMatcher.java b/spring-integration-test/src/main/java/org/springframework/integration/test/matcher/EqualsResultMatcher.java index b02c66c3de..8f3070c358 100644 --- a/spring-integration-test/src/main/java/org/springframework/integration/test/matcher/EqualsResultMatcher.java +++ b/spring-integration-test/src/main/java/org/springframework/integration/test/matcher/EqualsResultMatcher.java @@ -26,7 +26,7 @@ import org.springframework.util.ObjectUtils; * wrapped by the {@link EqualsResultMatcher.Evaluator} * * The goal is to defer the computation until the matcher needs to be actually evaluated. - * Mainly useful in conjunction with retrying matcherss such as {@link EventuallyMatcher} + * Mainly useful in conjunction with retrying matchers such as {@link EventuallyMatcher} * * @author Marius Bogoevici * @since 4.2 diff --git a/spring-integration-test/src/main/java/org/springframework/integration/test/matcher/HeaderMatcher.java b/spring-integration-test/src/main/java/org/springframework/integration/test/matcher/HeaderMatcher.java index 372ba2bf10..1298bd9a4f 100644 --- a/spring-integration-test/src/main/java/org/springframework/integration/test/matcher/HeaderMatcher.java +++ b/spring-integration-test/src/main/java/org/springframework/integration/test/matcher/HeaderMatcher.java @@ -25,7 +25,6 @@ import org.hamcrest.Factory; import org.hamcrest.Matcher; import org.junit.Assert; -import org.springframework.integration.IntegrationMessageHeaderAccessor; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; @@ -125,7 +124,7 @@ public class HeaderMatcher extends TypeSafeMatcher> { @Factory public static Matcher> hasCorrelationId(T value) { - return new HeaderMatcher(MapContentMatchers.hasEntry(IntegrationMessageHeaderAccessor.CORRELATION_ID, value)); + return new HeaderMatcher(MapContentMatchers.hasEntry("correlationId", value)); } @Factory @@ -135,7 +134,7 @@ public class HeaderMatcher extends TypeSafeMatcher> { @Factory public static Matcher> hasSequenceNumber(Matcher matcher) { - return new HeaderMatcher(MapContentMatchers.hasEntry(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, matcher)); + return new HeaderMatcher(MapContentMatchers.hasEntry("sequenceNumber", matcher)); } @Factory @@ -145,7 +144,7 @@ public class HeaderMatcher extends TypeSafeMatcher> { @Factory public static Matcher> hasSequenceSize(Matcher value) { - return new HeaderMatcher(MapContentMatchers.hasEntry(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, value)); + return new HeaderMatcher(MapContentMatchers.hasEntry("sequenceSize", value)); } @Factory @@ -155,7 +154,7 @@ public class HeaderMatcher extends TypeSafeMatcher> { @Factory public static Matcher> hasExpirationDate(Matcher matcher) { - return new HeaderMatcher(MapContentMatchers.hasEntry(IntegrationMessageHeaderAccessor.EXPIRATION_DATE, matcher)); + return new HeaderMatcher(MapContentMatchers.hasEntry("expirationDate", matcher)); } @Factory diff --git a/spring-integration-test/src/main/java/org/springframework/integration/test/util/TestUtils.java b/spring-integration-test/src/main/java/org/springframework/integration/test/util/TestUtils.java index abdf763c37..61695fe440 100644 --- a/spring-integration-test/src/main/java/org/springframework/integration/test/util/TestUtils.java +++ b/spring-integration-test/src/main/java/org/springframework/integration/test/util/TestUtils.java @@ -16,14 +16,17 @@ package org.springframework.integration.test.util; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; import java.util.Properties; +import java.util.Set; import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy; +import java.util.concurrent.atomic.AtomicReference; -import org.hamcrest.Matcher; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.FatalBeanException; @@ -33,21 +36,17 @@ import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.support.GenericApplicationContext; -import org.springframework.integration.MessageRejectedException; -import org.springframework.integration.channel.MessagePublishingErrorHandler; -import org.springframework.integration.context.IntegrationContextUtils; -import org.springframework.integration.endpoint.AbstractEndpoint; -import org.springframework.integration.history.MessageHistory; -import org.springframework.integration.support.channel.BeanFactoryChannelResolver; -import org.springframework.integration.support.context.NamedComponent; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.MessageDeliveryException; -import org.springframework.messaging.MessageHandler; -import org.springframework.messaging.MessageHandlingException; +import org.springframework.messaging.MessagingException; +import org.springframework.messaging.support.ErrorMessage; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; import org.springframework.util.ErrorHandler; +import org.springframework.util.ReflectionUtils; +import org.springframework.util.ReflectionUtils.MethodCallback; +import org.springframework.util.ReflectionUtils.MethodFilter; import org.springframework.util.StringUtils; /** @@ -55,6 +54,7 @@ import org.springframework.util.StringUtils; * @author Iwein Fuld * @author Oleg Zhurakousky * @author Artem Bilan + * @author Gary Russell */ public abstract class TestUtils { @@ -87,10 +87,10 @@ public abstract class TestUtils { public static TestApplicationContext createTestApplicationContext() { TestApplicationContext context = new TestApplicationContext(); - ErrorHandler errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(context)); + ErrorHandler errorHandler = new MessagePublishingErrorHandler(context); ThreadPoolTaskScheduler scheduler = createTaskScheduler(10); scheduler.setErrorHandler(errorHandler); - registerBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, scheduler, context); + registerBean("taskScheduler", scheduler, context); return context; } @@ -135,32 +135,59 @@ public abstract class TestUtils { super(); } - public void registerChannel(String channelName, MessageChannel channel) { - if (channel instanceof NamedComponent && ((NamedComponent) channel).getComponentName() != null) { + public void registerChannel(String channelName, final MessageChannel channel) { + String componentName = getComponentNameIfNamed(channel); + if (componentName != null) { if (channelName == null) { - channelName = ((NamedComponent) channel).getComponentName(); + channelName = componentName; } else { - Assert.isTrue(((NamedComponent) channel).getComponentName().equals(channelName), + Assert.isTrue(componentName.equals(channelName), "channel name has already been set with a conflicting value"); } } - registerBean(channelName, channel, this); + TestUtils.registerBean(channelName, channel, this); } - public void registerEndpoint(String endpointName, AbstractEndpoint endpoint) { - registerBean(endpointName, endpoint, this); - } - } + private String getComponentNameIfNamed(final MessageChannel channel) { + Set> interfaces = ClassUtils.getAllInterfacesAsSet(channel); + final AtomicReference componentName = new AtomicReference(); + for (Class intface : interfaces) { + if ("org.springframework.integration.support.context.NamedComponent".equals(intface.getName())) { + ReflectionUtils.doWithMethods(channel.getClass(), new MethodCallback() { - @SuppressWarnings("rawtypes") - public static MessageHandler handlerExpecting(final Matcher messageMatcher) { - return new MessageHandler() { - @Override - public void handleMessage(Message message) throws MessageRejectedException, MessageHandlingException, MessageDeliveryException { - assertThat(message, is(messageMatcher)); + @Override + public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { + try { + componentName.set((String) method.invoke(channel, new Object[0])); + } + catch (InvocationTargetException e) { + throw new IllegalArgumentException(e); + } + } + + }, new MethodFilter() { + + @Override + public boolean matches(Method method) { + return method.getName().equals("getComponentName"); + } + + }); + break; + } } - }; + return componentName.get(); + } + + public void registerEndpoint(String endpointName, Object endpoint) { + TestUtils.registerBean(endpointName, endpoint, this); + } + + public void registerBean(String beanName, Object bean) { + TestUtils.registerBean(beanName, bean, this); + } + } /** @@ -169,7 +196,7 @@ public abstract class TestUtils { * @param startingIndex the index to start scanning * @return the properties provided by the named component or null if none available */ - public static Properties locateComponentInHistory(MessageHistory history, String componentName, int startingIndex){ + public static Properties locateComponentInHistory(List history, String componentName, int startingIndex) { Assert.notNull(history, "'history' must not be null"); Assert.isTrue(StringUtils.hasText(componentName), "'componentName' must be provided"); Assert.isTrue(startingIndex < history.size(), "'startingIndex' can not be greater then size of history"); @@ -192,4 +219,60 @@ public abstract class TestUtils { public static String applySystemFileSeparator(String s) { return s.replaceAll("/", java.util.regex.Matcher.quoteReplacement(File.separator)); } + + private static class MessagePublishingErrorHandler implements ErrorHandler { + + private final Log logger = LogFactory.getLog(this.getClass()); + + private final TestApplicationContext context; + + private MessagePublishingErrorHandler(TestApplicationContext ctx) { + this.context = ctx; + } + + @Override + public void handleError(Throwable t) { + MessageChannel errorChannel = this.resolveErrorChannel(t); + boolean sent = false; + if (errorChannel != null) { + try { + sent = errorChannel.send(new ErrorMessage(t), 10000); + } + catch (Throwable errorDeliveryError) {//NOSONAR + // message will be logged only + if (logger.isWarnEnabled()) { + logger.warn("Error message was not delivered.", errorDeliveryError); + } + if (errorDeliveryError instanceof Error) { + throw ((Error) errorDeliveryError); + } + } + } + if (!sent && logger.isErrorEnabled()) { + Message failedMessage = (t instanceof MessagingException) ? + ((MessagingException) t).getFailedMessage() : null; + if (failedMessage != null) { + logger.error("failure occurred in messaging task with message: " + failedMessage, t); + } + else { + logger.error("failure occurred in messaging task", t); + } + } + + } + + private MessageChannel resolveErrorChannel(Throwable t) { + Message failedMessage = (t instanceof MessagingException) ? + ((MessagingException) t).getFailedMessage() : null; + Object errorChannelHeader = failedMessage.getHeaders().getErrorChannel(); + if (errorChannelHeader instanceof MessageChannel) { + return (MessageChannel) errorChannelHeader; + } + Assert.isInstanceOf(String.class, errorChannelHeader, + "Unsupported error channel header type. Expected MessageChannel or String, but actual type is [" + + errorChannelHeader.getClass() + "]"); + return this.context.getBean((String) errorChannelHeader, MessageChannel.class); + } + + } } diff --git a/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/MockitoMessageMatchersTests.java b/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/MockitoMessageMatchersTests.java index 450af43431..f6d034292e 100644 --- a/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/MockitoMessageMatchersTests.java +++ b/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/MockitoMessageMatchersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -15,21 +15,8 @@ */ package org.springframework.integration.test.matcher; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.exceptions.verification.junit.ArgumentsAreDifferent; -import org.mockito.runners.MockitoJUnitRunner; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.MessageHandler; -import org.springframework.integration.support.MessageBuilder; - -import java.util.Date; - -import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.verify; @@ -37,6 +24,20 @@ import static org.mockito.Mockito.when; import static org.springframework.integration.test.matcher.MockitoMessageMatchers.messageWithHeaderEntry; import static org.springframework.integration.test.matcher.MockitoMessageMatchers.messageWithPayload; +import java.util.Date; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.exceptions.verification.junit.ArgumentsAreDifferent; +import org.mockito.runners.MockitoJUnitRunner; + +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.MessageHandler; +import org.springframework.messaging.support.MessageBuilder; + /** * @author Alex Peters * @author Iwein Fuld diff --git a/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/PayloadMatcherTests.java b/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/PayloadMatcherTests.java index 00b1547ea1..6574e842b0 100644 --- a/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/PayloadMatcherTests.java +++ b/spring-integration-test/src/test/java/org/springframework/integration/test/matcher/PayloadMatcherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -15,8 +15,8 @@ */ package org.springframework.integration.test.matcher; -import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.notNullValue; import static org.junit.Assert.assertThat; @@ -26,8 +26,9 @@ import static org.springframework.integration.test.matcher.PayloadMatcher.hasPay import java.math.BigDecimal; import org.junit.Test; + import org.springframework.messaging.Message; -import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.support.MessageBuilder; /** * @author Alex Peters diff --git a/spring-integration-test/src/test/java/org/springframework/integration/test/support/MessageScenariosTests-context.xml b/spring-integration-test/src/test/java/org/springframework/integration/test/support/MessageScenariosTests-context.xml deleted file mode 100644 index 352bd1a987..0000000000 --- a/spring-integration-test/src/test/java/org/springframework/integration/test/support/MessageScenariosTests-context.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-integration-test/src/test/java/org/springframework/integration/test/support/MessageScenariosTests.java b/spring-integration-test/src/test/java/org/springframework/integration/test/support/MessageScenariosTests.java deleted file mode 100644 index 98cb5428d3..0000000000 --- a/spring-integration-test/src/test/java/org/springframework/integration/test/support/MessageScenariosTests.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2002-2011 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on 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.test.support; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.springframework.integration.test.matcher.HeaderMatcher.hasHeader; -import static org.springframework.integration.test.matcher.PayloadMatcher.hasPayload; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.integration.support.MessageBuilder; -import org.springframework.messaging.Message; -import org.springframework.test.context.ContextConfiguration; - -@ContextConfiguration -public class MessageScenariosTests extends AbstractRequestResponseScenarioTests { - - @Override - protected List defineRequestResponseScenarios() { - List scenarios= new ArrayList(); - RequestResponseScenario scenario1 = new RequestResponseScenario( - "inputChannel","outputChannel") - .setPayload("hello") - .setResponseValidator(new PayloadValidator() { - @Override - protected void validateResponse(String response) { - assertEquals("HELLO",response); - } - }); - - scenarios.add(scenario1); - - RequestResponseScenario scenario2 = new RequestResponseScenario( - "inputChannel","outputChannel") - .setMessage(MessageBuilder.withPayload("hello").setHeader("foo", "bar").build()) - .setResponseValidator(new MessageValidator() { - @Override - protected void validateMessage(Message message) { - assertThat(message,hasPayload("HELLO")); - assertThat(message,hasHeader("foo","bar")); - } - }); - - scenarios.add(scenario2); - - RequestResponseScenario scenario3 = new RequestResponseScenario( - "inputChannel2","outputChannel2") - .setMessage(MessageBuilder.withPayload("hello").setHeader("foo", "bar").build()) - .setResponseValidator(new MessageValidator() { - @Override - protected void validateMessage(Message message) { - assertThat(message,hasPayload("HELLO")); - assertThat(message,hasHeader("foo","bar")); - } - }); - - scenarios.add(scenario3); - - return scenarios; - } -} diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests.java index 70dad46e9e..bc51764e54 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests.java @@ -16,6 +16,15 @@ package org.springframework.integration.ws.config; +import static org.hamcrest.CoreMatchers.is; +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.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import java.util.Collections; import java.util.Map; import java.util.Properties; @@ -29,16 +38,16 @@ import org.mockito.Mockito; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.integration.mapping.AbstractHeaderMapper; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.MessageHeaders; -import org.springframework.messaging.PollableChannel; import org.springframework.integration.history.MessageHistory; +import org.springframework.integration.mapping.AbstractHeaderMapper; import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.ws.MarshallingWebServiceInboundGateway; import org.springframework.integration.ws.SimpleWebServiceInboundGateway; import org.springframework.integration.ws.SoapHeaderMapper; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.MessageHeaders; +import org.springframework.messaging.PollableChannel; import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.support.AbstractMarshaller; import org.springframework.test.annotation.DirtiesContext; @@ -49,15 +58,6 @@ import org.springframework.ws.context.DefaultMessageContext; import org.springframework.ws.context.MessageContext; import org.springframework.ws.soap.SoapMessage; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - /** * @author Iwein Fuld * @author Oleg Zhurakousky @@ -210,17 +210,21 @@ public class WebServiceInboundGatewayParserTests { @SuppressWarnings("unused") private static class TestHeaderMapper implements SoapHeaderMapper { + @Override public void fromHeadersToRequest(MessageHeaders headers, SoapMessage target) { } + @Override public void fromHeadersToReply(MessageHeaders headers, SoapMessage target) { } + @Override public Map toHeadersFromRequest(SoapMessage source) { return Collections.emptyMap(); } + @Override public Map toHeadersFromReply(SoapMessage source) { return Collections.emptyMap(); } diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltTransformerTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltTransformerTests.java index 2277de64ca..da09904d69 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltTransformerTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltTransformerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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,9 +16,9 @@ package org.springframework.integration.xml.transformer; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; import java.io.IOException; import java.util.Properties; @@ -48,7 +48,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) public class XsltTransformerTests { - private String docAsString = "test"; + private final String docAsString = "test"; @Autowired private ApplicationContext applicationContext; @Autowired