INT-1338, Added support for property placeholder
This commit is contained in:
@@ -16,10 +16,6 @@
|
||||
|
||||
package org.springframework.integration.event;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
@@ -57,14 +53,13 @@ public class ApplicationEventInboundChannelAdapterTests {
|
||||
assertEquals("event2", ((ApplicationEvent) message3.getPayload()).getSource());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void onlyConfiguredEventTypesAreSent() {
|
||||
QueueChannel channel = new QueueChannel();
|
||||
ApplicationEventInboundChannelAdapter adapter = new ApplicationEventInboundChannelAdapter();
|
||||
adapter.setOutputChannel(channel);
|
||||
Set<Class<? extends ApplicationEvent>> events = new HashSet<Class<? extends ApplicationEvent>>();
|
||||
events.add(TestApplicationEvent1.class);
|
||||
adapter.setEventTypes(events);
|
||||
adapter.setEventTypes(new Class[]{TestApplicationEvent1.class});
|
||||
Message<?> message1 = channel.receive(0);
|
||||
assertNull(message1);
|
||||
adapter.onApplicationEvent(new TestApplicationEvent1());
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-event="http://www.springframework.org/schema/integration/event"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/event http://www.springframework.org/schema/integration/event/spring-integration-event-2.0.xsd">
|
||||
http://www.springframework.org/schema/integration/event http://www.springframework.org/schema/integration/event/spring-integration-event-2.0.xsd"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-event="http://www.springframework.org/schema/integration/event">
|
||||
|
||||
<int-event:inbound-channel-adapter id="eventAdapterSimple" channel="input"/>
|
||||
|
||||
@@ -19,5 +21,14 @@
|
||||
<int:channel id="inputFiltered">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int-event:inbound-channel-adapter id="eventAdapterFilteredPlaceHolder" channel="inputFilteredPlaceHolder"
|
||||
event-types="${event.types}"/>
|
||||
|
||||
<int:channel id="inputFilteredPlaceHolder">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<context:property-placeholder location="classpath:org/springframework/integration/event/config/inbound-adapter.properties"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -74,6 +74,21 @@ public class EventInboundChannelAdapterParserTests {
|
||||
assertTrue(eventTypes.contains(SampleEvent.class));
|
||||
assertTrue(eventTypes.contains(AnotherSampleEvent.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void validateEventParserWithEventTypesAndPlaceholder() {
|
||||
Object adapter = context.getBean("eventAdapterFilteredPlaceHolder");
|
||||
Assert.assertNotNull(adapter);
|
||||
Assert.assertTrue(adapter instanceof ApplicationEventInboundChannelAdapter);
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
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.contains(SampleEvent.class));
|
||||
assertTrue(eventTypes.contains(AnotherSampleEvent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateUsage() {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
event.types=org.springframework.integration.event.config.EventInboundChannelAdapterParserTests$AnotherSampleEvent, org.springframework.integration.event.config.EventInboundChannelAdapterParserTests$SampleEvent
|
||||
Reference in New Issue
Block a user