use of org.springframework.amqp.rabbit.connection.Connection in project spring-integration by spring-projects.
the class AmqpOutboundChannelAdapterParserTests method testInt2773UseDefaultAmqpTemplateExchangeAndRoutingLey.
@Test
public void testInt2773UseDefaultAmqpTemplateExchangeAndRoutingLey() throws IOException {
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
Connection mockConnection = mock(Connection.class);
Channel mockChannel = mock(Channel.class);
when(connectionFactory.createConnection()).thenReturn(mockConnection);
PublisherCallbackChannelImpl publisherCallbackChannel = new PublisherCallbackChannelImpl(mockChannel);
when(mockConnection.createChannel(false)).thenReturn(publisherCallbackChannel);
MessageChannel requestChannel = context.getBean("toRabbitOnlyWithTemplateChannel", MessageChannel.class);
requestChannel.send(MessageBuilder.withPayload("test").build());
Mockito.verify(mockChannel, Mockito.times(1)).basicPublish(Mockito.eq("default.test.exchange"), Mockito.eq("default.routing.key"), Mockito.anyBoolean(), Mockito.any(BasicProperties.class), Mockito.any(byte[].class));
}
use of org.springframework.amqp.rabbit.connection.Connection in project spring-integration by spring-projects.
the class AmqpOutboundChannelAdapterParserTests method testInt2773WithDefaultAmqpTemplateExchangeAndRoutingKey.
@Test
public void testInt2773WithDefaultAmqpTemplateExchangeAndRoutingKey() throws IOException {
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
Connection mockConnection = mock(Connection.class);
Channel mockChannel = mock(Channel.class);
when(connectionFactory.createConnection()).thenReturn(mockConnection);
PublisherCallbackChannelImpl publisherCallbackChannel = new PublisherCallbackChannelImpl(mockChannel);
when(mockConnection.createChannel(false)).thenReturn(publisherCallbackChannel);
MessageChannel requestChannel = context.getBean("withDefaultAmqpTemplateExchangeAndRoutingKey", MessageChannel.class);
requestChannel.send(MessageBuilder.withPayload("test").build());
Mockito.verify(mockChannel, Mockito.times(1)).basicPublish(Mockito.eq(""), Mockito.eq(""), Mockito.anyBoolean(), Mockito.any(BasicProperties.class), Mockito.any(byte[].class));
}
use of org.springframework.amqp.rabbit.connection.Connection in project spring-integration by spring-projects.
the class InboundEndpointTests method testGatewayConversionError.
@Test
public void testGatewayConversionError() throws Exception {
Connection connection = mock(Connection.class);
doAnswer(invocation -> mock(Channel.class)).when(connection).createChannel(anyBoolean());
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
when(connectionFactory.createConnection()).thenReturn(connection);
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
AmqpInboundGateway adapter = new AmqpInboundGateway(container);
QueueChannel outputChannel = new QueueChannel();
adapter.setRequestChannel(outputChannel);
QueueChannel errorChannel = new QueueChannel();
adapter.setErrorChannel(errorChannel);
adapter.setMessageConverter(new MessageConverter() {
@Override
public org.springframework.amqp.core.Message toMessage(Object object, MessageProperties messageProperties) throws MessageConversionException {
throw new MessageConversionException("intended");
}
@Override
public Object fromMessage(org.springframework.amqp.core.Message message) throws MessageConversionException {
return null;
}
});
adapter.afterPropertiesSet();
((ChannelAwareMessageListener) container.getMessageListener()).onMessage(null, null);
assertNull(outputChannel.receive(0));
assertNotNull(errorChannel.receive(0));
}
use of org.springframework.amqp.rabbit.connection.Connection in project spring-integration by spring-projects.
the class InboundEndpointTests method testInt2809JavaTypePropertiesToAmqp.
@Test
public void testInt2809JavaTypePropertiesToAmqp() throws Exception {
Connection connection = mock(Connection.class);
doAnswer(invocation -> mock(Channel.class)).when(connection).createChannel(anyBoolean());
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
when(connectionFactory.createConnection()).thenReturn(connection);
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter(container);
adapter.setMessageConverter(new Jackson2JsonMessageConverter());
PollableChannel channel = new QueueChannel();
adapter.setOutputChannel(channel);
adapter.setBeanFactory(mock(BeanFactory.class));
adapter.afterPropertiesSet();
Object payload = new Foo("bar1");
Transformer objectToJsonTransformer = new ObjectToJsonTransformer();
Message<?> jsonMessage = objectToJsonTransformer.transform(new GenericMessage<Object>(payload));
MessageProperties amqpMessageProperties = new MessageProperties();
amqpMessageProperties.setDeliveryTag(123L);
org.springframework.amqp.core.Message amqpMessage = new SimpleMessageConverter().toMessage(jsonMessage.getPayload(), amqpMessageProperties);
DefaultAmqpHeaderMapper.inboundMapper().fromHeadersToRequest(jsonMessage.getHeaders(), amqpMessageProperties);
ChannelAwareMessageListener listener = (ChannelAwareMessageListener) container.getMessageListener();
Channel rabbitChannel = mock(Channel.class);
listener.onMessage(amqpMessage, rabbitChannel);
Message<?> result = channel.receive(1000);
assertEquals(payload, result.getPayload());
assertSame(rabbitChannel, result.getHeaders().get(AmqpHeaders.CHANNEL));
assertEquals(123L, result.getHeaders().get(AmqpHeaders.DELIVERY_TAG));
}
use of org.springframework.amqp.rabbit.connection.Connection in project spring-integration by spring-projects.
the class InboundEndpointTests method testInt2809JavaTypePropertiesFromAmqp.
@Test
public void testInt2809JavaTypePropertiesFromAmqp() throws Exception {
Connection connection = mock(Connection.class);
doAnswer(invocation -> mock(Channel.class)).when(connection).createChannel(anyBoolean());
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
when(connectionFactory.createConnection()).thenReturn(connection);
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter(container);
PollableChannel channel = new QueueChannel();
adapter.setOutputChannel(channel);
adapter.setBeanFactory(mock(BeanFactory.class));
adapter.afterPropertiesSet();
Object payload = new Foo("bar1");
MessageProperties amqpMessageProperties = new MessageProperties();
org.springframework.amqp.core.Message amqpMessage = new Jackson2JsonMessageConverter().toMessage(payload, amqpMessageProperties);
ChannelAwareMessageListener listener = (ChannelAwareMessageListener) container.getMessageListener();
listener.onMessage(amqpMessage, null);
Message<?> receive = channel.receive(1000);
Message<?> result = new JsonToObjectTransformer().transform(receive);
assertEquals(payload, result.getPayload());
}
Aggregations