INT-1338, Added namespace support for 'event-types' attribute

This commit is contained in:
Oleg Zhurakousky
2010-08-23 17:09:32 +00:00
parent 7816d5f681
commit 78dbf2bef5
7 changed files with 99 additions and 15 deletions

View File

@@ -16,14 +16,11 @@
package org.springframework.integration.event;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
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;
import org.springframework.context.event.ContextRefreshedEvent;
@@ -34,6 +31,10 @@ import org.springframework.integration.Message;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.core.PollableChannel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/**
* @author Mark Fisher
*/
@@ -61,7 +62,9 @@ public class ApplicationEventInboundChannelAdapterTests {
QueueChannel channel = new QueueChannel();
ApplicationEventInboundChannelAdapter adapter = new ApplicationEventInboundChannelAdapter();
adapter.setOutputChannel(channel);
adapter.setEventTypes(Collections.<Class<? extends ApplicationEvent>>singletonList(TestApplicationEvent1.class));
Set<Class<? extends ApplicationEvent>> events = new HashSet<Class<? extends ApplicationEvent>>();
events.add(TestApplicationEvent1.class);
adapter.setEventTypes(events);
Message<?> message1 = channel.receive(0);
assertNull(message1);
adapter.onApplicationEvent(new TestApplicationEvent1());

View File

@@ -7,10 +7,17 @@
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">
<int-event:inbound-channel-adapter id="eventAdapter" channel="input"/>
<int-event:inbound-channel-adapter id="eventAdapterSimple" channel="input"/>
<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,
org.springframework.integration.event.config.EventInboundChannelAdapterParserTests$SampleEvent"/>
<int:channel id="inputFiltered">
<int:queue/>
</int:channel>
</beans>

View File

@@ -18,6 +18,10 @@ package org.springframework.integration.event.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Set;
import junit.framework.Assert;
import org.junit.Test;
@@ -49,12 +53,27 @@ public class EventInboundChannelAdapterParserTests {
@Test
public void validateEventParser() {
Object adapter = context.getBean("eventAdapter");
Object adapter = context.getBean("eventAdapterSimple");
Assert.assertNotNull(adapter);
Assert.assertTrue(adapter instanceof ApplicationEventInboundChannelAdapter);
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
Assert.assertEquals(context.getBean("input"), adapterAccessor.getPropertyValue("outputChannel"));
}
@SuppressWarnings("unchecked")
@Test
public void validateEventParserWithEventTypes() {
Object adapter = context.getBean("eventAdapterFiltered");
Assert.assertNotNull(adapter);
Assert.assertTrue(adapter instanceof ApplicationEventInboundChannelAdapter);
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
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.contains(SampleEvent.class));
assertTrue(eventTypes.contains(AnotherSampleEvent.class));
}
@Test
public void validateUsage() {
@@ -69,11 +88,15 @@ public class EventInboundChannelAdapterParserTests {
@SuppressWarnings("serial")
public static class SampleEvent extends ApplicationEvent {
public SampleEvent(Object source) {
super(source);
}
}
@SuppressWarnings("serial")
public static class AnotherSampleEvent extends ApplicationEvent {
public AnotherSampleEvent(Object source) {
super(source);
}
}
}