Search in sources :

Example 1 with JsonOutboundMessageMapper

use of org.springframework.integration.support.json.JsonOutboundMessageMapper in project spring-integration by spring-projects.

the class JsonOutboundMessageMapperTests method testFromMessageExtractBeanPayload.

@Test
public void testFromMessageExtractBeanPayload() throws Exception {
    TestBean payload = new TestBean();
    Message<TestBean> testMessage = MessageBuilder.withPayload(payload).build();
    JsonOutboundMessageMapper mapper = new JsonOutboundMessageMapper();
    mapper.setShouldExtractPayload(true);
    String result = mapper.fromMessage(testMessage);
    assertTrue(!result.contains("headers"));
    TestBean parsedPayload = objectMapper.readValue(result, TestBean.class);
    assertEquals(payload, parsedPayload);
}
Also used : JsonOutboundMessageMapper(org.springframework.integration.support.json.JsonOutboundMessageMapper) Test(org.junit.Test)

Example 2 with JsonOutboundMessageMapper

use of org.springframework.integration.support.json.JsonOutboundMessageMapper in project spring-integration by spring-projects.

the class JsonOutboundMessageMapperTests method testFromMessageWithHeadersAndStringPayload.

@Test
public void testFromMessageWithHeadersAndStringPayload() throws Exception {
    Message<String> testMessage = MessageBuilder.withPayload("myPayloadStuff").build();
    JsonOutboundMessageMapper mapper = new JsonOutboundMessageMapper();
    String result = mapper.fromMessage(testMessage);
    assertTrue(result.contains("\"headers\":{"));
    assertTrue(result.contains("\"timestamp\":" + testMessage.getHeaders().getTimestamp()));
    assertTrue(result.contains("\"id\":\"" + testMessage.getHeaders().getId() + "\""));
    assertTrue(result.contains("\"payload\":\"myPayloadStuff\""));
}
Also used : JsonOutboundMessageMapper(org.springframework.integration.support.json.JsonOutboundMessageMapper) Test(org.junit.Test)

Example 3 with JsonOutboundMessageMapper

use of org.springframework.integration.support.json.JsonOutboundMessageMapper in project spring-integration by spring-projects.

the class AbstractJsonSymmetricalMessageMappingTests method testSymmetricalMappingWithHistory.

@Test
public void testSymmetricalMappingWithHistory() throws Exception {
    Message<String> testMessage = MessageBuilder.withPayload("myPayloadStuff").build();
    testMessage = MessageHistory.write(testMessage, new TestNamedComponent(1));
    testMessage = MessageHistory.write(testMessage, new TestNamedComponent(2));
    testMessage = MessageHistory.write(testMessage, new TestNamedComponent(3));
    JsonOutboundMessageMapper outboundMapper = new JsonOutboundMessageMapper();
    String outboundJson = outboundMapper.fromMessage(testMessage);
    JsonInboundMessageMapper inboundMapper = new JsonInboundMessageMapper(String.class, getParser());
    Message<?> result = inboundMapper.toMessage(outboundJson);
    assertThat(result, sameExceptImmutableHeaders(testMessage));
}
Also used : JsonInboundMessageMapper(org.springframework.integration.support.json.JsonInboundMessageMapper) JsonOutboundMessageMapper(org.springframework.integration.support.json.JsonOutboundMessageMapper) Test(org.junit.Test)

Example 4 with JsonOutboundMessageMapper

use of org.springframework.integration.support.json.JsonOutboundMessageMapper in project spring-integration by spring-projects.

the class JsonOutboundMessageMapperTests method testFromMessageExtractStringPayload.

@Test
public void testFromMessageExtractStringPayload() throws Exception {
    Message<String> testMessage = MessageBuilder.withPayload("myPayloadStuff").build();
    String expected = "\"myPayloadStuff\"";
    JsonOutboundMessageMapper mapper = new JsonOutboundMessageMapper();
    mapper.setShouldExtractPayload(true);
    String result = mapper.fromMessage(testMessage);
    assertEquals(expected, result);
}
Also used : JsonOutboundMessageMapper(org.springframework.integration.support.json.JsonOutboundMessageMapper) Test(org.junit.Test)

Example 5 with JsonOutboundMessageMapper

use of org.springframework.integration.support.json.JsonOutboundMessageMapper in project spring-integration by spring-projects.

the class JsonOutboundMessageMapperTests method testFromMessageWithMessageHistory.

@Test
public void testFromMessageWithMessageHistory() throws Exception {
    Message<String> testMessage = MessageBuilder.withPayload("myPayloadStuff").build();
    testMessage = MessageHistory.write(testMessage, new TestNamedComponent(1));
    testMessage = MessageHistory.write(testMessage, new TestNamedComponent(2));
    testMessage = MessageHistory.write(testMessage, new TestNamedComponent(3));
    JsonOutboundMessageMapper mapper = new JsonOutboundMessageMapper();
    String result = mapper.fromMessage(testMessage);
    assertTrue(result.contains("\"headers\":{"));
    assertTrue(result.contains("\"timestamp\":" + testMessage.getHeaders().getTimestamp()));
    assertTrue(result.contains("\"id\":\"" + testMessage.getHeaders().getId() + "\""));
    assertTrue(result.contains("\"payload\":\"myPayloadStuff\""));
    assertTrue(result.contains("\"history\":"));
    assertTrue(result.contains("testName-1"));
    assertTrue(result.contains("testType-1"));
    assertTrue(result.contains("testName-2"));
    assertTrue(result.contains("testType-2"));
    assertTrue(result.contains("testName-3"));
    assertTrue(result.contains("testType-3"));
}
Also used : JsonOutboundMessageMapper(org.springframework.integration.support.json.JsonOutboundMessageMapper) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 JsonOutboundMessageMapper (org.springframework.integration.support.json.JsonOutboundMessageMapper)7 JsonInboundMessageMapper (org.springframework.integration.support.json.JsonInboundMessageMapper)2 CallableStatement (java.sql.CallableStatement)1 Jackson2JsonMessageParser (org.springframework.integration.support.json.Jackson2JsonMessageParser)1 Transactional (org.springframework.transaction.annotation.Transactional)1