Search in sources :

Example 11 with JsonInboundMessageMapper

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

Example 12 with JsonInboundMessageMapper

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

Example 13 with JsonInboundMessageMapper

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

Example 14 with JsonInboundMessageMapper

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

Example 15 with JsonInboundMessageMapper

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