INT-3161: EventChannelAdapter: fix 'auto-startup'
JIRA: https://jira.springsource.org/browse/INT-3161
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -41,6 +41,7 @@ public class EventInboundChannelAdapterParser extends AbstractChannelAdapterPars
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(adapterBuilder, element, "error-channel", "errorChannel");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, element, "event-types");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, element, "payload-expression");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, element, "auto-startup");
|
||||
return adapterBuilder.getBeanDefinition();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,20 +12,21 @@
|
||||
<int:message-history/>
|
||||
|
||||
<int-event:inbound-channel-adapter id="eventAdapterSimple" channel="input"
|
||||
error-channel="errorChannel"/>
|
||||
error-channel="errorChannel"
|
||||
auto-startup="false"/>
|
||||
|
||||
<int:channel id="input">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int-event:inbound-channel-adapter id="eventAdapterFiltered" channel="inputFiltered" event-types="org.springframework.integration.event.config.EventInboundChannelAdapterParserTests$AnotherSampleEvent,
|
||||
|
||||
<int-event:inbound-channel-adapter id="eventAdapterFiltered" channel="inputFiltered" event-types="org.springframework.integration.event.config.EventInboundChannelAdapterParserTests$AnotherSampleEvent,
|
||||
org.springframework.integration.event.config.EventInboundChannelAdapterParserTests$SampleEvent"/>
|
||||
|
||||
<int:channel id="inputFiltered">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int-event:inbound-channel-adapter id="eventAdapterFilteredPlaceHolder" channel="inputFilteredPlaceHolder"
|
||||
|
||||
<int-event:inbound-channel-adapter id="eventAdapterFilteredPlaceHolder" channel="inputFilteredPlaceHolder"
|
||||
event-types="${event.types}"/>
|
||||
|
||||
<int:channel id="inputFilteredPlaceHolder">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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,8 +25,6 @@ import static org.junit.Assert.assertTrue;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -35,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.integration.Message;
|
||||
@@ -43,9 +42,12 @@ import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
@@ -69,6 +71,7 @@ public class EventInboundChannelAdapterParserTests {
|
||||
ApplicationEventListeningMessageProducer eventListener;
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void validateEventParser() {
|
||||
Object adapter = context.getBean("eventAdapterSimple");
|
||||
Assert.assertNotNull(adapter);
|
||||
@@ -76,6 +79,7 @@ public class EventInboundChannelAdapterParserTests {
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
Assert.assertEquals(context.getBean("input"), adapterAccessor.getPropertyValue("outputChannel"));
|
||||
Assert.assertSame(errorChannel, adapterAccessor.getPropertyValue("errorChannel"));
|
||||
Assert.assertFalse((Boolean) adapterAccessor.getPropertyValue("active"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,7 +92,7 @@ public class EventInboundChannelAdapterParserTests {
|
||||
Assert.assertEquals(context.getBean("inputFiltered"), adapterAccessor.getPropertyValue("outputChannel"));
|
||||
Set<Class<? extends ApplicationEvent>> eventTypes = (Set<Class<? extends ApplicationEvent>>) adapterAccessor.getPropertyValue("eventTypes");
|
||||
assertNotNull(eventTypes);
|
||||
assertTrue(eventTypes.size() == 2);
|
||||
assertTrue(eventTypes.size() == 2);
|
||||
assertTrue(eventTypes.contains(SampleEvent.class));
|
||||
assertTrue(eventTypes.contains(AnotherSampleEvent.class));
|
||||
assertNull(adapterAccessor.getPropertyValue("errorChannel"));
|
||||
@@ -104,13 +108,16 @@ public class EventInboundChannelAdapterParserTests {
|
||||
Assert.assertEquals(context.getBean("inputFilteredPlaceHolder"), adapterAccessor.getPropertyValue("outputChannel"));
|
||||
Set<Class<? extends ApplicationEvent>> eventTypes = (Set<Class<? extends ApplicationEvent>>) adapterAccessor.getPropertyValue("eventTypes");
|
||||
assertNotNull(eventTypes);
|
||||
assertTrue(eventTypes.size() == 2);
|
||||
assertTrue(eventTypes.size() == 2);
|
||||
assertTrue(eventTypes.contains(SampleEvent.class));
|
||||
assertTrue(eventTypes.contains(AnotherSampleEvent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void validateUsageWithHistory() {
|
||||
Lifecycle eventAdapterFiltered = context.getBean("eventAdapterSimple", Lifecycle.class);
|
||||
eventAdapterFiltered.start();
|
||||
PollableChannel channel = context.getBean("input", PollableChannel.class);
|
||||
assertEquals(ContextRefreshedEvent.class, channel.receive(0).getPayload().getClass());
|
||||
context.publishEvent(new SampleEvent("hello"));
|
||||
|
||||
Reference in New Issue
Block a user