use of org.springframework.integration.support.json.JsonInboundMessageMapper in project spring-integration by spring-projects.
the class AbstractJsonInboundMessageMapperTests method testToMessageWithHeadersAndPayloadTypeMappingFailure.
@Test
public void testToMessageWithHeadersAndPayloadTypeMappingFailure() throws Exception {
TestBean bean = new TestBean();
UUID id = UUID.randomUUID();
String jsonMessage = "{\"headers\":{\"$timestamp\":1,\"$id\":\"" + id + "\"},\"payload\":" + getBeanAsJson(bean) + "}";
JsonInboundMessageMapper mapper = new JsonInboundMessageMapper(Long.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 testToMessageWithPayloadAndHeadersReversed.
@Test
public void testToMessageWithPayloadAndHeadersReversed() throws Exception {
UUID id = UUID.randomUUID();
String jsonMessage = "{\"payload\":\"myPayloadStuff\",\"headers\":{\"timestamp\":1,\"id\":\"" + id + "\",\"foo\":123,\"bar\":\"abc\"}}";
Message<String> expected = MessageBuilder.withPayload("myPayloadStuff").setHeader("foo", 123).setHeader("bar", "abc").build();
JsonInboundMessageMapper mapper = new JsonInboundMessageMapper(String.class, 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 testToMessageWithHeadersAndBeanPayload.
@Test
public void testToMessageWithHeadersAndBeanPayload() throws Exception {
TestBean bean = new TestBean();
UUID id = UUID.randomUUID();
String jsonMessage = "{\"headers\":{\"timestamp\":1,\"id\":\"" + id + "\",\"foo\":123,\"bar\":\"abc\"},\"payload\":" + getBeanAsJson(bean) + "}";
Message<TestBean> expected = MessageBuilder.withPayload(bean).setHeader("foo", 123).setHeader("bar", "abc").build();
JsonInboundMessageMapper mapper = new JsonInboundMessageMapper(TestBean.class, 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 testToMessageInvalidFormatHeadersNoPayload.
@Test
public void testToMessageInvalidFormatHeadersNoPayload() throws Exception {
UUID id = UUID.randomUUID();
String jsonMessage = "{\"headers\":{\"$timestamp\":1,\"$id\":\"" + id + "\"}}";
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 testToMessageWithHeadersAndStringPayload.
@Test
public void testToMessageWithHeadersAndStringPayload() throws Exception {
UUID id = UUID.randomUUID();
String jsonMessage = "{\"headers\":{\"timestamp\":1,\"id\":\"" + id + "\",\"foo\":123,\"bar\":\"abc\"},\"payload\":\"myPayloadStuff\"}";
Message<String> expected = MessageBuilder.withPayload("myPayloadStuff").setHeader("foo", 123).setHeader("bar", "abc").build();
JsonInboundMessageMapper mapper = new JsonInboundMessageMapper(String.class, getParser());
Message<?> result = mapper.toMessage(jsonMessage);
assertThat(result, sameExceptImmutableHeaders(expected));
}
Aggregations