Search in sources :

Example 1 with JmsListenerEndpoint

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

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

the class JmsListenerAnnotationBeanPostProcessorTests method simpleMessageListener.

@Test
public void simpleMessageListener() throws Exception {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class, SimpleMessageListenerTestBean.class);
    JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
    assertEquals("One container should have been registered", 1, factory.getListenerContainers().size());
    MessageListenerTestContainer container = factory.getListenerContainers().get(0);
    JmsListenerEndpoint endpoint = container.getEndpoint();
    assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
    MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
    assertEquals(SimpleMessageListenerTestBean.class, methodEndpoint.getBean().getClass());
    assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMethod());
    assertEquals(SimpleMessageListenerTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod());
    SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
    methodEndpoint.setupListenerContainer(listenerContainer);
    assertNotNull(listenerContainer.getMessageListener());
    assertTrue("Should have been started " + container, container.isStarted());
    // Close and stop the listeners
    context.close();
    assertTrue("Should have been stopped " + container, container.isStopped());
}
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.Test)

Example 3 with JmsListenerEndpoint

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

the class JmsListenerAnnotationBeanPostProcessorTests method metaAnnotationIsDiscovered.

@Test
public void metaAnnotationIsDiscovered() throws Exception {
    ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetaAnnotationTestBean.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;
        assertEquals(MetaAnnotationTestBean.class, methodEndpoint.getBean().getClass());
        assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMethod());
        assertEquals(MetaAnnotationTestBean.class.getMethod("handleIt", String.class), methodEndpoint.getMostSpecificMethod());
        assertEquals("metaTestQueue", ((AbstractJmsListenerEndpoint) endpoint).getDestination());
    } 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) MethodJmsListenerEndpoint(org.springframework.jms.config.MethodJmsListenerEndpoint) Test(org.junit.Test)

Example 4 with JmsListenerEndpoint

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

Aggregations

JmsListenerContainerTestFactory (org.springframework.jms.config.JmsListenerContainerTestFactory)4 JmsListenerEndpoint (org.springframework.jms.config.JmsListenerEndpoint)4 MethodJmsListenerEndpoint (org.springframework.jms.config.MethodJmsListenerEndpoint)4 Test (org.junit.Test)3 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 AbstractJmsListenerEndpoint (org.springframework.jms.config.AbstractJmsListenerEndpoint)3 Method (java.lang.reflect.Method)1 JmsListenerEndpointRegistry (org.springframework.jms.config.JmsListenerEndpointRegistry)1 MessageListenerTestContainer (org.springframework.jms.config.MessageListenerTestContainer)1 SimpleJmsListenerEndpoint (org.springframework.jms.config.SimpleJmsListenerEndpoint)1 SimpleMessageListenerContainer (org.springframework.jms.listener.SimpleMessageListenerContainer)1