Search in sources :

Example 11 with MessageHistory

use of org.springframework.integration.history.MessageHistory in project spring-integration by spring-projects.

the class ConnectionToConnectionTests method testConnectRaw.

@Test
public void testConnectRaw() throws Exception {
    ByteArrayRawSerializer serializer = new ByteArrayRawSerializer();
    clientNet.setSerializer(serializer);
    serverNet.setDeserializer(serializer);
    clientNet.start();
    TcpConnection connection = clientNet.getConnection();
    connection.send(MessageBuilder.withPayload("Test").build());
    connection.close();
    Message<?> message = serverSideChannel.receive(10000);
    assertNotNull(message);
    MessageHistory history = MessageHistory.read(message);
    // org.springframework.integration.test.util.TestUtils
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "gwNet", 0);
    assertNotNull(componentHistoryRecord);
    assertTrue(componentHistoryRecord.get("type").equals("ip:tcp-inbound-gateway"));
    assertNotNull(message);
    assertEquals("Test", new String((byte[]) message.getPayload()));
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) ByteArrayRawSerializer(org.springframework.integration.ip.tcp.serializer.ByteArrayRawSerializer) TcpConnection(org.springframework.integration.ip.tcp.connection.TcpConnection) Properties(java.util.Properties) Test(org.junit.Test)

Example 12 with MessageHistory

use of org.springframework.integration.history.MessageHistory in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testWithMessageHistory.

@Test
@RedisAvailable
public void testWithMessageHistory() {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    Message<?> message = new GenericMessage<>("Hello");
    DirectChannel fooChannel = new DirectChannel();
    fooChannel.setBeanName("fooChannel");
    DirectChannel barChannel = new DirectChannel();
    barChannel.setBeanName("barChannel");
    message = MessageHistory.write(message, fooChannel);
    message = MessageHistory.write(message, barChannel);
    store.addMessagesToGroup(this.groupId, message);
    message = store.getMessageGroup(this.groupId).getMessages().iterator().next();
    MessageHistory messageHistory = MessageHistory.read(message);
    assertNotNull(messageHistory);
    assertEquals(2, messageHistory.size());
    Properties fooChannelHistory = messageHistory.get(0);
    assertEquals("fooChannel", fooChannelHistory.get("name"));
    assertEquals("channel", fooChannelHistory.get("type"));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHistory(org.springframework.integration.history.MessageHistory) DirectChannel(org.springframework.integration.channel.DirectChannel) Properties(java.util.Properties) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 13 with MessageHistory

use of org.springframework.integration.history.MessageHistory in project spring-integration by spring-projects.

the class GemfireMessageStoreTests method testWithMessageHistory.

@Test
public void testWithMessageHistory() throws Exception {
    GemfireMessageStore store = new GemfireMessageStore(region);
    Message<?> message = new GenericMessage<String>("Hello");
    DirectChannel fooChannel = new DirectChannel();
    fooChannel.setBeanName("fooChannel");
    DirectChannel barChannel = new DirectChannel();
    barChannel.setBeanName("barChannel");
    message = MessageHistory.write(message, fooChannel);
    message = MessageHistory.write(message, barChannel);
    store.addMessage(message);
    message = store.getMessage(message.getHeaders().getId());
    MessageHistory messageHistory = MessageHistory.read(message);
    assertNotNull(messageHistory);
    assertEquals(2, messageHistory.size());
    Properties fooChannelHistory = messageHistory.get(0);
    assertEquals("fooChannel", fooChannelHistory.get("name"));
    assertEquals("channel", fooChannelHistory.get("type"));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHistory(org.springframework.integration.history.MessageHistory) DirectChannel(org.springframework.integration.channel.DirectChannel) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with MessageHistory

use of org.springframework.integration.history.MessageHistory in project spring-integration by spring-projects.

the class WebServiceInboundGatewayParserTests method testMessageHistoryWithMarshallingGateway.

@Test
public void testMessageHistoryWithMarshallingGateway() throws Exception {
    MessageContext context = new DefaultMessageContext(new StubMessageFactory());
    Unmarshaller unmarshaller = mock(Unmarshaller.class);
    when(unmarshaller.unmarshal((Source) Mockito.any())).thenReturn("hello");
    marshallingGateway.setUnmarshaller(unmarshaller);
    marshallingGateway.invoke(context);
    Message<?> message = requestsMarshalling.receive(100);
    MessageHistory history = MessageHistory.read(message);
    assertNotNull(history);
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "marshalling", 0);
    assertNotNull(componentHistoryRecord);
    assertEquals("ws:inbound-gateway", componentHistoryRecord.get("type"));
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) DefaultMessageContext(org.springframework.ws.context.DefaultMessageContext) DefaultMessageContext(org.springframework.ws.context.DefaultMessageContext) MessageContext(org.springframework.ws.context.MessageContext) Unmarshaller(org.springframework.oxm.Unmarshaller) Properties(java.util.Properties) Test(org.junit.Test)

Example 15 with MessageHistory

use of org.springframework.integration.history.MessageHistory in project spring-integration by spring-projects.

the class WebServiceInboundGatewayParserTests method testMessageHistoryWithSimpleGateway.

@Test
public void testMessageHistoryWithSimpleGateway() throws Exception {
    MessageContext context = new DefaultMessageContext(new StubMessageFactory());
    payloadExtractingGateway.invoke(context);
    Message<?> message = requestsSimple.receive(100);
    MessageHistory history = MessageHistory.read(message);
    assertNotNull(history);
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "extractsPayload", 0);
    assertNotNull(componentHistoryRecord);
    assertEquals("ws:inbound-gateway", componentHistoryRecord.get("type"));
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) DefaultMessageContext(org.springframework.ws.context.DefaultMessageContext) DefaultMessageContext(org.springframework.ws.context.DefaultMessageContext) MessageContext(org.springframework.ws.context.MessageContext) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

MessageHistory (org.springframework.integration.history.MessageHistory)37 Test (org.junit.Test)34 Properties (java.util.Properties)26 GenericMessage (org.springframework.messaging.support.GenericMessage)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 DirectChannel (org.springframework.integration.channel.DirectChannel)8 PollableChannel (org.springframework.messaging.PollableChannel)8 Message (org.springframework.messaging.Message)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)3 QueueChannel (org.springframework.integration.channel.QueueChannel)3 EnableMessageHistory (org.springframework.integration.config.EnableMessageHistory)3 MongoClient (com.mongodb.MongoClient)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)2 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)2 TcpConnection (org.springframework.integration.ip.tcp.connection.TcpConnection)2 JmsMessageDrivenEndpoint (org.springframework.integration.jms.JmsMessageDrivenEndpoint)2 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)2 MessageChannel (org.springframework.messaging.MessageChannel)2