Search in sources :

Example 6 with MethodJmsListenerEndpoint

use of org.springframework.jms.config.MethodJmsListenerEndpoint 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 7 with MethodJmsListenerEndpoint

use of org.springframework.jms.config.MethodJmsListenerEndpoint 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 8 with MethodJmsListenerEndpoint

use of org.springframework.jms.config.MethodJmsListenerEndpoint 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)

Aggregations

MethodJmsListenerEndpoint (org.springframework.jms.config.MethodJmsListenerEndpoint)8 JmsListenerContainerTestFactory (org.springframework.jms.config.JmsListenerContainerTestFactory)7 Test (org.junit.Test)4 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)4 Method (java.lang.reflect.Method)3 AbstractJmsListenerEndpoint (org.springframework.jms.config.AbstractJmsListenerEndpoint)3 JmsListenerEndpoint (org.springframework.jms.config.JmsListenerEndpoint)3 SimpleMessageListenerContainer (org.springframework.jms.listener.SimpleMessageListenerContainer)2 Session (javax.jms.Session)1 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 StubTextMessage (org.springframework.jms.StubTextMessage)1 JmsListenerContainerFactory (org.springframework.jms.config.JmsListenerContainerFactory)1 MessageListenerTestContainer (org.springframework.jms.config.MessageListenerTestContainer)1 MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)1 InvocableHandlerMethod (org.springframework.messaging.handler.invocation.InvocableHandlerMethod)1