use of org.springframework.context.support.StaticApplicationContext in project spring-integration by spring-projects.
the class DelayHandlerTests method errorChannelNameHeaderAndHandlerThrowsExceptionWithDelay.
@Test
public void errorChannelNameHeaderAndHandlerThrowsExceptionWithDelay() throws Exception {
String errorChannelName = "customErrorChannel";
StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton(errorChannelName, DirectChannel.class);
context.registerSingleton(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, DirectChannel.class);
context.refresh();
DirectChannel customErrorChannel = (DirectChannel) context.getBean(errorChannelName);
MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler();
errorHandler.setBeanFactory(context);
taskScheduler.setErrorHandler(errorHandler);
this.setDelayExpression();
this.startDelayerHandler();
output.unsubscribe(resultHandler);
customErrorChannel.subscribe(resultHandler);
output.subscribe(message -> {
throw new UnsupportedOperationException("intentional test failure");
});
Message<?> message = MessageBuilder.withPayload("test").setHeader("delay", "10").setErrorChannelName(errorChannelName).build();
input.send(message);
waitForLatch(10000);
Message<?> errorMessage = resultHandler.lastMessage;
assertEquals(MessageDeliveryException.class, errorMessage.getPayload().getClass());
MessageDeliveryException exceptionPayload = (MessageDeliveryException) errorMessage.getPayload();
assertSame(message.getPayload(), exceptionPayload.getFailedMessage().getPayload());
assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass());
assertNotSame(Thread.currentThread(), resultHandler.lastThread);
}
use of org.springframework.context.support.StaticApplicationContext in project spring-integration by spring-projects.
the class DelayHandlerTests method defaultErrorChannelAndHandlerThrowsExceptionWithDelay.
@Test
public void defaultErrorChannelAndHandlerThrowsExceptionWithDelay() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, DirectChannel.class);
context.refresh();
DirectChannel defaultErrorChannel = (DirectChannel) context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler();
errorHandler.setBeanFactory(context);
taskScheduler.setErrorHandler(errorHandler);
this.setDelayExpression();
this.startDelayerHandler();
output.unsubscribe(resultHandler);
defaultErrorChannel.subscribe(resultHandler);
output.subscribe(message -> {
throw new UnsupportedOperationException("intentional test failure");
});
Message<?> message = MessageBuilder.withPayload("test").setHeader("delay", "10").build();
input.send(message);
waitForLatch(10000);
Message<?> errorMessage = resultHandler.lastMessage;
assertEquals(MessageDeliveryException.class, errorMessage.getPayload().getClass());
MessageDeliveryException exceptionPayload = (MessageDeliveryException) errorMessage.getPayload();
assertSame(message.getPayload(), exceptionPayload.getFailedMessage().getPayload());
assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass());
assertNotSame(Thread.currentThread(), resultHandler.lastThread);
}
use of org.springframework.context.support.StaticApplicationContext in project spring-integration by spring-projects.
the class ExpressionEvaluatingMessageProcessorTests method testProcessMessageWithMethodCallOnBean.
@Test
public void testProcessMessageWithMethodCallOnBean() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinition beanDefinition = new RootBeanDefinition(String.class);
beanDefinition.getConstructorArgumentValues().addGenericArgumentValue("bar");
context.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME, new RootBeanDefinition(IntegrationEvaluationContextFactoryBean.class));
context.registerBeanDefinition("testString", beanDefinition);
context.refresh();
Expression expression = expressionParser.parseExpression("@testString.concat(payload)");
ExpressionEvaluatingMessageProcessor<String> processor = new ExpressionEvaluatingMessageProcessor<>(expression);
processor.setBeanFactory(context);
processor.afterPropertiesSet();
GenericMessage<String> message = new GenericMessage<>("foo");
assertEquals("barfoo", processor.processMessage(message));
}
use of org.springframework.context.support.StaticApplicationContext in project spring-integration by spring-projects.
the class AsyncMessagingTemplateTests method asyncReceiveAndConvertWithResolvedChannel.
@Test
public void asyncReceiveAndConvertWithResolvedChannel() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton("testChannel", QueueChannel.class);
context.refresh();
QueueChannel channel = context.getBean("testChannel", QueueChannel.class);
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
template.setBeanFactory(context);
Future<?> result = template.asyncReceiveAndConvert("testChannel");
sendMessageAfterDelay(channel, new GenericMessage<String>("test"), 200);
long start = System.currentTimeMillis();
assertNotNull(result.get(10000, TimeUnit.MILLISECONDS));
long elapsed = System.currentTimeMillis() - start;
assertTrue(elapsed >= 200 - safety);
assertEquals("test", result.get());
}
use of org.springframework.context.support.StaticApplicationContext in project spring-integration by spring-projects.
the class AsyncMessagingTemplateTests method asyncConvertAndSendWithResolvedChannel.
@Test
public void asyncConvertAndSendWithResolvedChannel() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton("testChannel", QueueChannel.class);
context.refresh();
QueueChannel channel = context.getBean("testChannel", QueueChannel.class);
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
template.setBeanFactory(context);
Future<?> future = template.asyncConvertAndSend("testChannel", "test");
assertNull(future.get(10000, TimeUnit.MILLISECONDS));
Message<?> result = channel.receive(0);
assertEquals("test", result.getPayload());
}
Aggregations