Search in sources :

Example 1 with JmsListenerContainerTestFactory

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

the class AbstractJmsAnnotationDrivenTests method testCustomConfiguration.

/**
	 * Test for {@link CustomBean} and an manually endpoint registered
	 * with "myCustomEndpointId". The custom endpoint does not provide
	 * any factory so it's registered with the default one
	 */
public void testCustomConfiguration(ApplicationContext context) {
    JmsListenerContainerTestFactory defaultFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
    JmsListenerContainerTestFactory customFactory = context.getBean("customFactory", JmsListenerContainerTestFactory.class);
    assertEquals(1, defaultFactory.getListenerContainers().size());
    assertEquals(1, customFactory.getListenerContainers().size());
    JmsListenerEndpoint endpoint = defaultFactory.getListenerContainers().get(0).getEndpoint();
    assertEquals("Wrong endpoint type", SimpleJmsListenerEndpoint.class, endpoint.getClass());
    assertEquals("Wrong listener set in custom endpoint", context.getBean("simpleMessageListener"), ((SimpleJmsListenerEndpoint) endpoint).getMessageListener());
    JmsListenerEndpointRegistry customRegistry = context.getBean("customRegistry", JmsListenerEndpointRegistry.class);
    assertEquals("Wrong number of containers in the registry", 2, customRegistry.getListenerContainerIds().size());
    assertEquals("Wrong number of containers in the registry", 2, customRegistry.getListenerContainers().size());
    assertNotNull("Container with custom id on the annotation should be found", customRegistry.getListenerContainer("listenerId"));
    assertNotNull("Container created with custom id should be found", customRegistry.getListenerContainer("myCustomEndpointId"));
}
Also used : JmsListenerEndpointRegistry(org.springframework.jms.config.JmsListenerEndpointRegistry) JmsListenerEndpoint(org.springframework.jms.config.JmsListenerEndpoint) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint) SimpleJmsListenerEndpoint(org.springframework.jms.config.SimpleJmsListenerEndpoint) JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory)

Example 2 with JmsListenerContainerTestFactory

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

the class AbstractJmsAnnotationDrivenTests method testExplicitContainerFactoryConfiguration.

/**
	 * Test for {@link DefaultBean} that does not define the container
	 * factory to use as a default is registered with an explicit
	 * default.
	 */
public void testExplicitContainerFactoryConfiguration(ApplicationContext context) {
    JmsListenerContainerTestFactory defaultFactory = context.getBean("simpleFactory", JmsListenerContainerTestFactory.class);
    assertEquals(1, defaultFactory.getListenerContainers().size());
}
Also used : JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory)

Example 3 with JmsListenerContainerTestFactory

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

the class AbstractJmsAnnotationDrivenTests method testSampleConfiguration.

/**
	 * Test for {@link SampleBean} discovery. If a factory with the default name
	 * is set, an endpoint will use it automatically
	 */
public void testSampleConfiguration(ApplicationContext context) {
    JmsListenerContainerTestFactory defaultFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
    JmsListenerContainerTestFactory simpleFactory = context.getBean("simpleFactory", JmsListenerContainerTestFactory.class);
    assertEquals(1, defaultFactory.getListenerContainers().size());
    assertEquals(1, simpleFactory.getListenerContainers().size());
}
Also used : JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory)

Example 4 with JmsListenerContainerTestFactory

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

the class AbstractJmsAnnotationDrivenTests method testDefaultContainerFactoryConfiguration.

/**
	 * Test for {@link DefaultBean} that does not define the container
	 * factory to use as a default is registered with the default name.
	 */
public void testDefaultContainerFactoryConfiguration(ApplicationContext context) {
    JmsListenerContainerTestFactory defaultFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
    assertEquals(1, defaultFactory.getListenerContainers().size());
}
Also used : JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory)

Example 5 with JmsListenerContainerTestFactory

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

the class AbstractJmsAnnotationDrivenTests method testJmsListenerRepeatable.

/**
	 * Test for {@link JmsListenerRepeatableBean} and {@link JmsListenersBean} that validates that the
	 * {@code @JmsListener} annotation is repeatable and generate one specific container per annotation.
	 */
public void testJmsListenerRepeatable(ApplicationContext context) {
    JmsListenerContainerTestFactory simpleFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
    assertEquals(2, simpleFactory.getListenerContainers().size());
    MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer("first").getEndpoint();
    assertEquals("first", first.getId());
    assertEquals("myQueue", first.getDestination());
    assertEquals(null, first.getConcurrency());
    MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer("second").getEndpoint();
    assertEquals("second", second.getId());
    assertEquals("anotherQueue", second.getDestination());
    assertEquals("2-10", second.getConcurrency());
}
Also used : JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint)

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