Search in sources :

Example 1 with JsonObjectMapper

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

the class ChainParserTests method testInt2755SubComponentsIdSupport.

@Test
public void testInt2755SubComponentsIdSupport() {
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1.handler"));
    assertTrue(this.beanFactory.containsBean("filterChain$child.filterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("filterChain$child.serviceActivatorWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain$child.aggregatorWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain$child.filterWithinNestedChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain$child.doubleNestedChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain$child.doubleNestedChain$child.filterWithinDoubleNestedChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain2.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain2$child.aggregatorWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain2$child.nestedChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain2$child.nestedChain$child.filterWithinNestedChain.handler"));
    assertTrue(this.beanFactory.containsBean("payloadTypeRouterChain$child.payloadTypeRouterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("headerValueRouterChain$child.headerValueRouterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("chainWithClaimChecks$child.claimCheckInWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("chainWithClaimChecks$child.claimCheckOutWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("outboundChain$child.outboundChannelAdapterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("logChain$child.transformerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("logChain$child.loggingChannelAdapterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.splitterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.resequencerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.enricherWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.headerFilterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.payloadSerializingTransformerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.payloadDeserializingTransformerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.gatewayWithinChain.handler"));
    // INT-3117
    GatewayProxyFactoryBean gatewayProxyFactoryBean = this.beanFactory.getBean("&subComponentsIdSupport1$child.gatewayWithinChain.handler", GatewayProxyFactoryBean.class);
    assertEquals("strings", TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultRequestChannelName"));
    assertEquals("numbers", TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultReplyChannelName"));
    assertEquals(1000L, TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultRequestTimeout", Expression.class).getValue());
    assertEquals(100L, TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultReplyTimeout", Expression.class).getValue());
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.objectToStringTransformerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.objectToMapTransformerWithinChain.handler"));
    Object transformerHandler = this.beanFactory.getBean("subComponentsIdSupport1$child.objectToMapTransformerWithinChain.handler");
    Object transformer = TestUtils.getPropertyValue(transformerHandler, "transformer");
    assertThat(transformer, instanceOf(ObjectToMapTransformer.class));
    assertFalse(TestUtils.getPropertyValue(transformer, "shouldFlattenKeys", Boolean.class));
    assertSame(this.beanFactory.getBean(JsonObjectMapper.class), TestUtils.getPropertyValue(transformer, "jsonObjectMapper"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.mapToObjectTransformerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.controlBusWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.routerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("exceptionTypeRouterChain$child.exceptionTypeRouterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("recipientListRouterChain$child.recipientListRouterWithinChain.handler"));
    MessageHandlerChain chain = this.beanFactory.getBean("headerEnricherChain.handler", MessageHandlerChain.class);
    List<?> handlers = TestUtils.getPropertyValue(chain, "handlers", List.class);
    assertTrue(handlers.get(0) instanceof MessageTransformingHandler);
    assertEquals("headerEnricherChain$child.headerEnricherWithinChain", TestUtils.getPropertyValue(handlers.get(0), "componentName"));
    assertEquals("headerEnricherChain$child.headerEnricherWithinChain.handler", TestUtils.getPropertyValue(handlers.get(0), "beanName"));
    assertTrue(this.beanFactory.containsBean("headerEnricherChain$child.headerEnricherWithinChain.handler"));
    assertTrue(handlers.get(1) instanceof ServiceActivatingHandler);
    assertEquals("headerEnricherChain$child#1", TestUtils.getPropertyValue(handlers.get(1), "componentName"));
    assertEquals("headerEnricherChain$child#1.handler", TestUtils.getPropertyValue(handlers.get(1), "beanName"));
    assertFalse(this.beanFactory.containsBean("headerEnricherChain$child#1.handler"));
}
Also used : GatewayProxyFactoryBean(org.springframework.integration.gateway.GatewayProxyFactoryBean) MessageTransformingHandler(org.springframework.integration.transformer.MessageTransformingHandler) MessageHandlerChain(org.springframework.integration.handler.MessageHandlerChain) ObjectToMapTransformer(org.springframework.integration.transformer.ObjectToMapTransformer) JsonObjectMapper(org.springframework.integration.support.json.JsonObjectMapper) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 2 with JsonObjectMapper

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

the class JsonToObjectTransformerParserTests method testInt2831CustomJsonObjectMapper.

@Test
public void testInt2831CustomJsonObjectMapper() {
    Object jsonToObjectTransformer = TestUtils.getPropertyValue(this.customJsonMapperTransformer, "transformer");
    assertSame(this.jsonObjectMapper, TestUtils.getPropertyValue(jsonToObjectTransformer, "jsonObjectMapper", JsonObjectMapper.class));
    String jsonString = "{firstName:'John', lastName:'Doe', age:42, address:{number:123, street:'Main Street'}}";
    QueueChannel replyChannel = new QueueChannel();
    Message<String> message = MessageBuilder.withPayload(jsonString).setReplyChannel(replyChannel).build();
    this.customJsonObjectMapperInput.send(message);
    Message<?> reply = replyChannel.receive(0);
    assertNotNull(reply);
    assertNotNull(reply.getPayload());
    assertEquals(TestJsonContainer.class, reply.getPayload().getClass());
    TestJsonContainer result = (TestJsonContainer) reply.getPayload();
    assertEquals(jsonString, result.getJson());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Jackson2JsonObjectMapper(org.springframework.integration.support.json.Jackson2JsonObjectMapper) JsonObjectMapper(org.springframework.integration.support.json.JsonObjectMapper) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 JsonObjectMapper (org.springframework.integration.support.json.JsonObjectMapper)2 QueueChannel (org.springframework.integration.channel.QueueChannel)1 GatewayProxyFactoryBean (org.springframework.integration.gateway.GatewayProxyFactoryBean)1 MessageHandlerChain (org.springframework.integration.handler.MessageHandlerChain)1 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)1 Jackson2JsonObjectMapper (org.springframework.integration.support.json.Jackson2JsonObjectMapper)1 MessageTransformingHandler (org.springframework.integration.transformer.MessageTransformingHandler)1 ObjectToMapTransformer (org.springframework.integration.transformer.ObjectToMapTransformer)1