Search in sources :

Example 1 with JsonToObjectTransformer

use of org.springframework.integration.json.JsonToObjectTransformer 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());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) JsonToObjectTransformer(org.springframework.integration.json.JsonToObjectTransformer) PollableChannel(org.springframework.messaging.PollableChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) Channel(com.rabbitmq.client.Channel) QueueChannel(org.springframework.integration.channel.QueueChannel) Connection(org.springframework.amqp.rabbit.connection.Connection) SimpleMessageListenerContainer(org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer) ChannelAwareMessageListener(org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener) Jackson2JsonMessageConverter(org.springframework.amqp.support.converter.Jackson2JsonMessageConverter) ConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory) MessageProperties(org.springframework.amqp.core.MessageProperties) PollableChannel(org.springframework.messaging.PollableChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.Test)

Aggregations

Channel (com.rabbitmq.client.Channel)1 Test (org.junit.Test)1 MessageProperties (org.springframework.amqp.core.MessageProperties)1 Connection (org.springframework.amqp.rabbit.connection.Connection)1 ConnectionFactory (org.springframework.amqp.rabbit.connection.ConnectionFactory)1 SimpleMessageListenerContainer (org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer)1 ChannelAwareMessageListener (org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener)1 Jackson2JsonMessageConverter (org.springframework.amqp.support.converter.Jackson2JsonMessageConverter)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 JsonToObjectTransformer (org.springframework.integration.json.JsonToObjectTransformer)1 PollableChannel (org.springframework.messaging.PollableChannel)1