Search in sources :

Example 6 with JmsListenerContainerTestFactory

use of org.springframework.jms.config.JmsListenerContainerTestFactory in project spring-framework by spring-projects.

the class EnableJmsTests method lazyComponent.

@Test
public void lazyComponent() {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EnableJmsDefaultContainerFactoryConfig.class, LazyBean.class);
    JmsListenerContainerTestFactory defaultFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
    assertEquals(0, defaultFactory.getListenerContainers().size());
    // trigger lazy resolution
    context.getBean(LazyBean.class);
    assertEquals(1, defaultFactory.getListenerContainers().size());
    MessageListenerTestContainer container = defaultFactory.getListenerContainers().get(0);
    assertTrue("Should have been started " + container, container.isStarted());
    // close and stop the listeners
    context.close();
    assertTrue("Should have been stopped " + container, container.isStopped());
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MessageListenerTestContainer(org.springframework.jms.config.MessageListenerTestContainer) JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory) Test(org.junit.Test)

Example 7 with JmsListenerContainerTestFactory

use of org.springframework.jms.config.JmsListenerContainerTestFactory in project spring-framework by spring-projects.

the class JmsListenerAnnotationBeanPostProcessorTests method simpleMessageListener.

@Test
public void simpleMessageListener() throws Exception {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class, SimpleMessageListenerTestBean.class);
    JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
    assertEquals("One container should have been registered", 1, factory.getListenerContainers().size());
    MessageListenerTestContainer container = factory.getListenerContainers().get(0);
    JmsListenerEndpoint endpoint = container.getEndpoint();
    assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
    MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
    assertEquals(SimpleMessageListenerTestBean.class, methodEndpoint.getBean().getClass());
    assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMethod());
    assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod());
    SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
    methodEndpoint.setupListenerContainer(listenerContainer);
    assertNotNull(listenerContainer.getMessageListener());
    assertTrue("Should have been started " + container, container.isStarted());
    // Close and stop the listeners
    context.close();
    assertTrue("Should have been stopped " + container, container.isStopped());
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AbstractJmsListenerEndpoint(org.springframework.jms.config.AbstractJmsListenerEndpoint) JmsListenerEndpoint(org.springframework.jms.config.JmsListenerEndpoint) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MessageListenerTestContainer(org.springframework.jms.config.MessageListenerTestContainer) SimpleMessageListenerContainer(org.springframework.jms.listener.SimpleMessageListenerContainer) JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint) Test(org.junit.Test)

Example 8 with JmsListenerContainerTestFactory

use of org.springframework.jms.config.JmsListenerContainerTestFactory in project spring-framework by spring-projects.

the class EnableJmsTests method composedJmsListeners.

@Test
public void composedJmsListeners() {
    try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EnableJmsDefaultContainerFactoryConfig.class, ComposedJmsListenersBean.class)) {
        JmsListenerContainerTestFactory simpleFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
        assertEquals(2, simpleFactory.getListenerContainers().size());
        MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer("first").getEndpoint();
        assertEquals("first", first.getId());
        assertEquals("orderQueue", first.getDestination());
        assertNull(first.getConcurrency());
        MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer("second").getEndpoint();
        assertEquals("second", second.getId());
        assertEquals("billingQueue", second.getDestination());
        assertEquals("2-10", second.getConcurrency());
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint) Test(org.junit.Test)

Example 9 with JmsListenerContainerTestFactory

use of org.springframework.jms.config.JmsListenerContainerTestFactory in project spring-framework by spring-projects.

the class EnableJmsTests method containerCanBeStarterViaTheRegistry.

@Test
public void containerCanBeStarterViaTheRegistry() {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EnableJmsAutoStartupFalseConfig.class, DefaultBean.class);
    JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
    MessageListenerTestContainer container = factory.getListenerContainers().get(0);
    assertFalse(container.isAutoStartup());
    assertFalse(container.isStarted());
    JmsListenerEndpointRegistry registry = context.getBean(JmsListenerEndpointRegistry.class);
    registry.start();
    assertTrue(container.isStarted());
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) JmsListenerEndpointRegistry(org.springframework.jms.config.JmsListenerEndpointRegistry) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MessageListenerTestContainer(org.springframework.jms.config.MessageListenerTestContainer) JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory) Test(org.junit.Test)

Example 10 with JmsListenerContainerTestFactory

use of org.springframework.jms.config.JmsListenerContainerTestFactory in project spring-framework by spring-projects.

the class JmsListenerAnnotationBeanPostProcessorTests method metaAnnotationIsDiscovered.

@Test
public void metaAnnotationIsDiscovered() throws Exception {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetaAnnotationTestBean.class);
    try {
        JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
        assertEquals("one container should have been registered", 1, factory.getListenerContainers().size());
        JmsListenerEndpoint endpoint = factory.getListenerContainers().get(0).getEndpoint();
        assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
        MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
        assertEquals(MetaAnnotationTestBean.class, methodEndpoint.getBean().getClass());
        assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMethod());
        assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod());
        assertEquals("metaTestQueue", ((AbstractJmsListenerEndpoint) endpoint).getDestination());
    } finally {
        context.close();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AbstractJmsListenerEndpoint(org.springframework.jms.config.AbstractJmsListenerEndpoint) JmsListenerEndpoint(org.springframework.jms.config.JmsListenerEndpoint) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint) Test(org.junit.Test)

Aggregations

JmsListenerContainerTestFactory (org.springframework.jms.config.JmsListenerContainerTestFactory)14 MethodJmsListenerEndpoint (org.springframework.jms.config.MethodJmsListenerEndpoint)8 Test (org.junit.Test)7 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)7 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)7 JmsListenerEndpoint (org.springframework.jms.config.JmsListenerEndpoint)4 MessageListenerTestContainer (org.springframework.jms.config.MessageListenerTestContainer)4 AbstractJmsListenerEndpoint (org.springframework.jms.config.AbstractJmsListenerEndpoint)3 Method (java.lang.reflect.Method)2 JmsListenerEndpointRegistry (org.springframework.jms.config.JmsListenerEndpointRegistry)2 SimpleMessageListenerContainer (org.springframework.jms.listener.SimpleMessageListenerContainer)2 Session (javax.jms.Session)1 StubTextMessage (org.springframework.jms.StubTextMessage)1 SimpleJmsListenerEndpoint (org.springframework.jms.config.SimpleJmsListenerEndpoint)1 MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)1