use of org.springframework.jms.config.MessageListenerTestContainer in project spring-framework by spring-projects.
the class EnableJmsTests method lazyComponent.
@Test
void lazyComponent() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EnableJmsDefaultContainerFactoryConfig.class, LazyBean.class);
JmsListenerContainerTestFactory defaultFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
assertThat(defaultFactory.getListenerContainers().size()).isEqualTo(0);
// trigger lazy resolution
context.getBean(LazyBean.class);
assertThat(defaultFactory.getListenerContainers().size()).isEqualTo(1);
MessageListenerTestContainer container = defaultFactory.getListenerContainers().get(0);
assertThat(container.isStarted()).as("Should have been started " + container).isTrue();
// close and stop the listeners
context.close();
assertThat(container.isStopped()).as("Should have been stopped " + container).isTrue();
}
use of org.springframework.jms.config.MessageListenerTestContainer in project spring-framework by spring-projects.
the class JmsListenerAnnotationBeanPostProcessorTests method simpleMessageListener.
@Test
void simpleMessageListener() throws Exception {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class, SimpleMessageListenerTestBean.class);
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
assertThat(factory.getListenerContainers().size()).as("One container should have been registered").isEqualTo(1);
MessageListenerTestContainer container = factory.getListenerContainers().get(0);
JmsListenerEndpoint endpoint = container.getEndpoint();
assertThat(endpoint.getClass()).as("Wrong endpoint type").isEqualTo(MethodJmsListenerEndpoint.class);
MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
assertThat(methodEndpoint.getBean().getClass()).isEqualTo(SimpleMessageListenerTestBean.class);
assertThat(methodEndpoint.getMethod()).isEqualTo(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class));
assertThat(methodEndpoint.getMostSpecificMethod()).isEqualTo(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class));
SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
methodEndpoint.setupListenerContainer(listenerContainer);
assertThat(listenerContainer.getMessageListener()).isNotNull();
assertThat(container.isStarted()).as("Should have been started " + container).isTrue();
// Close and stop the listeners
context.close();
assertThat(container.isStopped()).as("Should have been stopped " + container).isTrue();
}
use of org.springframework.jms.config.MessageListenerTestContainer in project spring-framework by spring-projects.
the class EnableJmsTests method containerCanBeStarterViaTheRegistry.
@Test
@SuppressWarnings("resource")
void containerCanBeStarterViaTheRegistry() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EnableJmsAutoStartupFalseConfig.class, DefaultBean.class);
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
MessageListenerTestContainer container = factory.getListenerContainers().get(0);
assertThat(container.isAutoStartup()).isFalse();
assertThat(container.isStarted()).isFalse();
JmsListenerEndpointRegistry registry = context.getBean(JmsListenerEndpointRegistry.class);
registry.start();
assertThat(container.isStarted()).isTrue();
}
use of org.springframework.jms.config.MessageListenerTestContainer in project spring-framework by spring-projects.
the class EnableJmsTests method containerAreStartedByDefault.
@Test
@SuppressWarnings("resource")
void containerAreStartedByDefault() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EnableJmsDefaultContainerFactoryConfig.class, DefaultBean.class);
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
MessageListenerTestContainer container = factory.getListenerContainers().get(0);
assertThat(container.isAutoStartup()).isTrue();
assertThat(container.isStarted()).isTrue();
}
Aggregations