INT-1624 Add error-channel to event inbound channel adapter XSD, Parser, Test
This commit is contained in:
@@ -11,7 +11,8 @@
|
||||
|
||||
<int:message-history/>
|
||||
|
||||
<int-event:inbound-channel-adapter id="eventAdapterSimple" channel="input"/>
|
||||
<int-event:inbound-channel-adapter id="eventAdapterSimple" channel="input"
|
||||
error-channel="errorChannel"/>
|
||||
|
||||
<int:channel id="input">
|
||||
<int:queue/>
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.event.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Properties;
|
||||
@@ -35,6 +36,7 @@ import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
@@ -54,6 +56,8 @@ public class EventInboundChannelAdapterParserTests {
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
MessageChannel errorChannel;
|
||||
|
||||
@Test
|
||||
public void validateEventParser() {
|
||||
@@ -62,6 +66,7 @@ public class EventInboundChannelAdapterParserTests {
|
||||
Assert.assertTrue(adapter instanceof ApplicationEventListeningMessageProducer);
|
||||
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
|
||||
Assert.assertEquals(context.getBean("input"), adapterAccessor.getPropertyValue("outputChannel"));
|
||||
Assert.assertSame(errorChannel, adapterAccessor.getPropertyValue("errorChannel"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,6 +82,7 @@ public class EventInboundChannelAdapterParserTests {
|
||||
assertTrue(eventTypes.size() == 2);
|
||||
assertTrue(eventTypes.contains(SampleEvent.class));
|
||||
assertTrue(eventTypes.contains(AnotherSampleEvent.class));
|
||||
assertNull(adapterAccessor.getPropertyValue("errorChannel"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,9 +19,9 @@ package org.springframework.integration.event.inbound;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
@@ -29,10 +29,14 @@ import org.springframework.context.event.ContextStartedEvent;
|
||||
import org.springframework.context.event.ContextStoppedEvent;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.event.core.MessagingEvent;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.test.annotation.ExpectedException;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -145,6 +149,30 @@ public class ApplicationEventListeningMessageProducerTests {
|
||||
assertEquals("test", message2.getPayload());
|
||||
}
|
||||
|
||||
@Test @ExpectedException(value=MessageHandlingException.class)
|
||||
public void anyApplicationEventCausesExceptionWithErrorHandling() {
|
||||
DirectChannel channel = new DirectChannel();
|
||||
channel.subscribe(new AbstractReplyProducingMessageHandler() {
|
||||
protected Object handleRequestMessage(Message<?> requestMessage) {
|
||||
throw new RuntimeException("Failed");
|
||||
}
|
||||
});
|
||||
ApplicationEventListeningMessageProducer adapter = new ApplicationEventListeningMessageProducer();
|
||||
adapter.setOutputChannel(channel);
|
||||
QueueChannel errorChannel = new QueueChannel();
|
||||
adapter.setErrorChannel(errorChannel);
|
||||
adapter.start();
|
||||
adapter.onApplicationEvent(new TestApplicationEvent1());
|
||||
Message<?> message = errorChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals("Failed", ((Exception) message.getPayload()).getCause().getMessage());
|
||||
adapter.setErrorChannel(null);
|
||||
try {
|
||||
adapter.onApplicationEvent(new TestApplicationEvent1());
|
||||
fail("Expected MessageHandlingException");
|
||||
} catch (MessageHandlingException e) { }
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class TestApplicationEvent1 extends ApplicationEvent {
|
||||
|
||||
Reference in New Issue
Block a user