Search in sources :

Example 26 with MessageHistory

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

the class CGLibProxyHandlerTests method testProxyBridge.

@Test
public void testProxyBridge() {
    assertTrue(AopUtils.isCglibProxy(this.bridge));
    this.bridge.handleMessage(new GenericMessage<>("foo"));
    Message<?> received = this.out.receive(0);
    assertNotNull(received);
    assertNotNull(received.getHeaders().get(MessageHistory.HEADER_NAME));
    MessageHistory history = received.getHeaders().get(MessageHistory.HEADER_NAME, MessageHistory.class);
    assertThat(history.size(), equalTo(2));
}
Also used : EnableMessageHistory(org.springframework.integration.config.EnableMessageHistory) MessageHistory(org.springframework.integration.history.MessageHistory) Test(org.junit.Test)

Example 27 with MessageHistory

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

the class HttpInboundChannelAdapterParserTests method postRequestWithTextContentOk.

@Test
public void postRequestWithTextContentOk() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("POST");
    request.setContent("test".getBytes());
    request.setContentType("text/plain");
    MockHttpServletResponse response = new MockHttpServletResponse();
    postOnlyAdapter.handleRequest(request, response);
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    Message<?> message = requests.receive(0);
    MessageHistory history = MessageHistory.read(message);
    assertNotNull(history);
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "postOnlyAdapter", 0);
    assertNotNull(componentHistoryRecord);
    assertEquals("http:inbound-channel-adapter", componentHistoryRecord.get("type"));
    assertNotNull(message);
    assertEquals("test", message.getPayload());
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Properties(java.util.Properties) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 28 with MessageHistory

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

the class FileMessageHistoryTests method testMessageHistory.

@Test
public void testMessageHistory() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("file-message-history-context.xml", getClass());
    TemporaryFolder input = context.getBean(TemporaryFolder.class);
    File file = input.newFile("FileMessageHistoryTest.txt");
    BufferedWriter out = new BufferedWriter(new FileWriter(file));
    out.write("hello");
    out.close();
    PollableChannel outChannel = context.getBean("outChannel", PollableChannel.class);
    Message<?> message = outChannel.receive(10000);
    assertThat(message, is(notNullValue()));
    MessageHistory history = MessageHistory.read(message);
    assertThat(history, is(notNullValue()));
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "fileAdapter", 0);
    assertNotNull(componentHistoryRecord);
    assertEquals("file:inbound-channel-adapter", componentHistoryRecord.get("type"));
    context.close();
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) FileWriter(java.io.FileWriter) TemporaryFolder(org.junit.rules.TemporaryFolder) PollableChannel(org.springframework.messaging.PollableChannel) Properties(java.util.Properties) File(java.io.File) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 29 with MessageHistory

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

the class GemfireGroupStoreTests method testWithMessageHistory.

@Test
public void testWithMessageHistory() throws Exception {
    GemfireMessageStore store = new GemfireMessageStore(region);
    store.getMessageGroup(1);
    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.addMessagesToGroup(1, message);
    message = store.getMessageGroup(1).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) Test(org.junit.Test)

Example 30 with MessageHistory

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

the class JdbcPollingChannelAdapterParserTests method testSimpleInboundChannelAdapter.

@Test
public void testSimpleInboundChannelAdapter() {
    setUp("pollingForMapJdbcInboundChannelAdapterTest.xml", getClass());
    this.jdbcTemplate.update("insert into item values(1,'',2)");
    Message<?> message = messagingTemplate.receive();
    assertNotNull("No message found ", message);
    assertTrue("Wrong payload type expected instance of List", message.getPayload() instanceof List<?>);
    MessageHistory history = MessageHistory.read(message);
    assertNotNull(history);
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "jdbcAdapter", 0);
    assertNotNull(componentHistoryRecord);
    assertEquals("jdbc:inbound-channel-adapter", componentHistoryRecord.get("type"));
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) 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