Search in sources :

Example 1 with MessageListenerTestContainer

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();
}
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.jupiter.api.Test)

Example 2 with MessageListenerTestContainer

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();
}
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.jupiter.api.Test)

Example 3 with MessageListenerTestContainer

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();
}
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.jupiter.api.Test)

Example 4 with MessageListenerTestContainer

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();
}
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.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)4 JmsListenerContainerTestFactory (org.springframework.jms.config.JmsListenerContainerTestFactory)4 MessageListenerTestContainer (org.springframework.jms.config.MessageListenerTestContainer)4 AbstractJmsListenerEndpoint (org.springframework.jms.config.AbstractJmsListenerEndpoint)1 JmsListenerEndpoint (org.springframework.jms.config.JmsListenerEndpoint)1 JmsListenerEndpointRegistry (org.springframework.jms.config.JmsListenerEndpointRegistry)1 MethodJmsListenerEndpoint (org.springframework.jms.config.MethodJmsListenerEndpoint)1 SimpleMessageListenerContainer (org.springframework.jms.listener.SimpleMessageListenerContainer)1