Search in sources :

Example 11 with JmsListenerContainerTestFactory

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

the class JmsListenerAnnotationBeanPostProcessorTests method sendToAnnotationFoundOnProxy.

@Test
public void sendToAnnotationFoundOnProxy() throws Exception {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class, ProxyConfig.class, ProxyTestBean.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;
        assertTrue(AopUtils.isJdkDynamicProxy(methodEndpoint.getBean()));
        assertTrue(methodEndpoint.getBean() instanceof SimpleService);
        assertEquals(SimpleService.class.getMethod("handleIt", String.class), methodEndpoint.getMethod());
        assertEquals(ProxyTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod());
        Method m = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
        ReflectionUtils.makeAccessible(m);
        Object destination = ReflectionUtils.invokeMethod(m, endpoint);
        assertEquals("SendTo annotation not found on proxy", "foobar", destination);
    } 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) Method(java.lang.reflect.Method) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint) Test(org.junit.Test)

Example 12 with JmsListenerContainerTestFactory

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

the class AbstractJmsAnnotationDrivenTests method testFullConfiguration.

/**
	 * Test for {@link FullBean} discovery. In this case, no default is set because
	 * all endpoints provide a default registry. This shows that the default factory
	 * is only retrieved if it needs to be.
	 */
public void testFullConfiguration(ApplicationContext context) {
    JmsListenerContainerTestFactory simpleFactory = context.getBean("simpleFactory", JmsListenerContainerTestFactory.class);
    assertEquals(1, simpleFactory.getListenerContainers().size());
    MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainers().get(0).getEndpoint();
    assertEquals("listener1", endpoint.getId());
    assertEquals("queueIn", endpoint.getDestination());
    assertEquals("mySelector", endpoint.getSelector());
    assertEquals("mySubscription", endpoint.getSubscription());
    assertEquals("1-10", endpoint.getConcurrency());
    Method m = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
    ReflectionUtils.makeAccessible(m);
    Object destination = ReflectionUtils.invokeMethod(m, endpoint);
    assertEquals("queueOut", destination);
}
Also used : JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory) Method(java.lang.reflect.Method) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint)

Example 13 with JmsListenerContainerTestFactory

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

the class AbstractJmsAnnotationDrivenTests method testJmsHandlerMethodFactoryConfiguration.

/**
	 * Test for {@link ValidationBean} with a validator ({@link TestValidator}) specified
	 * in a custom {@link org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory}.
	 *
	 * The test should throw a {@link org.springframework.jms.listener.adapter.ListenerExecutionFailedException}
	 */
public void testJmsHandlerMethodFactoryConfiguration(ApplicationContext context) throws JMSException {
    JmsListenerContainerTestFactory simpleFactory = context.getBean("defaultFactory", JmsListenerContainerTestFactory.class);
    assertEquals(1, simpleFactory.getListenerContainers().size());
    MethodJmsListenerEndpoint endpoint = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainers().get(0).getEndpoint();
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    endpoint.setupListenerContainer(container);
    MessagingMessageListenerAdapter listener = (MessagingMessageListenerAdapter) container.getMessageListener();
    listener.onMessage(new StubTextMessage("failValidation"), mock(Session.class));
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) StubTextMessage(org.springframework.jms.StubTextMessage) SimpleMessageListenerContainer(org.springframework.jms.listener.SimpleMessageListenerContainer) JmsListenerContainerTestFactory(org.springframework.jms.config.JmsListenerContainerTestFactory) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint) Session(javax.jms.Session)

Example 14 with JmsListenerContainerTestFactory

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

the class EnableJmsTests method containerAreStartedByDefault.

@Test
public void containerAreStartedByDefault() {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EnableJmsDefaultContainerFactoryConfig.class, DefaultBean.class);
    JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
    MessageListenerTestContainer container = factory.getListenerContainers().get(0);
    assertTrue(container.isAutoStartup());
    assertTrue(container.isStarted());
}
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)

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