@Test public void registerNullContainerFactoryIsAllowed() throws Exception { SimpleRabbitListenerEndpoint endpoint = new SimpleRabbitListenerEndpoint(); endpoint.setId("some id"); registrar.setContainerFactory(containerFactory); registrar.registerEndpoint(endpoint, null); registrar.afterPropertiesSet(); assertNotNull("Container not created", registry.getListenerContainer("some id")); assertEquals("some id", registry.getListenerContainerIds().iterator().next()); assertEquals(1, registry.getListenerContainers().size()); }
@Test public void registerContainerWithoutFactory() throws Exception { SimpleRabbitListenerEndpoint endpoint = new SimpleRabbitListenerEndpoint(); endpoint.setId("myEndpoint"); registrar.setContainerFactory(containerFactory); registrar.registerEndpoint(endpoint); registrar.afterPropertiesSet(); assertNotNull("Container not created", registry.getListenerContainer("myEndpoint")); assertEquals("myEndpoint", registry.getListenerContainerIds().iterator().next()); assertEquals(1, registry.getListenerContainers().size()); }
/** * 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) { RabbitListenerContainerTestFactory defaultFactory = context.getBean("rabbitListenerContainerFactory", RabbitListenerContainerTestFactory.class); RabbitListenerContainerTestFactory customFactory = context.getBean("customFactory", RabbitListenerContainerTestFactory.class); assertEquals(1, defaultFactory.getListenerContainers().size()); assertEquals(1, customFactory.getListenerContainers().size()); RabbitListenerEndpoint endpoint = defaultFactory.getListenerContainers().get(0).getEndpoint(); assertEquals("Wrong endpoint type", SimpleRabbitListenerEndpoint.class, endpoint.getClass()); assertEquals("Wrong listener set in custom endpoint", context.getBean("simpleMessageListener"), ((SimpleRabbitListenerEndpoint) endpoint).getMessageListener()); RabbitListenerEndpointRegistry customRegistry = context.getBean("customRegistry", RabbitListenerEndpointRegistry.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")); }