More File Cleanup - Core

This commit is contained in:
Gary Russell
2016-06-05 10:12:18 -04:00
parent 90e5457260
commit c54d95b1aa
47 changed files with 277 additions and 165 deletions

View File

@@ -22,10 +22,10 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessagingException;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.messaging.support.ErrorMessage;
import org.springframework.retry.RecoveryCallback;
import org.springframework.retry.RetryContext;
@@ -46,8 +46,6 @@ public class ErrorMessageSendingRecoverer implements RecoveryCallback<Object>, B
private final MessagingTemplate messagingTemplate = new MessagingTemplate();
private BeanFactory beanFactory;
public ErrorMessageSendingRecoverer(MessageChannel channel) {
Assert.notNull(channel, "channel cannot be null");
this.messagingTemplate.setDefaultDestination(channel);
@@ -59,10 +57,10 @@ public class ErrorMessageSendingRecoverer implements RecoveryCallback<Object>, B
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
this.messagingTemplate.setBeanFactory(beanFactory);
}
@Override
public Object recover(RetryContext context) throws Exception {
Throwable lastThrowable = context.getLastThrowable();
if (lastThrowable == null) {

View File

@@ -100,7 +100,7 @@ public final class MessageHistory implements List<Properties>, Serializable {
IntegrationMessageHeaderAccessor headerAccessor = new IntegrationMessageHeaderAccessor(message);
headerAccessor.setHeader(HEADER_NAME, history);
message = new AdviceMessage<T>(message.getPayload(), headerAccessor.toMessageHeaders(),
((AdviceMessage) message).getInputMessage());
((AdviceMessage<?>) message).getInputMessage());
}
else {
if (!(message instanceof GenericMessage) &&

View File

@@ -128,7 +128,7 @@ public class BoonJsonObjectMapper extends JsonObjectMapperAdapter<Map<String, Ob
}
@Override
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> T fromJson(Object json, Map<String, Object> javaTypes) throws Exception {
JsonParserAndMapper parser = this.objectMapper.parser();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-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.
@@ -28,6 +28,7 @@ import org.springframework.integration.mapping.support.JsonHeaders;
* to provide entire operations implementation.
*
* @author Artem Bilan
* @author Gary Russell
* @since 3.0
*/
public abstract class JsonObjectMapperAdapter<N, P> implements JsonObjectMapper<N, P> {
@@ -64,12 +65,12 @@ public abstract class JsonObjectMapperAdapter<N, P> implements JsonObjectMapper<
@Override
public void populateJavaTypes(Map<String, Object> map, Object object) {
map.put(JsonHeaders.TYPE_ID, object.getClass());
if (object instanceof Collection && !((Collection) object).isEmpty()) {
map.put(JsonHeaders.CONTENT_TYPE_ID, ((Collection) object).iterator().next().getClass());
if (object instanceof Collection && !((Collection<?>) object).isEmpty()) {
map.put(JsonHeaders.CONTENT_TYPE_ID, ((Collection<?>) object).iterator().next().getClass());
}
if (object instanceof Map && !((Map) object).isEmpty()) {
map.put(JsonHeaders.CONTENT_TYPE_ID, ((Map) object).values().iterator().next().getClass());
map.put(JsonHeaders.KEY_TYPE_ID, ((Map) object).keySet().iterator().next().getClass());
if (object instanceof Map && !((Map<?, ?>) object).isEmpty()) {
map.put(JsonHeaders.CONTENT_TYPE_ID, ((Map<?, ?>) object).values().iterator().next().getClass());
map.put(JsonHeaders.KEY_TYPE_ID, ((Map<?, ?>) object).keySet().iterator().next().getClass());
}
}

View File

@@ -347,6 +347,7 @@ public class ConcurrentAggregatorTests {
}
@SuppressWarnings("unused")
private class NullReturningMessageProcessor implements MessageGroupProcessor {
@Override
public Object processMessageGroup(MessageGroup group) {

View File

@@ -30,11 +30,11 @@ import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.SpelParserConfiguration;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.integration.support.MessageBuilder;
/**
* @author Alex Peters
@@ -79,6 +79,7 @@ public class ExpressionEvaluatingCorrelationStrategyTests {
inputChannel.send(message);
Message<?> reply = outputChannel.receive(0);
assertNotNull(reply);
context.close();
}
public static class CustomCorrelator {

View File

@@ -338,6 +338,8 @@ public class MethodInvokingMessageGroupProcessorTests {
public void testTwoMethodsWithSameParameterTypesAmbiguous() {
class AnnotatedParametersAggregator {
@SuppressWarnings("unused")
public Integer and(List<Integer> flags) {
int result = 0;
for (Integer flag : flags) {
@@ -346,6 +348,7 @@ public class MethodInvokingMessageGroupProcessorTests {
return result;
}
@SuppressWarnings("unused")
public String listHeaderShouldBeIgnored(@Header List<Integer> flags) {
fail("this method should not be invoked");
return "";

View File

@@ -29,22 +29,22 @@ import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.messaging.Message;
import org.springframework.integration.channel.PublishSubscribeChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.core.MessageSource;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.ErrorMessage;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.endpoint.PollingConsumer;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.integration.scheduling.PollerMetadata;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.test.util.TestUtils.TestApplicationContext;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.ErrorMessage;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.scheduling.support.PeriodicTrigger;
/**
@@ -63,6 +63,7 @@ public class ApplicationContextMessageBusTests {
.setReplyChannelName("targetChannel").build();
sourceChannel.send(message);
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
public Object handleRequestMessage(Message<?> message) {
return message;
}
@@ -101,6 +102,7 @@ public class ApplicationContextMessageBusTests {
PollableChannel targetChannel = (PollableChannel) context.getBean("targetChannel");
Message<?> result = targetChannel.receive(3000);
assertEquals("test", result.getPayload());
context.close();
}
@Test
@@ -231,12 +233,13 @@ public class ApplicationContextMessageBusTests {
private static class FailingSource implements MessageSource<Object> {
private CountDownLatch latch;
private final CountDownLatch latch;
FailingSource(CountDownLatch latch) {
this.latch = latch;
}
@Override
public Message<Object> receive() {
latch.countDown();
throw new RuntimeException("intentional test failure");

View File

@@ -138,7 +138,7 @@ public class DispatchingChannelParserTests {
public void loadBalancerRefFailWithLoadBalancer() {
try {
new ClassPathXmlApplicationContext("ChannelWithLoadBalancerRef-fail-config.xml", this.getClass());
new ClassPathXmlApplicationContext("ChannelWithLoadBalancerRef-fail-config.xml", this.getClass()).close();
}
catch (BeanDefinitionParsingException e) {
assertThat(e.getMessage(), Matchers.containsString("'load-balancer' and 'load-balancer-ref' are mutually exclusive"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 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.
@@ -21,11 +21,12 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.channel.RendezvousChannel;
import org.springframework.messaging.MessageChannel;
/**
* @author Mark Fisher
* @author Gary Russell
*/
public class RendezvousChannelParserTests {
@@ -35,6 +36,7 @@ public class RendezvousChannelParserTests {
"rendezvousChannelParserTests.xml", RendezvousChannelParserTests.class);
MessageChannel channel = (MessageChannel) context.getBean("channel");
assertEquals(RendezvousChannel.class, channel.getClass());
context.close();
}
}

View File

@@ -353,7 +353,7 @@ public class ChannelInterceptorTests {
private static class AfterCompletionTestInterceptor extends ChannelInterceptorAdapter {
private AtomicInteger counter = new AtomicInteger();
private final AtomicInteger counter = new AtomicInteger();
private volatile boolean afterCompletionInvoked;
@@ -363,6 +363,7 @@ public class ChannelInterceptorTests {
this.exceptionToRaise = exception;
}
@SuppressWarnings("unused")
public AtomicInteger getCounter() {
return this.counter;
}
@@ -390,7 +391,7 @@ public class ChannelInterceptorTests {
private static class PreReceiveReturnsTrueInterceptor extends ChannelInterceptorAdapter {
private AtomicInteger counter = new AtomicInteger();
private final AtomicInteger counter = new AtomicInteger();
private volatile boolean afterCompletionInvoked;

View File

@@ -129,6 +129,7 @@ public class AnnotatedEndpointActivationTests {
}
@SuppressWarnings("unused")
private static class AnnotatedEndpoint2 {
@ServiceActivator(inputChannel = "input", outputChannel = "output")

View File

@@ -27,13 +27,13 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.annotation.Order;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.MessageRejectedException;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
/**
@@ -65,6 +65,7 @@ public class SubscriberOrderTests {
assertEquals(3, calls.get(2).intValue());
assertEquals(4, calls.get(3).intValue());
assertEquals(5, calls.get(4).intValue());
context.close();
}
@Test
@@ -106,6 +107,7 @@ public class SubscriberOrderTests {
channel.send(new GenericMessage<String>("test-11"));
assertEquals(1, testBean.calls.size());
assertEquals(1, testBean.calls.get(0).intValue());
context.close();
}
@Test
@@ -133,6 +135,7 @@ public class SubscriberOrderTests {
assertEquals(3, calls.get(2).intValue());
assertEquals(4, calls.get(3).intValue());
assertEquals(5, calls.get(4).intValue());
context.close();
}

View File

@@ -23,27 +23,29 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
*
* @author Oleg Zhurakousky
* @author Gary Russell
*
*/
public class ChannelAutoCreationTests {
@Test // no assertions since it validates that no exception is thrown
public void testEnablingAutoChannelCreationBeforeWithCustom() {
new ClassPathXmlApplicationContext("TestEnableChannelAutoCreation-before-context.xml", this.getClass());
new ClassPathXmlApplicationContext("TestEnableChannelAutoCreation-before-context.xml", this.getClass()).close();
}
@Test // no assertions since it validates that no exception is thrown
public void testEnablingAutoChannelCreationAfterWithCustom() {
new ClassPathXmlApplicationContext("TestEnableChannelAutoCreation-after-context.xml", this.getClass());
new ClassPathXmlApplicationContext("TestEnableChannelAutoCreation-after-context.xml", this.getClass()).close();
}
@Test(expected = BeanCreationException.class)
public void testDisablingAutoChannelCreationAfter() {
new ClassPathXmlApplicationContext("TestDisableChannelAutoCreation-after-context.xml", this.getClass());
new ClassPathXmlApplicationContext("TestDisableChannelAutoCreation-after-context.xml", this.getClass()).close();
}
@Test(expected = BeanCreationException.class)
public void testDisablingAutoChannelCreationBefore() {
new ClassPathXmlApplicationContext("TestDisableChannelAutoCreation-before-context.xml", this.getClass());
new ClassPathXmlApplicationContext("TestDisableChannelAutoCreation-before-context.xml", this.getClass())
.close();
}
}

View File

@@ -131,10 +131,10 @@ public class ControlBusRecipientListRouterTests {
messagingTemplate.setReceiveTimeout(1000);
messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.addRecipient('channel1')");
messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.getRecipients()");
PollableChannel chanel1 = (PollableChannel) context.getBean("channel1");
PollableChannel channel1 = (PollableChannel) context.getBean("channel1");
Message<?> result = this.output.receive(0);
Collection<Recipient> mappings = (Collection<Recipient>) result.getPayload();
assertEquals(context.getBean("channel1"), mappings.iterator().next().getChannel());
assertEquals(channel1, mappings.iterator().next().getChannel());
}
@Test

View File

@@ -55,8 +55,9 @@ public class ConverterParserWithExistingConversionServiceTests {
}
@Test
public void testParentConversionServiceAvailability() {
ApplicationContext parentContext =
new ClassPathXmlApplicationContext("ConverterParserWithExistingConversionServiceTests-parent.xml", ConverterParserWithExistingConversionServiceTests.class);
ClassPathXmlApplicationContext parentContext = new ClassPathXmlApplicationContext(
"ConverterParserWithExistingConversionServiceTests-parent.xml",
ConverterParserWithExistingConversionServiceTests.class);
GenericApplicationContext childContext = new GenericApplicationContext();
childContext.setParent(parentContext);
@@ -69,6 +70,8 @@ public class ConverterParserWithExistingConversionServiceTests {
conversionServiceChild.addConverter(new TestConverter3());
Assert.isTrue(conversionServiceChild.canConvert(TestBean1.class, TestBean2.class));
Assert.isTrue(conversionServiceChild.canConvert(TestBean1.class, TestBean3.class));
childContext.close();
parentContext.close();
}

View File

@@ -41,6 +41,7 @@ import org.springframework.util.ErrorHandler;
/**
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -80,17 +81,24 @@ public class DefaultConfiguringBeanFactoryPostProcessorTests {
@Test
public void taskSchedulerNotRegisteredMoreThanOnce() {
ClassPathXmlApplicationContext superParentApplicationContext = new ClassPathXmlApplicationContext("superParentApplicationContext.xml", this.getClass());
ClassPathXmlApplicationContext parentApplicationContext =
new ClassPathXmlApplicationContext(new String[]{"org/springframework/integration/config/xml/parentApplicationContext.xml"}, superParentApplicationContext);
ClassPathXmlApplicationContext childApplicationContext =
new ClassPathXmlApplicationContext(new String[]{"org/springframework/integration/config/xml/childApplicationContext.xml"}, parentApplicationContext);
TaskScheduler parentScheduler = childApplicationContext.getParent().getBean("taskScheduler", TaskScheduler.class);
TaskScheduler childScheduler = childApplicationContext.getBean("taskScheduler", TaskScheduler.class);
ClassPathXmlApplicationContext superParentApplicationContext = new ClassPathXmlApplicationContext(
"superParentApplicationContext.xml", this.getClass());
ClassPathXmlApplicationContext parentApplicationContext = new ClassPathXmlApplicationContext(
new String[] { "org/springframework/integration/config/xml/parentApplicationContext.xml" },
superParentApplicationContext);
ClassPathXmlApplicationContext childApplicationContext = new ClassPathXmlApplicationContext(
new String[] { "org/springframework/integration/config/xml/childApplicationContext.xml" },
parentApplicationContext);
TaskScheduler parentScheduler = childApplicationContext.getParent().getBean("taskScheduler",
TaskScheduler.class);
TaskScheduler childScheduler = childApplicationContext.getBean("taskScheduler", TaskScheduler.class);
assertNotNull("Child task scheduler was null", childScheduler);
assertNotNull("Parent task scheduler was null", parentScheduler);
assertEquals("Different schedulers in parent and child", parentScheduler, childScheduler);
assertNotNull("Child task scheduler was null", childScheduler);
assertNotNull("Parent task scheduler was null", parentScheduler);
assertEquals("Different schedulers in parent and child", parentScheduler, childScheduler);
childApplicationContext.close();
parentApplicationContext.close();
superParentApplicationContext.close();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 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.
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.expression.spel.SpelEvaluationException;
import org.springframework.messaging.Message;
@@ -40,7 +40,8 @@ public class EnricherParserTests3 {
@Test
public void testSourceBeanResolver() {
ApplicationContext context = new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-context.xml", this.getClass());
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
this.getClass().getSimpleName() + "-context.xml", this.getClass());
MessageChannel beanResolveIn = context.getBean("beanResolveIn", MessageChannel.class);
PollableChannel beanResolveOut = context.getBean("beanResolveOut", PollableChannel.class);
SomeBean payload = new SomeBean("foo");
@@ -50,11 +51,13 @@ public class EnricherParserTests3 {
Message<SomeBean> out = (Message<SomeBean>) beanResolveOut.receive();
assertSame(payload, out.getPayload());
assertEquals("bar", out.getPayload().getNested().getValue());
context.close();
}
@Test
public void testTargetBeanResolver() {
ApplicationContext context = new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail-context.xml", this.getClass());
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
this.getClass().getSimpleName() + "-fail-context.xml", this.getClass());
MessageChannel beanResolveIn = context.getBean("beanResolveIn", MessageChannel.class);
SomeBean payload = new SomeBean("foo");
assertEquals("foo", payload.getNested().getValue());
@@ -65,11 +68,12 @@ public class EnricherParserTests3 {
catch (MessageHandlingException e) {
assertTrue(e.getCause() instanceof SpelEvaluationException);
}
context.close();
}
public static class SomeBean {
private Nested nested = new Nested();
private final Nested nested = new Nested();
public SomeBean(String someProperty) {
this.nested.setValue(someProperty);

View File

@@ -258,7 +258,7 @@ public class HeaderEnricherTests {
@Test(expected = BeanDefinitionParsingException.class)
public void testFailConfigUnexpectedSubElement() {
new ClassPathXmlApplicationContext("HeaderEnricherWithUnexpectedSubElementForHeader-fail-context.xml",
this.getClass());
this.getClass()).close();
}
@Test
@@ -272,7 +272,7 @@ public class HeaderEnricherTests {
assertNotNull(routingSlip);
assertThat(routingSlip, instanceOf(Map.class));
@SuppressWarnings("unchecked")
List<Object> routingSlipPath = (List<Object>) ((Map) routingSlip).keySet().iterator().next();
List<Object> routingSlipPath = (List<Object>) ((Map<?, ?>) routingSlip).keySet().iterator().next();
assertEquals("fooChannel", routingSlipPath.get(0));
assertThat(routingSlipPath.get(1), instanceOf(ExpressionEvaluatingRoutingSlipRouteStrategy.class));

View File

@@ -75,7 +75,8 @@ public class LoggingChannelAdapterParserTests {
@Test
public void failConfigLogFullMessageAndExpression() {
try {
new ClassPathXmlApplicationContext("LoggingChannelAdapterParserTests-fail-context.xml", this.getClass());
new ClassPathXmlApplicationContext("LoggingChannelAdapterParserTests-fail-context.xml", this.getClass())
.close();
fail("BeanDefinitionParsingException expected");
}
catch (BeansException e) {

View File

@@ -25,15 +25,16 @@ import java.util.Map;
import org.junit.Test;
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.core.convert.converter.Converter;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -127,7 +128,8 @@ public class MapToObjectTransformerParserTests {
}
@Test(expected = BeanCreationException.class)
public void testNonPrototypeFailure() {
new ClassPathXmlApplicationContext("MapToObjectTransformerParserTests-context-fail.xml", MapToObjectTransformerParserTests.class);
new ClassPathXmlApplicationContext("MapToObjectTransformerParserTests-context-fail.xml",
MapToObjectTransformerParserTests.class).close();
}
public static class Person {
@@ -175,6 +177,7 @@ public class MapToObjectTransformerParserTests {
public static class StringToAddressConverter implements Converter<String, Address> {
public StringToAddressConverter() { }
@Override
public Address convert(String source) {
Address address = new Address();
address.setStreet(source);

View File

@@ -28,7 +28,6 @@ import org.aopalliance.aop.Advice;
import org.junit.Test;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.config.TestTrigger;
import org.springframework.integration.scheduling.PollerMetadata;
@@ -47,38 +46,40 @@ public class PollerParserTests {
@Test
public void defaultPollerWithId() {
ApplicationContext context = new ClassPathXmlApplicationContext(
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"defaultPollerWithId.xml", PollerParserTests.class);
Object poller = context.getBean("defaultPollerWithId");
assertNotNull(poller);
Object defaultPoller = context.getBean(PollerMetadata.DEFAULT_POLLER_METADATA_BEAN_NAME);
assertNotNull(defaultPoller);
assertEquals(defaultPoller, context.getBean("defaultPollerWithId"));
context.close();
}
@Test
public void defaultPollerWithoutId() {
ApplicationContext context = new ClassPathXmlApplicationContext(
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"defaultPollerWithoutId.xml", PollerParserTests.class);
Object defaultPoller = context.getBean(PollerMetadata.DEFAULT_POLLER_METADATA_BEAN_NAME);
assertNotNull(defaultPoller);
context.close();
}
@Test(expected = BeanDefinitionParsingException.class)
public void multipleDefaultPollers() {
new ClassPathXmlApplicationContext(
"multipleDefaultPollers.xml", PollerParserTests.class);
"multipleDefaultPollers.xml", PollerParserTests.class).close();
}
@Test(expected = BeanDefinitionParsingException.class)
public void topLevelPollerWithoutId() {
new ClassPathXmlApplicationContext(
"topLevelPollerWithoutId.xml", PollerParserTests.class);
"topLevelPollerWithoutId.xml", PollerParserTests.class).close();
}
@Test
public void pollerWithAdviceChain() {
ApplicationContext context = new ClassPathXmlApplicationContext(
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"pollerWithAdviceChain.xml", PollerParserTests.class);
Object poller = context.getBean("poller");
assertNotNull(poller);
@@ -97,12 +98,13 @@ public class PollerParserTests {
HashMap nameMap = TestUtils.getPropertyValue(transactionAttributeSource, "nameMap", HashMap.class);
assertEquals(1, nameMap.size());
assertEquals("{*=PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnly}", nameMap.toString());
context.close();
}
@Test
public void pollerWithReceiveTimeoutAndTimeunit() {
ApplicationContext context = new ClassPathXmlApplicationContext(
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"pollerWithReceiveTimeout.xml", PollerParserTests.class);
Object poller = context.getBean("poller");
assertNotNull(poller);
@@ -110,34 +112,36 @@ public class PollerParserTests {
assertEquals(1234, metadata.getReceiveTimeout());
PeriodicTrigger trigger = (PeriodicTrigger) metadata.getTrigger();
assertEquals(TimeUnit.SECONDS.toString(), TestUtils.getPropertyValue(trigger, "timeUnit").toString());
context.close();
}
@Test
public void pollerWithTriggerReference() {
ApplicationContext context = new ClassPathXmlApplicationContext(
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"pollerWithTriggerReference.xml", PollerParserTests.class);
Object poller = context.getBean("poller");
assertNotNull(poller);
PollerMetadata metadata = (PollerMetadata) poller;
assertTrue(metadata.getTrigger() instanceof TestTrigger);
context.close();
}
@Test(expected = BeanDefinitionParsingException.class)
public void pollerWithCronTriggerAndTimeUnit() {
new ClassPathXmlApplicationContext(
"cronTriggerWithTimeUnit-fail.xml", PollerParserTests.class);
"cronTriggerWithTimeUnit-fail.xml", PollerParserTests.class).close();
}
@Test(expected = BeanDefinitionParsingException.class)
public void topLevelPollerWithRef() {
new ClassPathXmlApplicationContext(
"defaultPollerWithRef.xml", PollerParserTests.class);
"defaultPollerWithRef.xml", PollerParserTests.class).close();
}
@Test(expected = BeanDefinitionParsingException.class)
public void pollerWithCronAndFixedDelay() {
new ClassPathXmlApplicationContext(
"pollerWithCronAndFixedDelay.xml", PollerParserTests.class);
"pollerWithCronAndFixedDelay.xml", PollerParserTests.class).close();
}
}

View File

@@ -24,15 +24,14 @@ import static org.mockito.Mockito.verify;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.messaging.support.GenericMessage;
/**
@@ -49,7 +48,8 @@ public class PollerWithErrorChannelTests {
* receive() and not on send()
*/
public void testWithErrorChannelAsHeader() throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml",
this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("withErrorHeader", SourcePollingChannelAdapter.class);
SubscribableChannel errorChannel = ac.getBean("errorChannel", SubscribableChannel.class);
@@ -59,47 +59,58 @@ public class PollerWithErrorChannelTests {
Thread.sleep(1000);
verify(handler, atLeastOnce()).handleMessage(Mockito.any(Message.class));
adapter.stop();
ac.close();
}
@Test
public void testWithErrorChannel() throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml",
this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannel", SourcePollingChannelAdapter.class);
adapter.start();
PollableChannel errorChannel = ac.getBean("eChannel", PollableChannel.class);
assertNotNull(errorChannel.receive(10000));
adapter.stop();
ac.close();
}
@Test
public void testWithErrorChannelAndHeader() throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannelAndHeader", SourcePollingChannelAdapter.class);
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml",
this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannelAndHeader",
SourcePollingChannelAdapter.class);
adapter.start();
PollableChannel errorChannel = ac.getBean("eChannel", PollableChannel.class);
assertNotNull(errorChannel.receive(10000));
adapter.stop();
ac.close();
}
@Test
// config the same as above but the error wil come from the send
public void testWithErrorChannelAndHeaderWithSendFailure() throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannelAndHeaderErrorOnSend", SourcePollingChannelAdapter.class);
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml",
this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannelAndHeaderErrorOnSend",
SourcePollingChannelAdapter.class);
adapter.start();
PollableChannel errorChannel = ac.getBean("errChannel", PollableChannel.class);
assertNotNull(errorChannel.receive(10000));
adapter.stop();
ac.close();
}
@Test
// INT-1952
public void testWithErrorChannelAndPollingConsumer() throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml",
this.getClass());
MessageChannel serviceWithPollerChannel = ac.getBean("serviceWithPollerChannel", MessageChannel.class);
QueueChannel errorChannel = ac.getBean("serviceErrorChannel", QueueChannel.class);
serviceWithPollerChannel.send(new GenericMessage<String>(""));
assertNotNull(errorChannel.receive(10000));
ac.close();
}
public static class SampleService {

View File

@@ -27,11 +27,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.handler.ServiceActivatingHandler;
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -121,7 +121,7 @@ public class ServiceActivatorParserTests {
public void failRefAndExpression() {
try {
new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail-ref-and-expression-context.xml",
this.getClass());
this.getClass()).close();
fail("Expected exception");
}
catch (BeanDefinitionParsingException e) {
@@ -134,7 +134,7 @@ public class ServiceActivatorParserTests {
public void failRefAndBean() {
try {
new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail-ref-and-bean-context.xml",
this.getClass());
this.getClass()).close();
fail("Expected exception");
}
catch (BeanDefinitionParsingException e) {
@@ -149,7 +149,7 @@ public class ServiceActivatorParserTests {
public void failExpressionAndBean() {
try {
new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail-expression-and-bean-context.xml",
this.getClass());
this.getClass()).close();
fail("Expected exception");
}
catch (BeanDefinitionParsingException e) {
@@ -163,7 +163,7 @@ public class ServiceActivatorParserTests {
public void failNoService() {
try {
new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail-no-service-context.xml",
this.getClass());
this.getClass()).close();
fail("Expected exception");
}
catch (BeanDefinitionParsingException e) {
@@ -177,7 +177,7 @@ public class ServiceActivatorParserTests {
public void failExpressionAndExpression() {
try {
new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail-expression-and-expression-element-context.xml",
this.getClass());
this.getClass()).close();
fail("Expected exception");
}
catch (BeanDefinitionParsingException e) {
@@ -191,7 +191,7 @@ public class ServiceActivatorParserTests {
public void failMethodAndExpressionElement() {
try {
new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail-method-and-expression-element-context.xml",
this.getClass());
this.getClass()).close();
fail("Expected exception");
}
catch (BeanDefinitionParsingException e) {

View File

@@ -25,52 +25,60 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpression;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.transaction.DefaultTransactionSynchronizationFactory;
import org.springframework.integration.transaction.ExpressionEvaluatingTransactionSynchronizationProcessor;
import org.springframework.integration.transaction.TransactionSynchronizationProcessor;
import org.springframework.messaging.MessageChannel;
/**
* @author Oleg Zhurakousky
* @author Gary Russell
*/
public class TransactionSynchronizationFactoryParserTests {
@Test // nothing to assert. Validates only XSD
public void validateXsdCombinationOfOrderOfSubelements() {
new ClassPathXmlApplicationContext("TransactionSynchronizationFactoryParserTests-xsd.xml", this.getClass());
new ClassPathXmlApplicationContext("TransactionSynchronizationFactoryParserTests-xsd.xml", this.getClass())
.close();
}
@Test
public void validateFullConfiguration() {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("TransactionSynchronizationFactoryParserTests-config.xml", this.getClass());
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"TransactionSynchronizationFactoryParserTests-config.xml", this.getClass());
DefaultTransactionSynchronizationFactory syncFactory =
context.getBean("syncFactoryComplete", DefaultTransactionSynchronizationFactory.class);
DefaultTransactionSynchronizationFactory syncFactory = context.getBean("syncFactoryComplete",
DefaultTransactionSynchronizationFactory.class);
assertNotNull(syncFactory);
TransactionSynchronizationProcessor processor =
TestUtils.getPropertyValue(syncFactory, "processor", ExpressionEvaluatingTransactionSynchronizationProcessor.class);
TransactionSynchronizationProcessor processor = TestUtils.getPropertyValue(syncFactory, "processor",
ExpressionEvaluatingTransactionSynchronizationProcessor.class);
assertNotNull(processor);
MessageChannel beforeCommitResultChannel = TestUtils.getPropertyValue(processor, "beforeCommitChannel", MessageChannel.class);
MessageChannel beforeCommitResultChannel = TestUtils.getPropertyValue(processor, "beforeCommitChannel",
MessageChannel.class);
assertNotNull(beforeCommitResultChannel);
assertEquals(beforeCommitResultChannel, context.getBean("beforeCommitChannel"));
Object beforeCommitExpression = TestUtils.getPropertyValue(processor, "beforeCommitExpression");
assertNull(beforeCommitExpression);
MessageChannel afterCommitResultChannel = TestUtils.getPropertyValue(processor, "afterCommitChannel", MessageChannel.class);
MessageChannel afterCommitResultChannel = TestUtils.getPropertyValue(processor, "afterCommitChannel",
MessageChannel.class);
assertNotNull(afterCommitResultChannel);
assertEquals(afterCommitResultChannel, context.getBean("nullChannel"));
Expression afterCommitExpression = TestUtils.getPropertyValue(processor, "afterCommitExpression", Expression.class);
Expression afterCommitExpression = TestUtils.getPropertyValue(processor, "afterCommitExpression",
Expression.class);
assertNotNull(afterCommitExpression);
assertEquals("'afterCommit'", ((SpelExpression) afterCommitExpression).getExpressionString());
MessageChannel afterRollbackResultChannel = TestUtils.getPropertyValue(processor, "afterRollbackChannel", MessageChannel.class);
MessageChannel afterRollbackResultChannel = TestUtils.getPropertyValue(processor, "afterRollbackChannel",
MessageChannel.class);
assertNotNull(afterRollbackResultChannel);
assertEquals(afterRollbackResultChannel, context.getBean("afterRollbackChannel"));
Expression afterRollbackExpression = TestUtils.getPropertyValue(processor, "afterRollbackExpression", Expression.class);
Expression afterRollbackExpression = TestUtils.getPropertyValue(processor, "afterRollbackExpression",
Expression.class);
assertNotNull(afterRollbackExpression);
assertEquals("'afterRollback'", ((SpelExpression) afterRollbackExpression).getExpressionString());
context.close();
}
}

View File

@@ -113,7 +113,7 @@ public class MessageHistoryTests {
assertThat(result1, instanceOf(AdviceMessage.class));
assertNotSame(original, result1);
assertSame(original.getPayload(), result1.getPayload());
assertSame(original.getInputMessage(), ((AdviceMessage) result1).getInputMessage());
assertSame(original.getInputMessage(), ((AdviceMessage<?>) result1).getInputMessage());
MessageHistory history1 = MessageHistory.read(result1);
assertNotNull(history1);
assertEquals("testComponent-1", history1.toString());
@@ -121,7 +121,7 @@ public class MessageHistoryTests {
assertThat(result2, instanceOf(AdviceMessage.class));
assertNotSame(original, result2);
assertSame(original.getPayload(), result2.getPayload());
assertSame(original.getInputMessage(), ((AdviceMessage) result2).getInputMessage());
assertSame(original.getInputMessage(), ((AdviceMessage<?>) result2).getInputMessage());
assertNotSame(result1, result2);
MessageHistory history2 = MessageHistory.read(result2);
assertNotNull(history2);
@@ -137,10 +137,12 @@ public class MessageHistoryTests {
this.id = id;
}
@Override
public String getComponentName() {
return "testComponent-" + this.id;
}
@Override
public String getComponentType() {
return "type-" + this.id;
}

View File

@@ -33,13 +33,13 @@ import org.springframework.aop.Advisor;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.PollingConsumer;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.util.TestTransactionManager;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.integration.endpoint.PollingConsumer;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.util.TestTransactionManager;
import org.springframework.transaction.IllegalTransactionStateException;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.interceptor.TransactionInterceptor;
@@ -47,6 +47,7 @@ import org.springframework.transaction.interceptor.TransactionInterceptor;
/**
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
*/
public class PollingTransactionTests {
@@ -65,7 +66,7 @@ public class PollingTransactionTests {
assertNotNull(message);
assertEquals(1, txManager.getCommitCount());
assertEquals(0, txManager.getRollbackCount());
context.stop();
context.close();
}
@Test
@@ -95,7 +96,7 @@ public class PollingTransactionTests {
assertNotNull(message);
assertEquals(1, txManager.getCommitCount());
assertEquals(0, txManager.getRollbackCount());
context.stop();
context.close();
}
@Test
@@ -113,7 +114,7 @@ public class PollingTransactionTests {
assertNull(message);
assertEquals(0, txManager.getCommitCount());
assertEquals(1, txManager.getRollbackCount());
context.stop();
context.close();
}
@Test
@@ -130,7 +131,7 @@ public class PollingTransactionTests {
txManager.waitForCompletion(3000);
assertEquals(1, txManager.getCommitCount());
assertEquals(Propagation.REQUIRED.value(), txManager.getLastDefinition().getPropagationBehavior());
context.stop();
context.close();
}
@Test
@@ -147,7 +148,7 @@ public class PollingTransactionTests {
txManager.waitForCompletion(3000);
assertEquals(1, txManager.getCommitCount());
assertEquals(Propagation.REQUIRES_NEW.value(), txManager.getLastDefinition().getPropagationBehavior());
context.stop();
context.close();
}
@Test
@@ -163,7 +164,7 @@ public class PollingTransactionTests {
assertNotNull(reply);
assertEquals(0, txManager.getCommitCount());
assertNull(txManager.getLastDefinition());
context.stop();
context.close();
}
@Test
@@ -179,7 +180,7 @@ public class PollingTransactionTests {
assertNotNull(reply);
assertEquals(0, txManager.getCommitCount());
assertNull(txManager.getLastDefinition());
context.stop();
context.close();
}
@Test
@@ -198,12 +199,14 @@ public class PollingTransactionTests {
assertEquals(IllegalTransactionStateException.class, payload.getClass());
assertNull(output.receive(0));
assertEquals(0, txManager.getCommitCount());
context.stop();
context.close();
}
public static class SampleAdvice implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
return invocation.proceed();
}
}
}

View File

@@ -19,13 +19,14 @@ package org.springframework.integration.dispatcher;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Gary Russell
*
* This test was influenced by INT-1483 where by registering TX Advisor
* in the BeanFactory while having <aop:config> resent resulted in
@@ -35,11 +36,12 @@ public class TransactionalPollerWithMixedAopConfigTests {
@Test
public void validateTransactionalProxyIsolationToThePollerOnly() {
ApplicationContext context =
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("TransactionalPollerWithMixedAopConfig-context.xml", this.getClass());
assertTrue(!(context.getBean("foo") instanceof Advised));
assertTrue(!(context.getBean("inputChannel") instanceof Advised));
context.close();
}
public static class SampleService {

View File

@@ -20,20 +20,21 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.gateway.RequestReplyExchanger;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.support.GenericMessage;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Gary Russell
*
*/
public class UnicastingDispatcherTests {
@@ -41,10 +42,11 @@ public class UnicastingDispatcherTests {
@SuppressWarnings("unchecked")
@Test
public void withInboundGatewayAsyncRequestChannelAndExplicitErrorChannel() throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("unicasting-with-async.xml", this.getClass());
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("unicasting-with-async.xml", this.getClass());
SubscribableChannel errorChannel = context.getBean("errorChannel", SubscribableChannel.class);
MessageHandler errorHandler = new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
assertTrue(message.getPayload() instanceof MessageDeliveryException);
@@ -56,6 +58,7 @@ public class UnicastingDispatcherTests {
RequestReplyExchanger exchanger = context.getBean(RequestReplyExchanger.class);
Message<String> reply = (Message<String>) exchanger.exchange(new GenericMessage<String>("Hello"));
assertEquals("reply", reply.getPayload());
context.close();
}
}

View File

@@ -28,6 +28,7 @@ import org.springframework.messaging.support.ErrorMessage;
/**
* @author Jonas Partner
* @author Gary Russell
*/
public class PollingEndpointErrorHandlingTests {
@@ -40,6 +41,7 @@ public class PollingEndpointErrorHandlingTests {
Message errorMessage = errorChannel.receive(5000);
assertNotNull("No error message received", errorMessage);
assertEquals("Message received was not an ErrorMessage", ErrorMessage.class, errorMessage.getClass());
context.close();
}
}

View File

@@ -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.
@@ -34,6 +34,7 @@ import org.springframework.messaging.support.GenericMessage;
/**
* @author Mark Fisher
* @author Gary Russell
*/
public class ReturnAddressTests {
@@ -50,6 +51,7 @@ public class ReturnAddressTests {
Message<?> response = channel5.receive(3000);
assertNotNull(response);
assertEquals("**", response.getPayload());
context.close();
}
@Test
@@ -65,6 +67,7 @@ public class ReturnAddressTests {
Message<?> response = channel5.receive(3000);
assertNotNull(response);
assertEquals("**", response.getPayload());
context.close();
}
@Test
@@ -82,6 +85,7 @@ public class ReturnAddressTests {
assertEquals("********", response.getPayload());
PollableChannel channel2 = (PollableChannel) context.getBean("channel2");
assertNull(channel2.receive(0));
context.close();
}
@Test
@@ -99,6 +103,7 @@ public class ReturnAddressTests {
assertEquals("********", response.getPayload());
PollableChannel channel2 = (PollableChannel) context.getBean("channel2");
assertNull(channel2.receive(0));
context.close();
}
@Test
@@ -114,6 +119,7 @@ public class ReturnAddressTests {
catch (MessagingException e) {
assertTrue(e.getCause() instanceof DestinationResolutionException);
}
context.close();
}
@Test
@@ -128,6 +134,7 @@ public class ReturnAddressTests {
Message<?> response = replyChannel.receive(3000);
assertNotNull(response);
assertEquals("**", response.getPayload());
context.close();
}
@Test
@@ -145,6 +152,7 @@ public class ReturnAddressTests {
assertEquals("**", response.getPayload());
PollableChannel channel5 = (PollableChannel) context.getBean("channel5");
assertNull(channel5.receive(0));
context.close();
}
}

View File

@@ -60,7 +60,9 @@ public class DynamicExpressionTests {
ClassPathResource resource = new ClassPathResource(filepath);
byte[] bytes = new String(key + "=" + expressionString).getBytes();
try {
new FileOutputStream(resource.getFile()).write(bytes);
FileOutputStream fileOutputStream = new FileOutputStream(resource.getFile());
fileOutputStream.write(bytes);
fileOutputStream.close();
}
catch (Exception e) {
throw new IllegalStateException("failed to write expression string to file", e);

View File

@@ -132,6 +132,7 @@ public class GatewayInterfaceTests {
bar.foo("hello");
assertTrue(called.get());
Map<?, ?> gateways = TestUtils.getPropertyValue(ac.getBean("&sampleGateway"), "gatewayMap", Map.class);
assertEquals(5, gateways.size());
ac.close();
}

View File

@@ -166,6 +166,7 @@ public class GatewayProxyFactoryBeanTests {
TestService service = (TestService) context.getBean("proxy");
String result = service.requestReply("foo");
assertEquals("foo!!!", result);
context.close();
}
@Test
@@ -178,6 +179,7 @@ public class GatewayProxyFactoryBeanTests {
TestChannelInterceptor interceptor = (TestChannelInterceptor) context.getBean("interceptor");
assertEquals(1, interceptor.getSentCount());
assertEquals(1, interceptor.getReceivedCount());
context.close();
}
@Test
@@ -213,6 +215,7 @@ public class GatewayProxyFactoryBeanTests {
TestChannelInterceptor interceptor = (TestChannelInterceptor) context.getBean("interceptor");
assertEquals(numRequests, interceptor.getSentCount());
assertEquals(numRequests, interceptor.getReceivedCount());
context.close();
}
@Test
@@ -390,7 +393,7 @@ public class GatewayProxyFactoryBeanTests {
@Test
public void autowiredGateway() {
new ClassPathXmlApplicationContext("gatewayAutowiring.xml", GatewayProxyFactoryBeanTests.class);
new ClassPathXmlApplicationContext("gatewayAutowiring.xml", GatewayProxyFactoryBeanTests.class).close();
}

View File

@@ -28,14 +28,14 @@ import org.junit.Test;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.IntegrationEvaluationContextFactoryBean;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
/**
* @author Mark Fisher
@@ -153,6 +153,7 @@ public class GatewayProxyMessageMappingTests {
Message<?> result = channel.receive(0);
assertNotNull(result);
assertEquals("FOO!!!", result.getPayload());
context.close();
}
@Test
@@ -184,6 +185,7 @@ public class GatewayProxyMessageMappingTests {
assertNotNull(barResult);
assertEquals(309, barResult.getPayload());
assertNull(channel.receive(0));
context.close();
}
@Test(expected = MessagingException.class)

View File

@@ -525,6 +525,7 @@ public class MethodInvokingMessageProcessorTests {
private final Map<String, Object> arguments = new LinkedHashMap<String, Object>();
@SuppressWarnings("unused")
public void optionalHeaders(Optional<String> foo, @Header(value = "foo", required = false) String foo1,
@Header(value = "foo") Optional<String> foo2) {
this.arguments.put("foo", (foo.isPresent() ? foo.get() : null));

View File

@@ -30,16 +30,17 @@ import org.mockito.Mockito;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.integration.test.util.TestUtils;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Gary Russell
*
*/
public class AnotatedTests {
@@ -49,6 +50,7 @@ public class AnotatedTests {
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("annotated-config.xml", this.getClass());
ApplicationListener<ApplicationEvent> listener = new ApplicationListener<ApplicationEvent>() {
@Override
public void onApplicationEvent(ApplicationEvent event) {
MessageHistory history = MessageHistory.read((Message<?>) event.getSource());
Properties adapterHistory = history.get(1);
@@ -67,5 +69,7 @@ public class AnotatedTests {
handlerField.set(consumer, handler);
channel.send(new GenericMessage<String>("hello"));
verify(listener, times(1)).onApplicationEvent((ApplicationEvent) Mockito.any());
ac.close();
}
}

View File

@@ -31,6 +31,7 @@ import org.springframework.messaging.support.GenericMessage;
/**
* @author Artem Bilan
* @author Gary Russell
* @since 3.0
*/
public class JsonTransformersSymmetricalTests {
@@ -50,7 +51,7 @@ public class JsonTransformersSymmetricalTests {
JsonToObjectTransformer jsonToObjectTransformer = new JsonToObjectTransformer();
Object result = jsonToObjectTransformer.transform(jsonMessage).getPayload();
assertThat(result, Matchers.instanceOf(List.class));
assertEquals(person, ((List) result).get(0));
assertEquals(person, ((List<?>) result).get(0));
}
@Test
@@ -68,7 +69,7 @@ public class JsonTransformersSymmetricalTests {
JsonToObjectTransformer jsonToObjectTransformer = new JsonToObjectTransformer(new BoonJsonObjectMapper());
Object result = jsonToObjectTransformer.transform(jsonMessage).getPayload();
assertThat(result, Matchers.instanceOf(List.class));
assertEquals(person, ((List) result).get(0));
assertEquals(person, ((List<?>) result).get(0));
}

View File

@@ -16,6 +16,12 @@
package org.springframework.integration.resource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.Collection;
@@ -28,21 +34,16 @@ import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.messaging.Message;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.util.CollectionFilter;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.springframework.messaging.Message;
/**
* @author Oleg Zhurakousky
* @author Artem Bilan
* @author Gary Russell
* @since 2.1
*/
public class ResourceInboundChannelAdapterParserTests {
@@ -72,9 +73,12 @@ public class ResourceInboundChannelAdapterParserTests {
@Test
public void testDefaultConfig() {
ApplicationContext context = new ClassPathXmlApplicationContext("ResourcePatternResolver-config.xml", this.getClass());
SourcePollingChannelAdapter resourceAdapter = context.getBean("resourceAdapterDefault", SourcePollingChannelAdapter.class);
ResourceRetrievingMessageSource source = TestUtils.getPropertyValue(resourceAdapter, "source", ResourceRetrievingMessageSource.class);
ApplicationContext context = new ClassPathXmlApplicationContext("ResourcePatternResolver-config.xml",
this.getClass());
SourcePollingChannelAdapter resourceAdapter = context.getBean("resourceAdapterDefault",
SourcePollingChannelAdapter.class);
ResourceRetrievingMessageSource source = TestUtils.getPropertyValue(resourceAdapter, "source",
ResourceRetrievingMessageSource.class);
assertNotNull(source);
boolean autoStartup = TestUtils.getPropertyValue(resourceAdapter, "autoStartup", Boolean.class);
assertFalse(autoStartup);
@@ -85,16 +89,20 @@ public class ResourceInboundChannelAdapterParserTests {
@Test(expected = BeanCreationException.class)
public void testDefaultConfigNoLocationPattern() {
new ClassPathXmlApplicationContext("ResourcePatternResolver-config-fail.xml", this.getClass());
new ClassPathXmlApplicationContext("ResourcePatternResolver-config-fail.xml", this.getClass()).close();
}
@Test
public void testCustomPatternResolver() {
ApplicationContext context = new ClassPathXmlApplicationContext("ResourcePatternResolver-config-custom.xml", this.getClass());
SourcePollingChannelAdapter resourceAdapter = context.getBean("resourceAdapterDefault", SourcePollingChannelAdapter.class);
ResourceRetrievingMessageSource source = TestUtils.getPropertyValue(resourceAdapter, "source", ResourceRetrievingMessageSource.class);
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"ResourcePatternResolver-config-custom.xml", this.getClass());
SourcePollingChannelAdapter resourceAdapter = context.getBean("resourceAdapterDefault",
SourcePollingChannelAdapter.class);
ResourceRetrievingMessageSource source = TestUtils.getPropertyValue(resourceAdapter, "source",
ResourceRetrievingMessageSource.class);
assertNotNull(source);
assertEquals(context.getBean("customResolver"), TestUtils.getPropertyValue(source, "patternResolver"));
context.close();
}
@SuppressWarnings("unchecked")
@@ -106,7 +114,8 @@ public class ResourceInboundChannelAdapterParserTests {
f.createNewFile();
}
ApplicationContext context = new ClassPathXmlApplicationContext("ResourcePatternResolver-config-usage.xml", this.getClass());
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"ResourcePatternResolver-config-usage.xml", this.getClass());
QueueChannel resultChannel = context.getBean("resultChannel", QueueChannel.class);
Message<Resource[]> message = (Message<Resource[]>) resultChannel.receive(3000);
assertNotNull(message);
@@ -114,6 +123,7 @@ public class ResourceInboundChannelAdapterParserTests {
for (Resource resource : resources) {
assertTrue(resource.getURI().toString().contains("testUsage"));
}
context.close();
}
@SuppressWarnings("unchecked")
@@ -125,9 +135,12 @@ public class ResourceInboundChannelAdapterParserTests {
f.createNewFile();
}
ApplicationContext context = new ClassPathXmlApplicationContext("ResourcePatternResolver-config-usagerf.xml", this.getClass());
SourcePollingChannelAdapter resourceAdapter = context.getBean("resourceAdapterDefault", SourcePollingChannelAdapter.class);
ResourceRetrievingMessageSource source = TestUtils.getPropertyValue(resourceAdapter, "source", ResourceRetrievingMessageSource.class);
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"ResourcePatternResolver-config-usagerf.xml", this.getClass());
SourcePollingChannelAdapter resourceAdapter = context.getBean("resourceAdapterDefault",
SourcePollingChannelAdapter.class);
ResourceRetrievingMessageSource source = TestUtils.getPropertyValue(resourceAdapter, "source",
ResourceRetrievingMessageSource.class);
assertNotNull(source);
TestCollectionFilter customFilter = context.getBean("customFilter", TestCollectionFilter.class);
assertEquals(customFilter, TestUtils.getPropertyValue(source, "filter"));
@@ -138,6 +151,7 @@ public class ResourceInboundChannelAdapterParserTests {
Message<Resource[]> message = (Message<Resource[]>) resultChannel.receive(1000);
assertNotNull(message);
assertTrue(customFilter.invoked);
context.close();
}
@Test
@@ -148,11 +162,15 @@ public class ResourceInboundChannelAdapterParserTests {
f.createNewFile();
}
ApplicationContext context = new ClassPathXmlApplicationContext("ResourcePatternResolver-config-usage-emptyref.xml", this.getClass());
SourcePollingChannelAdapter resourceAdapter = context.getBean("resourceAdapterDefault", SourcePollingChannelAdapter.class);
ResourceRetrievingMessageSource source = TestUtils.getPropertyValue(resourceAdapter, "source", ResourceRetrievingMessageSource.class);
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"ResourcePatternResolver-config-usage-emptyref.xml", this.getClass());
SourcePollingChannelAdapter resourceAdapter = context.getBean("resourceAdapterDefault",
SourcePollingChannelAdapter.class);
ResourceRetrievingMessageSource source = TestUtils.getPropertyValue(resourceAdapter, "source",
ResourceRetrievingMessageSource.class);
assertNotNull(source);
assertNull(TestUtils.getPropertyValue(source, "filter"));
context.close();
}
@@ -160,6 +178,7 @@ public class ResourceInboundChannelAdapterParserTests {
private volatile boolean invoked = false;
@Override
public Collection<Resource> filter(Collection<Resource> unfilteredResources) {
this.invoked = true;
return unfilteredResources;

View File

@@ -21,11 +21,10 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.messaging.support.GenericMessage;
/**
@@ -38,7 +37,8 @@ public class ExceptionTypeRouterParserTests {
@SuppressWarnings("unchecked")
@Test
public void testExceptionTypeRouterConfig() {
ApplicationContext context = new ClassPathXmlApplicationContext("ExceptionTypeRouterParserTests-context.xml", this.getClass());
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"ExceptionTypeRouterParserTests-context.xml", this.getClass());
MessageChannel inputChannel = context.getBean("inChannel", MessageChannel.class);
inputChannel.send(new GenericMessage<Throwable>(new NullPointerException()));
@@ -56,5 +56,6 @@ public class ExceptionTypeRouterParserTests {
inputChannel.send(new GenericMessage<String>("Hello"));
QueueChannel outputChannel = context.getBean("outputChannel", QueueChannel.class);
assertNotNull(outputChannel.receive(1000));
context.close();
}
}

View File

@@ -30,12 +30,13 @@ import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.IntegrationMessageHeaderAccessor;
import org.springframework.integration.annotation.Router;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.router.AbstractMappingMessageRouter;
import org.springframework.integration.router.MethodInvokingRouter;
import org.springframework.integration.test.util.TestUtils;
@@ -47,7 +48,7 @@ import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.core.DestinationResolutionException;
import org.springframework.messaging.core.DestinationResolver;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -233,7 +234,7 @@ public class RouterParserTests {
@Test // should not fail
public void routerFactoryBeanTest() {
new ClassPathXmlApplicationContext("rfb-fix-config.xml", this.getClass());
new ClassPathXmlApplicationContext("rfb-fix-config.xml", this.getClass()).close();
}
@@ -286,6 +287,7 @@ public class RouterParserTests {
static class TestChannelResover implements DestinationResolver<MessageChannel> {
@Override
public MessageChannel resolveDestination(String channelName) {
return null;
}

View File

@@ -146,6 +146,7 @@ public class RouterWithMappingTests {
private boolean running;
@SuppressWarnings("unused")
public String route(TestBean bean) {
return bean.getName();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 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.
@@ -25,7 +25,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
@@ -34,6 +33,7 @@ import org.springframework.messaging.support.GenericMessage;
/**
* @author Mark Fisher
* @author Gary Russell
*/
public class SplitterAggregatorTests {
@@ -42,7 +42,7 @@ public class SplitterAggregatorTests {
@Test
public void testSplitterAndAggregator() {
ApplicationContext context = new ClassPathXmlApplicationContext(
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"splitterAggregatorTests.xml", this.getClass());
MessageChannel inputChannel = (MessageChannel) context.getBean("numbers");
PollableChannel outputChannel = (PollableChannel) context.getBean("results");
@@ -56,6 +56,7 @@ public class SplitterAggregatorTests {
assertNotNull(result2);
assertEquals(Integer.class, result2.getPayload().getClass());
assertEquals(155, result2.getPayload());
context.close();
}
private Numbers nextTen() {

View File

@@ -101,7 +101,6 @@ public class RoutingSlipTests {
MessageHistory messageHistory = MessageHistory.read(message);
List<String> channelNames = Arrays.asList("input", "split", "process", "channel1", "channel2",
"channel3", "channel4", "channel5", "aggregate");
int i = 0;
for (Properties properties : messageHistory) {
assertTrue(channelNames.contains(properties.getProperty("name")));
}
@@ -163,7 +162,7 @@ public class RoutingSlipTests {
public static class TestRoutingSlipRouteStrategy implements RoutingSlipRouteStrategy {
private AtomicBoolean invoked = new AtomicBoolean();
private final AtomicBoolean invoked = new AtomicBoolean();
@Override
public Object getNextPath(Message<?> requestMessage, Object reply) {

View File

@@ -90,6 +90,7 @@ public class MapToObjectTransformerTests {
assertNull(person.getSsn());
assertNotNull(person.getAddress());
assertEquals("1123 Main st", person.getAddress().getStreet());
ac.close();
}
@Test

View File

@@ -27,7 +27,6 @@ import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.convert.TypeDescriptor;
@@ -39,12 +38,12 @@ import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.IntegrationEvaluationContextFactoryBean;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.handler.ReplyRequiredException;
import org.springframework.messaging.support.GenericMessage;
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.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.Assert;
@@ -82,9 +81,6 @@ public class SpelTransformerIntegrationTests {
@Autowired
private IntegrationEvaluationContextFactoryBean evaluationContextFactoryBean;
@Autowired
private BeanFactory beanFactory;
@Test
public void simple() {
Message<?> message = MessageBuilder.withPayload(new TestBean()).setHeader("bar", 123).build();

View File

@@ -45,15 +45,15 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.ResolvableType;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.integration.event.core.MessagingEvent;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
/**
* @author Mark Fisher
@@ -85,7 +85,6 @@ public class ApplicationEventListeningMessageProducerTests {
}
@Test
@SuppressWarnings("unchecked")
public void onlyConfiguredEventTypesAreSent() {
QueueChannel channel = new QueueChannel();
ApplicationEventListeningMessageProducer adapter = new ApplicationEventListeningMessageProducer();
@@ -347,6 +346,7 @@ public class ApplicationEventListeningMessageProducerTests {
this.counter = counter;
}
@Override
public void onApplicationEvent(ApplicationEvent event) {
this.counter.incrementAndGet();
}