Search in sources :

Example 1 with Jackson2JsonMessageParser

use of org.springframework.integration.support.json.Jackson2JsonMessageParser 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 2 with Jackson2JsonMessageParser

use of org.springframework.integration.support.json.Jackson2JsonMessageParser in project spring-integration by spring-projects.

the class StoredProcOutboundGatewayWithSpelIntegrationTests method testInt2865SqlReturnType.

@Test
@Transactional
public void testInt2865SqlReturnType() throws Exception {
    Mockito.reset(this.clobSqlReturnType);
    Message<String> testMessage = MessageBuilder.withPayload("TEST").setHeader("FOO", "BAR").build();
    String messageId = testMessage.getHeaders().getId().toString();
    String jsonMessage = new JsonOutboundMessageMapper().fromMessage(testMessage);
    this.jdbcTemplate.update("INSERT INTO json_message VALUES (?,?)", messageId, jsonMessage);
    this.getMessageChannel.send(new GenericMessage<String>(messageId));
    Message<?> resultMessage = this.output2Channel.receive(10000);
    assertNotNull(resultMessage);
    Object resultPayload = resultMessage.getPayload();
    assertTrue(resultPayload instanceof String);
    Message<?> message = new JsonInboundMessageMapper(String.class, new Jackson2JsonMessageParser()).toMessage((String) resultPayload);
    assertEquals(testMessage.getPayload(), message.getPayload());
    assertEquals(testMessage.getHeaders().get("FOO"), message.getHeaders().get("FOO"));
    Mockito.verify(clobSqlReturnType).getTypeValue(Mockito.any(CallableStatement.class), Mockito.eq(2), Mockito.eq(JdbcTypesEnum.CLOB.getCode()), Mockito.eq((String) null));
}
Also used : JsonInboundMessageMapper(org.springframework.integration.support.json.JsonInboundMessageMapper) Jackson2JsonMessageParser(org.springframework.integration.support.json.Jackson2JsonMessageParser) CallableStatement(java.sql.CallableStatement) JsonOutboundMessageMapper(org.springframework.integration.support.json.JsonOutboundMessageMapper) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Test (org.junit.Test)2 Jackson2JsonMessageParser (org.springframework.integration.support.json.Jackson2JsonMessageParser)2 JsonInboundMessageMapper (org.springframework.integration.support.json.JsonInboundMessageMapper)2 CallableStatement (java.sql.CallableStatement)1 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)1 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)1 JsonOutboundMessageMapper (org.springframework.integration.support.json.JsonOutboundMessageMapper)1 GenericMessage (org.springframework.messaging.support.GenericMessage)1 Transactional (org.springframework.transaction.annotation.Transactional)1