use of org.springframework.integration.support.json.JsonInboundMessageMapper in project spring-integration by spring-projects.
the class AbstractJsonInboundMessageMapperTests method testToMessageWithHeadersAndListOfStringsPayload.
@Test
public void testToMessageWithHeadersAndListOfStringsPayload() throws Exception {
UUID id = UUID.randomUUID();
String jsonMessage = "{\"headers\":{\"timestamp\":1,\"id\":\"" + id + "\",\"foo\":123,\"bar\":\"abc\"}," + "\"payload\":[\"myPayloadStuff1\",\"myPayloadStuff2\",\"myPayloadStuff3\"]}";
List<String> expectedList = Arrays.asList("myPayloadStuff1", "myPayloadStuff2", "myPayloadStuff3");
Message<List<String>> expected = MessageBuilder.withPayload(expectedList).setHeader("foo", 123).setHeader("bar", "abc").build();
Type type = new ParameterizedTypeReference<List<String>>() {
}.getType();
JsonInboundMessageMapper mapper = new JsonInboundMessageMapper(type, getParser());
Message<?> result = mapper.toMessage(jsonMessage);
assertThat(result, sameExceptImmutableHeaders(expected));
}
use of org.springframework.integration.support.json.JsonInboundMessageMapper in project spring-integration by spring-projects.
the class AbstractJsonInboundMessageMapperTests method testToMessageInvalidFormatHeadersAndStringPayloadWithMapToPayload.
@Test
public void testToMessageInvalidFormatHeadersAndStringPayloadWithMapToPayload() throws Exception {
UUID id = UUID.randomUUID();
String jsonMessage = "{\"headers\":{\"$timestamp\":1,\"$id\":\"" + id + "\"},\"payload\":\"myPayloadStuff\"}";
JsonInboundMessageMapper mapper = new JsonInboundMessageMapper(String.class, getParser());
mapper.setMapToPayload(true);
try {
mapper.toMessage(jsonMessage);
fail();
} catch (IllegalArgumentException ex) {
// Expected
}
}
use of org.springframework.integration.support.json.JsonInboundMessageMapper in project spring-integration by spring-projects.
the class AbstractJsonInboundMessageMapperTests method testToMessageInvalidFormatPayloadNoHeaders.
@Test
public void testToMessageInvalidFormatPayloadNoHeaders() throws Exception {
String jsonMessage = "{\"payload\":\"myPayloadStuff\"}";
JsonInboundMessageMapper mapper = new JsonInboundMessageMapper(String.class, getParser());
try {
mapper.toMessage(jsonMessage);
fail();
} catch (IllegalArgumentException ex) {
// Expected
}
}
use of org.springframework.integration.support.json.JsonInboundMessageMapper in project spring-integration by spring-projects.
the class AbstractJsonInboundMessageMapperTests method testToMessageWithHeadersAndListOfBeansPayload.
@Test
public void testToMessageWithHeadersAndListOfBeansPayload() throws Exception {
TestBean bean1 = new TestBean();
TestBean bean2 = new TestBean();
UUID id = UUID.randomUUID();
String jsonMessage = "{\"headers\":{\"timestamp\":1,\"id\":\"" + id + "\",\"foo\":123,\"bar\":\"abc\"},\"payload\":[" + getBeanAsJson(bean1) + "," + getBeanAsJson(bean2) + "]}";
List<TestBean> expectedList = Arrays.asList(bean1, bean2);
Message<List<TestBean>> expected = MessageBuilder.withPayload(expectedList).setHeader("foo", 123).setHeader("bar", "abc").build();
Type type = new ParameterizedTypeReference<List<TestBean>>() {
}.getType();
JsonInboundMessageMapper mapper = new JsonInboundMessageMapper(type, getParser());
Message<?> result = mapper.toMessage(jsonMessage);
assertThat(result, sameExceptImmutableHeaders(expected));
}
use of org.springframework.integration.support.json.JsonInboundMessageMapper in project spring-integration by spring-projects.
the class AbstractJsonInboundMessageMapperTests method testToMessageWithStringPayload.
@Test
public void testToMessageWithStringPayload() throws Exception {
String jsonMessage = "\"myPayloadStuff\"";
String expected = "myPayloadStuff";
JsonInboundMessageMapper mapper = new JsonInboundMessageMapper(String.class, getParser());
mapper.setMapToPayload(true);
Message<?> result = mapper.toMessage(jsonMessage);
assertEquals(expected, result.getPayload());
}
Aggregations