List of usage examples for org.springframework.amqp.rabbit.listener SimpleMessageListenerContainer getMessageListener
public Object getMessageListener()
From source file:org.springframework.integration.amqp.channel.DispatcherHasNoSubscribersTests.java
@Test public void testPtP() { final Channel channel = mock(Channel.class); Connection connection = mock(Connection.class); doAnswer(new Answer<Channel>() { public Channel answer(InvocationOnMock invocation) throws Throwable { return channel; }//from ww w . j a v a2s.co m }).when(connection).createChannel(anyBoolean()); ConnectionFactory connectionFactory = mock(ConnectionFactory.class); when(connectionFactory.createConnection()).thenReturn(connection); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); AmqpTemplate amqpTemplate = mock(AmqpTemplate.class); PointToPointSubscribableAmqpChannel amqpChannel = new PointToPointSubscribableAmqpChannel( "noSubscribersChannel", container, amqpTemplate); amqpChannel.setBeanName("noSubscribersChannel"); amqpChannel.afterPropertiesSet(); MessageListener listener = (MessageListener) container.getMessageListener(); try { listener.onMessage(new Message("Hello world!".getBytes(), null)); fail("Exception expected"); } catch (MessageDeliveryException e) { assertEquals("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'.", e.getMessage()); } }
From source file:org.springframework.integration.amqp.channel.DispatcherHasNoSubscribersTests.java
@Test public void testPubSub() { final Channel channel = mock(Channel.class); Connection connection = mock(Connection.class); doAnswer(new Answer<Channel>() { public Channel answer(InvocationOnMock invocation) throws Throwable { return channel; }/*from w w w . j a v a 2 s . com*/ }).when(connection).createChannel(anyBoolean()); ConnectionFactory connectionFactory = mock(ConnectionFactory.class); when(connectionFactory.createConnection()).thenReturn(connection); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); AmqpTemplate amqpTemplate = mock(AmqpTemplate.class); final Queue queue = new Queue("noSubscribersQueue"); PublishSubscribeAmqpChannel amqpChannel = new PublishSubscribeAmqpChannel("noSubscribersChannel", container, amqpTemplate) { @Override protected Queue initializeQueue(AmqpAdmin admin, String channelName) { return queue; } }; amqpChannel.setBeanName("noSubscribersChannel"); amqpChannel.afterPropertiesSet(); List<String> logList = insertMockLoggerInListener(amqpChannel); MessageListener listener = (MessageListener) container.getMessageListener(); listener.onMessage(new Message("Hello world!".getBytes(), null)); verifyLogReceived(logList); }
From source file:org.springframework.integration.amqp.channel.DispatcherHasNoSubscribersTests.java
private List<String> insertMockLoggerInListener(PublishSubscribeAmqpChannel channel) { SimpleMessageListenerContainer container = TestUtils.getPropertyValue(channel, "container", SimpleMessageListenerContainer.class); Log logger = mock(Log.class); final ArrayList<String> logList = new ArrayList<String>(); doAnswer(new Answer<Object>() { public Object answer(InvocationOnMock invocation) throws Throwable { String message = (String) invocation.getArguments()[0]; if (message.startsWith("Dispatcher has no subscribers")) { logList.add(message);//from w w w . j ava 2 s .co m } return null; } }).when(logger).warn(anyString(), any(Exception.class)); when(logger.isWarnEnabled()).thenReturn(true); Object listener = container.getMessageListener(); DirectFieldAccessor dfa = new DirectFieldAccessor(listener); dfa.setPropertyValue("logger", logger); return logList; }