use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.
the class PublishSubscribeChannelParserTests method channelWithTaskExecutor.
@Test
public void channelWithTaskExecutor() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("channelWithTaskExecutor");
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
Executor executor = (Executor) dispatcherAccessor.getPropertyValue("executor");
assertNotNull(executor);
assertEquals(ErrorHandlingTaskExecutor.class, executor.getClass());
DirectFieldAccessor executorAccessor = new DirectFieldAccessor(executor);
Executor innerExecutor = (Executor) executorAccessor.getPropertyValue("executor");
assertEquals(context.getBean("pool"), innerExecutor);
context.close();
}
use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.
the class PublishSubscribeChannelParserTests method applySequenceEnabled.
@Test
public void applySequenceEnabled() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("channelWithApplySequenceEnabled");
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
assertTrue((Boolean) new DirectFieldAccessor(dispatcher).getPropertyValue("applySequence"));
context.close();
}
use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.
the class MessageProducerSupportTests method validateExceptionIfSendToErrorChannelFails.
@Test(expected = MessageDeliveryException.class)
public void validateExceptionIfSendToErrorChannelFails() {
DirectChannel outChannel = new DirectChannel();
outChannel.subscribe(message -> {
throw new RuntimeException("problems");
});
PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
errorChannel.subscribe(message -> {
throw new RuntimeException("ooops");
});
MessageProducerSupport mps = new MessageProducerSupport() {
};
mps.setOutputChannel(outChannel);
mps.setErrorChannel(errorChannel);
mps.setBeanFactory(TestUtils.createTestApplicationContext());
mps.afterPropertiesSet();
mps.start();
mps.sendMessage(new GenericMessage<String>("hello"));
}
use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.
the class MessageProducerSupportTests method validateSuccessfulErrorFlowDoesNotThrowErrors.
@Test
public void validateSuccessfulErrorFlowDoesNotThrowErrors() {
TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
testApplicationContext.refresh();
DirectChannel outChannel = new DirectChannel();
outChannel.subscribe(message -> {
throw new RuntimeException("problems");
});
PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
SuccessfulErrorService errorService = new SuccessfulErrorService();
ServiceActivatingHandler handler = new ServiceActivatingHandler(errorService);
handler.setBeanFactory(testApplicationContext);
handler.afterPropertiesSet();
errorChannel.subscribe(handler);
MessageProducerSupport mps = new MessageProducerSupport() {
};
mps.setOutputChannel(outChannel);
mps.setErrorChannel(errorChannel);
mps.setBeanFactory(testApplicationContext);
mps.afterPropertiesSet();
mps.start();
Message<?> message = new GenericMessage<String>("hello");
mps.sendMessage(message);
assertThat(errorService.lastMessage, instanceOf(ErrorMessage.class));
ErrorMessage errorMessage = (ErrorMessage) errorService.lastMessage;
assertEquals(MessageDeliveryException.class, errorMessage.getPayload().getClass());
MessageDeliveryException exception = (MessageDeliveryException) errorMessage.getPayload();
assertEquals(message, exception.getFailedMessage());
testApplicationContext.close();
}
use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.
the class MessagingGatewayTests method validateErroMessageCanNotBeReplyMessage.
// should fail but it doesn't now
@Test(expected = MessagingException.class)
public void validateErroMessageCanNotBeReplyMessage() {
DirectChannel reqChannel = new DirectChannel();
reqChannel.subscribe(message -> {
throw new RuntimeException("ooops");
});
PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
ServiceActivatingHandler handler = new ServiceActivatingHandler(new MyErrorService());
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
errorChannel.subscribe(handler);
this.messagingGateway = new MessagingGatewaySupport() {
};
this.messagingGateway.setRequestChannel(reqChannel);
this.messagingGateway.setErrorChannel(errorChannel);
this.messagingGateway.setReplyChannel(null);
this.messagingGateway.setBeanFactory(mock(BeanFactory.class));
this.messagingGateway.afterPropertiesSet();
this.messagingGateway.start();
this.messagingGateway.sendAndReceiveMessage("hello");
}
Aggregations