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);
}
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\""));
}
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));
}
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);
}
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"));
}
Aggregations