use of org.springframework.integration.support.json.JsonInboundMessageMapper in project spring-integration by spring-projects.
the class AbstractJsonInboundMessageMapperTests method testToMessageInvalidFormatHeadersAndBeanPayloadWithMapToPayloadNotFail.
@Test
public void testToMessageInvalidFormatHeadersAndBeanPayloadWithMapToPayloadNotFail() throws Exception {
TestBean bean = new TestBean();
UUID id = UUID.randomUUID();
String jsonMessage = "{\"headers\":{\"$timestamp\":1,\"$id\":\"" + id + "\"},\"payload\":" + getBeanAsJson(bean) + "}";
JsonInboundMessageMapper mapper = new JsonInboundMessageMapper(TestBean.class, getParser());
mapper.setMapToPayload(true);
Message<?> message = mapper.toMessage(jsonMessage);
assertEquals(bean, message.getPayload());
}
use of org.springframework.integration.support.json.JsonInboundMessageMapper in project spring-integration by spring-projects.
the class AbstractJsonInboundMessageMapperTests method testToMessageWithBeanHeaderAndStringPayload.
@Test
public void testToMessageWithBeanHeaderAndStringPayload() throws Exception {
TestBean bean = new TestBean();
UUID id = UUID.randomUUID();
String jsonMessage = "{\"headers\":{\"timestamp\":1,\"id\":\"" + id + "\", \"myHeader\":" + getBeanAsJson(bean) + "},\"payload\":\"myPayloadStuff\"}";
Message<String> expected = MessageBuilder.withPayload("myPayloadStuff").setHeader("myHeader", bean).build();
JsonInboundMessageMapper mapper = new JsonInboundMessageMapper(String.class, getParser());
Map<String, Class<?>> headerTypes = new HashMap<String, Class<?>>();
headerTypes.put("myHeader", TestBean.class);
mapper.setHeaderTypes(headerTypes);
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 RedisQueueOutboundChannelAdapterTests method testInt3017IntegrationOutbound.
@Test
@RedisAvailable
public void testInt3017IntegrationOutbound() throws Exception {
final String queueName = "si.test.Int3017IntegrationOutbound";
GenericMessage<Object> message = new GenericMessage<Object>(queueName);
this.sendChannel.send(message);
RedisTemplate<String, String> redisTemplate = new StringRedisTemplate();
redisTemplate.setConnectionFactory(this.connectionFactory);
redisTemplate.afterPropertiesSet();
String result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
assertNotNull(result);
InboundMessageMapper<String> mapper = new JsonInboundMessageMapper(String.class, new Jackson2JsonMessageParser());
Message<?> resultMessage = mapper.toMessage(result);
assertEquals(message.getPayload(), resultMessage.getPayload());
}
use of org.springframework.integration.support.json.JsonInboundMessageMapper 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.JsonInboundMessageMapper in project spring-integration by spring-projects.
the class AbstractJsonInboundMessageMapperTests method testToMessageWithBeanPayload.
@Test
public void testToMessageWithBeanPayload() throws Exception {
TestBean expected = new TestBean();
String jsonMessage = getBeanAsJson(expected);
JsonInboundMessageMapper mapper = new JsonInboundMessageMapper(TestBean.class, getParser());
mapper.setMapToPayload(true);
Message<?> result = mapper.toMessage(jsonMessage);
assertEquals(expected, result.getPayload());
}
Aggregations