adding MessagingGatewaySupport tests for error-channel
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.gateway;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.eq;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
@@ -37,7 +38,13 @@ import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.MessageDeliveryException;
|
||||
import org.springframework.integration.MessageHeaders;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.PublishSubscribeChannel;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.handler.ServiceActivatingHandler;
|
||||
import org.springframework.integration.message.ErrorMessage;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
|
||||
/**
|
||||
@@ -228,5 +235,69 @@ public class MessagingGatewayTests {
|
||||
verify(allmocks);
|
||||
}
|
||||
}
|
||||
|
||||
// should fail but it doesn't now
|
||||
@Test(expected=MessagingException.class)
|
||||
@Ignore
|
||||
public void validateErroMessageCanNotBeReplyMessage() {
|
||||
DirectChannel reqChannel = new DirectChannel();
|
||||
reqChannel.subscribe(new MessageHandler() {
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
throw new RuntimeException("ooops");
|
||||
}
|
||||
});
|
||||
PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
|
||||
ServiceActivatingHandler handler = new ServiceActivatingHandler(new MyErrorService());
|
||||
handler.afterPropertiesSet();
|
||||
errorChannel.subscribe(handler);
|
||||
this.messagingGateway = new MessagingGatewaySupport() {};
|
||||
|
||||
this.messagingGateway.setRequestChannel(reqChannel);
|
||||
this.messagingGateway.setErrorChannel(errorChannel);
|
||||
this.messagingGateway.setBeanFactory(TestUtils.createTestApplicationContext());
|
||||
this.messagingGateway.afterPropertiesSet();
|
||||
this.messagingGateway.start();
|
||||
|
||||
this.messagingGateway.sendAndReceiveMessage("hello");
|
||||
|
||||
}
|
||||
|
||||
|
||||
// should not fail but it does now
|
||||
@Test
|
||||
@Ignore
|
||||
public void validateErrorChannelWithSuccessfullReply() {
|
||||
DirectChannel reqChannel = new DirectChannel();
|
||||
reqChannel.subscribe(new MessageHandler() {
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
throw new RuntimeException("ooops");
|
||||
}
|
||||
});
|
||||
PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
|
||||
ServiceActivatingHandler handler = new ServiceActivatingHandler(new MyOneWayErrorService());
|
||||
handler.afterPropertiesSet();
|
||||
errorChannel.subscribe(handler);
|
||||
this.messagingGateway = new MessagingGatewaySupport() {};
|
||||
|
||||
this.messagingGateway.setRequestChannel(reqChannel);
|
||||
this.messagingGateway.setErrorChannel(errorChannel);
|
||||
this.messagingGateway.setBeanFactory(TestUtils.createTestApplicationContext());
|
||||
this.messagingGateway.afterPropertiesSet();
|
||||
this.messagingGateway.start();
|
||||
|
||||
this.messagingGateway.send("hello");
|
||||
}
|
||||
|
||||
public static class MyErrorService {
|
||||
public Message<?> handleErrorMessage(Message<?> errorMessage){
|
||||
return errorMessage;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyOneWayErrorService {
|
||||
public void handleErrorMessage(Message<?> errorMessage){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user