Java Code Examples for org.springframework.jms.config.JmsListenerContainerTestFactory

The following examples show how to use org.springframework.jms.config.JmsListenerContainerTestFactory. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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());
	context.close(); // Close and stop the listeners
	assertTrue("Should have been stopped " + container, container.isStopped());
}
 
Example 2
@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();
	}
}
 
Example 3
Source Project: spring-analysis-note   Source File: EnableJmsTests.java    License: MIT License 6 votes vote down vote up
@Test
public void composedJmsListeners() {
	try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
		EnableJmsDefaultContainerFactoryConfig.class, ComposedJmsListenersBean.class)) {
		JmsListenerContainerTestFactory simpleFactory = context.getBean("jmsListenerContainerFactory",
			JmsListenerContainerTestFactory.class);
		assertEquals(2, simpleFactory.getListenerContainers().size());

		MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
			"first").getEndpoint();
		assertEquals("first", first.getId());
		assertEquals("orderQueue", first.getDestination());
		assertNull(first.getConcurrency());

		MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
			"second").getEndpoint();
		assertEquals("second", second.getId());
		assertEquals("billingQueue", second.getDestination());
		assertEquals("2-10", second.getConcurrency());
	}
}
 
Example 4
/**
 * 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);
}
 
Example 5
/**
 * 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"));
}
 
Example 6
/**
 * 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());
}
 
Example 7
@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());
	context.close(); // Close and stop the listeners
	assertTrue("Should have been stopped " + container, container.isStopped());
}
 
Example 8
@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();
	}
}
 
Example 9
Source Project: java-technology-stack   Source File: EnableJmsTests.java    License: MIT License 6 votes vote down vote up
@Test
public void composedJmsListeners() {
	try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
		EnableJmsDefaultContainerFactoryConfig.class, ComposedJmsListenersBean.class)) {
		JmsListenerContainerTestFactory simpleFactory = context.getBean("jmsListenerContainerFactory",
			JmsListenerContainerTestFactory.class);
		assertEquals(2, simpleFactory.getListenerContainers().size());

		MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
			"first").getEndpoint();
		assertEquals("first", first.getId());
		assertEquals("orderQueue", first.getDestination());
		assertNull(first.getConcurrency());

		MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
			"second").getEndpoint();
		assertEquals("second", second.getId());
		assertEquals("billingQueue", second.getDestination());
		assertEquals("2-10", second.getConcurrency());
	}
}
 
Example 10
/**
 * 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);
}
 
Example 11
/**
 * 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"));
}
 
Example 12
/**
 * 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());
}
 
Example 13
@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());
	context.close(); // Close and stop the listeners
	assertTrue("Should have been stopped " + container, container.isStopped());
}
 
Example 14
@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();
	}
}
 
Example 15
@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();
	}
}
 
Example 16
/**
 * 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);
}
 
Example 17
/**
 * 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"));
}
 
Example 18
/**
 * 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());
}
 
Example 19
@Test
public void sendToAnnotationFoundOnInterfaceProxy() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, ProxyConfig.class, InterfaceProxyTestBean.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, String.class),
				methodEndpoint.getMethod());
		assertEquals(InterfaceProxyTestBean.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMostSpecificMethod());

		Method method = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
		ReflectionUtils.makeAccessible(method);
		Object destination = ReflectionUtils.invokeMethod(method, endpoint);
		assertEquals("SendTo annotation not found on proxy", "foobar", destination);
	}
	finally {
		context.close();
	}
}
 
Example 20
@Test
public void sendToAnnotationFoundOnCglibProxy() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, ProxyConfig.class, ClassProxyTestBean.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.isCglibProxy(methodEndpoint.getBean()));
		assertTrue(methodEndpoint.getBean() instanceof ClassProxyTestBean);
		assertEquals(ClassProxyTestBean.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMethod());
		assertEquals(ClassProxyTestBean.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMostSpecificMethod());

		Method method = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
		ReflectionUtils.makeAccessible(method);
		Object destination = ReflectionUtils.invokeMethod(method, endpoint);
		assertEquals("SendTo annotation not found on proxy", "foobar", destination);
	}
	finally {
		context.close();
	}
}
 
Example 21
Source Project: spring-analysis-note   Source File: EnableJmsTests.java    License: MIT License 5 votes vote down vote up
@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());
}
 
Example 22
Source Project: spring-analysis-note   Source File: EnableJmsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void containerCanBeStarterViaTheRegistry() {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			EnableJmsAutoStartupFalseConfig.class, DefaultBean.class);
	JmsListenerContainerTestFactory factory =
			context.getBean(JmsListenerContainerTestFactory.class);
	MessageListenerTestContainer container = factory.getListenerContainers().get(0);
	assertFalse(container.isAutoStartup());
	assertFalse(container.isStarted());
	JmsListenerEndpointRegistry registry = context.getBean(JmsListenerEndpointRegistry.class);
	registry.start();
	assertTrue(container.isStarted());
}
 
Example 23
Source Project: spring-analysis-note   Source File: EnableJmsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void lazyComponent() {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			EnableJmsDefaultContainerFactoryConfig.class, LazyBean.class);
	JmsListenerContainerTestFactory defaultFactory =
			context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
	assertEquals(0, defaultFactory.getListenerContainers().size());

	context.getBean(LazyBean.class);  // trigger lazy resolution
	assertEquals(1, defaultFactory.getListenerContainers().size());
	MessageListenerTestContainer container = defaultFactory.getListenerContainers().get(0);
	assertTrue("Should have been started " + container, container.isStarted());
	context.close();  // close and stop the listeners
	assertTrue("Should have been stopped " + container, container.isStopped());
}
 
Example 24
/**
 * 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());
}
 
Example 25
/**
 * 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));
}
 
Example 26
@Test
public void sendToAnnotationFoundOnInterfaceProxy() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, ProxyConfig.class, InterfaceProxyTestBean.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, String.class),
				methodEndpoint.getMethod());
		assertEquals(InterfaceProxyTestBean.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMostSpecificMethod());

		Method method = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
		ReflectionUtils.makeAccessible(method);
		Object destination = ReflectionUtils.invokeMethod(method, endpoint);
		assertEquals("SendTo annotation not found on proxy", "foobar", destination);
	}
	finally {
		context.close();
	}
}
 
Example 27
@Test
public void sendToAnnotationFoundOnCglibProxy() throws Exception {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			Config.class, ProxyConfig.class, ClassProxyTestBean.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.isCglibProxy(methodEndpoint.getBean()));
		assertTrue(methodEndpoint.getBean() instanceof ClassProxyTestBean);
		assertEquals(ClassProxyTestBean.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMethod());
		assertEquals(ClassProxyTestBean.class.getMethod("handleIt", String.class, String.class),
				methodEndpoint.getMostSpecificMethod());

		Method method = ReflectionUtils.findMethod(endpoint.getClass(), "getDefaultResponseDestination");
		ReflectionUtils.makeAccessible(method);
		Object destination = ReflectionUtils.invokeMethod(method, endpoint);
		assertEquals("SendTo annotation not found on proxy", "foobar", destination);
	}
	finally {
		context.close();
	}
}
 
Example 28
Source Project: java-technology-stack   Source File: EnableJmsTests.java    License: MIT License 5 votes vote down vote up
@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());
}
 
Example 29
Source Project: java-technology-stack   Source File: EnableJmsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void containerCanBeStarterViaTheRegistry() {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			EnableJmsAutoStartupFalseConfig.class, DefaultBean.class);
	JmsListenerContainerTestFactory factory =
			context.getBean(JmsListenerContainerTestFactory.class);
	MessageListenerTestContainer container = factory.getListenerContainers().get(0);
	assertFalse(container.isAutoStartup());
	assertFalse(container.isStarted());
	JmsListenerEndpointRegistry registry = context.getBean(JmsListenerEndpointRegistry.class);
	registry.start();
	assertTrue(container.isStarted());
}
 
Example 30
Source Project: java-technology-stack   Source File: EnableJmsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void lazyComponent() {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			EnableJmsDefaultContainerFactoryConfig.class, LazyBean.class);
	JmsListenerContainerTestFactory defaultFactory =
			context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
	assertEquals(0, defaultFactory.getListenerContainers().size());

	context.getBean(LazyBean.class);  // trigger lazy resolution
	assertEquals(1, defaultFactory.getListenerContainers().size());
	MessageListenerTestContainer container = defaultFactory.getListenerContainers().get(0);
	assertTrue("Should have been started " + container, container.isStarted());
	context.close();  // close and stop the listeners
	assertTrue("Should have been stopped " + container, container.isStopped());
}