Search in sources :

Example 6 with JsonInboundMessageMapper

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());
}
Also used : JsonInboundMessageMapper(org.springframework.integration.support.json.JsonInboundMessageMapper) UUID(java.util.UUID) Test(org.junit.Test)

Example 7 with JsonInboundMessageMapper

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));
}
Also used : JsonInboundMessageMapper(org.springframework.integration.support.json.JsonInboundMessageMapper) HashMap(java.util.HashMap) UUID(java.util.UUID) Test(org.junit.Test)

Example 8 with JsonInboundMessageMapper

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());
}
Also used : JsonInboundMessageMapper(org.springframework.integration.support.json.JsonInboundMessageMapper) GenericMessage(org.springframework.messaging.support.GenericMessage) Jackson2JsonMessageParser(org.springframework.integration.support.json.Jackson2JsonMessageParser) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 9 with JsonInboundMessageMapper

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));
}
Also used : JsonInboundMessageMapper(org.springframework.integration.support.json.JsonInboundMessageMapper) JsonOutboundMessageMapper(org.springframework.integration.support.json.JsonOutboundMessageMapper) Test(org.junit.Test)

Example 10 with JsonInboundMessageMapper

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());
}
Also used : JsonInboundMessageMapper(org.springframework.integration.support.json.JsonInboundMessageMapper) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)17 JsonInboundMessageMapper (org.springframework.integration.support.json.JsonInboundMessageMapper)17 UUID (java.util.UUID)11 Type (java.lang.reflect.Type)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Jackson2JsonMessageParser (org.springframework.integration.support.json.Jackson2JsonMessageParser)2 JsonOutboundMessageMapper (org.springframework.integration.support.json.JsonOutboundMessageMapper)2 CallableStatement (java.sql.CallableStatement)1 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)1 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)1 GenericMessage (org.springframework.messaging.support.GenericMessage)1 Transactional (org.springframework.transaction.annotation.Transactional)1