use of org.springframework.context.support.StaticApplicationContext in project spring-integration by spring-projects.
the class AsyncMessagingTemplateTests method asyncConvertSendAndReceiveWithResolvedChannelAndMessagePostProcessor.
@Test
public void asyncConvertSendAndReceiveWithResolvedChannelAndMessagePostProcessor() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton("testChannel", DirectChannel.class);
context.refresh();
DirectChannel channel = context.getBean("testChannel", DirectChannel.class);
channel.subscribe(new EchoHandler(200));
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
template.setBeanFactory(context);
long start = System.currentTimeMillis();
Future<String> result = template.asyncConvertSendAndReceive("testChannel", "test", new TestMessagePostProcessor());
assertNotNull(result.get());
long elapsed = System.currentTimeMillis() - start;
assertTrue(elapsed >= 200 - safety);
assertEquals("TEST-bar", result.get());
}
use of org.springframework.context.support.StaticApplicationContext in project spring-integration by spring-projects.
the class MapToObjectTransformerTests method testMapToObjectTransformationWithPrototype.
@Test
public void testMapToObjectTransformationWithPrototype() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("fname", "Justin");
map.put("lname", "Case");
Address address = new Address();
address.setStreet("1123 Main st");
map.put("address", address);
Message<?> message = MessageBuilder.withPayload(map).build();
StaticApplicationContext ac = new StaticApplicationContext();
ac.registerPrototype("person", Person.class);
MapToObjectTransformer transformer = new MapToObjectTransformer("person");
transformer.setBeanFactory(ac.getBeanFactory());
Message<?> newMessage = transformer.transform(message);
Person person = (Person) newMessage.getPayload();
assertNotNull(person);
assertEquals("Justin", person.getFname());
assertEquals("Case", person.getLname());
assertNull(person.getSsn());
assertNotNull(person.getAddress());
assertEquals("1123 Main st", person.getAddress().getStreet());
ac.close();
}
use of org.springframework.context.support.StaticApplicationContext in project spring-integration by spring-projects.
the class HeaderValueRouterTests method resolveMultipleChannelsWithCommaDelimitedString.
@Test
public void resolveMultipleChannelsWithCommaDelimitedString() {
StaticApplicationContext context = new StaticApplicationContext();
RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
context.registerBeanDefinition("router", routerBeanDefinition);
context.registerBeanDefinition("channel1", new RootBeanDefinition(QueueChannel.class));
context.registerBeanDefinition("channel2", new RootBeanDefinition(QueueChannel.class));
context.refresh();
MessageHandler handler = (MessageHandler) context.getBean("router");
String channels = "channel1, channel2";
Message<?> message = MessageBuilder.withPayload("test").setHeader("testHeaderName", channels).build();
handler.handleMessage(message);
QueueChannel channel1 = (QueueChannel) context.getBean("channel1");
QueueChannel channel2 = (QueueChannel) context.getBean("channel2");
Message<?> result1 = channel1.receive(1000);
Message<?> result2 = channel2.receive(1000);
assertNotNull(result1);
assertNotNull(result2);
assertSame(message, result1);
assertSame(message, result2);
context.close();
}
use of org.springframework.context.support.StaticApplicationContext in project spring-integration by spring-projects.
the class HeaderValueRouterTests method resolveChannelNameFromMap.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void resolveChannelNameFromMap() {
StaticApplicationContext context = new StaticApplicationContext();
ManagedMap channelMappings = new ManagedMap();
channelMappings.put("testKey", "testChannel");
RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
routerBeanDefinition.getPropertyValues().addPropertyValue("channelMappings", channelMappings);
routerBeanDefinition.getPropertyValues().addPropertyValue("beanFactory", context);
context.registerBeanDefinition("router", routerBeanDefinition);
context.registerBeanDefinition("testChannel", new RootBeanDefinition(QueueChannel.class));
context.refresh();
MessageHandler handler = (MessageHandler) context.getBean("router");
Message<?> message = MessageBuilder.withPayload("test").setHeader("testHeaderName", "testKey").build();
handler.handleMessage(message);
QueueChannel channel = (QueueChannel) context.getBean("testChannel");
Message<?> result = channel.receive(1000);
assertNotNull(result);
assertSame(message, result);
context.close();
}
use of org.springframework.context.support.StaticApplicationContext in project spring-integration by spring-projects.
the class HeaderValueRouterTests method resolveChannelNameFromContext.
@Test
public void resolveChannelNameFromContext() {
StaticApplicationContext context = new StaticApplicationContext();
RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
context.registerBeanDefinition("router", routerBeanDefinition);
context.registerBeanDefinition("testChannel", new RootBeanDefinition(QueueChannel.class));
context.registerBeanDefinition("newChannel", new RootBeanDefinition(QueueChannel.class));
context.refresh();
MessageHandler handler = (MessageHandler) context.getBean("router");
Message<?> message = MessageBuilder.withPayload("test").setHeader("testHeaderName", "testChannel").build();
handler.handleMessage(message);
QueueChannel channel = (QueueChannel) context.getBean("testChannel");
Message<?> result = channel.receive(1000);
assertNotNull(result);
assertSame(message, result);
// validate dynamics
HeaderValueRouter router = (HeaderValueRouter) context.getBean("router");
router.setChannelMapping("testChannel", "newChannel");
router.handleMessage(message);
QueueChannel newChannel = (QueueChannel) context.getBean("newChannel");
result = newChannel.receive(10);
assertNotNull(result);
router.removeChannelMapping("testChannel");
router.handleMessage(message);
result = channel.receive(1000);
assertNotNull(result);
assertSame(message, result);
context.close();
}
Aggregations