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());
}
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());
}
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());
}
}
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());
}
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();
}
}
Aggregations