Search in sources :

Example 11 with StaticApplicationContext

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());
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 12 with StaticApplicationContext

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();
}
Also used : HashMap(java.util.HashMap) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.Test)

Example 13 with StaticApplicationContext

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();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) MessageHandler(org.springframework.messaging.MessageHandler) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 14 with StaticApplicationContext

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();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) MessageHandler(org.springframework.messaging.MessageHandler) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ManagedMap(org.springframework.beans.factory.support.ManagedMap) Test(org.junit.Test)

Example 15 with StaticApplicationContext

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();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) MessageHandler(org.springframework.messaging.MessageHandler) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Aggregations

StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)322 Test (org.junit.jupiter.api.Test)218 lombok.val (lombok.val)159 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)59 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)39 BeforeEach (org.junit.jupiter.api.BeforeEach)36 Test (org.junit.Test)34 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)31 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)25 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)20 HashSet (java.util.HashSet)19 MockRequestContext (org.springframework.webflow.test.MockRequestContext)19 InMemoryServiceRegistry (org.apereo.cas.services.InMemoryServiceRegistry)16 MockServletContext (org.springframework.mock.web.MockServletContext)16 MultifactorAuthenticationProviderBypassProperties (org.apereo.cas.configuration.model.support.mfa.MultifactorAuthenticationProviderBypassProperties)15 BeanDefinitionReader (org.springframework.beans.factory.support.BeanDefinitionReader)13 ApplicationContext (org.springframework.context.ApplicationContext)12 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 QueueChannel (org.springframework.integration.channel.QueueChannel)11