Search in sources :

Example 1 with MessageHandlerChain

use of org.springframework.integration.handler.MessageHandlerChain 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 MessageHandlerChain

use of org.springframework.integration.handler.MessageHandlerChain in project spring-integration by spring-projects.

the class ChainParserTests method checkSmartLifecycleConfig.

// INT-2605
@Test
public void checkSmartLifecycleConfig() {
    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("ChainParserSmartLifecycleAttributesTest.xml", this.getClass());
    AbstractEndpoint chainEndpoint = ctx.getBean("chain", AbstractEndpoint.class);
    assertEquals(false, chainEndpoint.isAutoStartup());
    assertEquals(256, chainEndpoint.getPhase());
    MessageHandlerChain handlerChain = ctx.getBean("chain.handler", MessageHandlerChain.class);
    assertEquals(3000L, TestUtils.getPropertyValue(handlerChain, "messagingTemplate.sendTimeout"));
    assertEquals(false, TestUtils.getPropertyValue(handlerChain, "running"));
    // INT-3108
    MessageHandler serviceActivator = ctx.getBean("chain$child.sa-within-chain.handler", MessageHandler.class);
    assertTrue(TestUtils.getPropertyValue(serviceActivator, "requiresReply", Boolean.class));
    ctx.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) MessageHandler(org.springframework.messaging.MessageHandler) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MessageHandlerChain(org.springframework.integration.handler.MessageHandlerChain) Test(org.junit.Test)

Example 3 with MessageHandlerChain

use of org.springframework.integration.handler.MessageHandlerChain in project spring-integration by spring-projects.

the class ConsoleOutboundChannelAdapterParserTests method stdoutInsideNestedChain.

// INT-2275
@Test
public void stdoutInsideNestedChain() throws IOException {
    List<?> handlers = TestUtils.getPropertyValue(this.stdoutChainHandler, "handlers", List.class);
    assertEquals(2, handlers.size());
    Object chainHandler = handlers.get(1);
    assertTrue(chainHandler instanceof MessageHandlerChain);
    List<?> nestedChainHandlers = TestUtils.getPropertyValue(chainHandler, "handlers", List.class);
    assertEquals(1, nestedChainHandlers.size());
    Object stdoutHandler = nestedChainHandlers.get(0);
    assertTrue(stdoutHandler instanceof CharacterStreamWritingMessageHandler);
    BufferedWriter bufferedWriter = TestUtils.getPropertyValue(stdoutHandler, "writer", BufferedWriter.class);
    Writer writer = TestUtils.getPropertyValue(bufferedWriter, "out", Writer.class);
    assertEquals(OutputStreamWriter.class, writer.getClass());
    Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding());
    assertEquals(Charset.defaultCharset(), writerCharset);
    Object lock = TestUtils.getPropertyValue(writer, "lock");
    assertEquals(System.out, lock);
    bufferedWriter = Mockito.spy(bufferedWriter);
    DirectFieldAccessor dfa = new DirectFieldAccessor(stdoutHandler);
    dfa.setPropertyValue("writer", bufferedWriter);
    this.stdoutInsideNestedChain.send(new GenericMessage<String>("foo"));
    verify(bufferedWriter, times(1)).write(eq("foobar"));
}
Also used : MessageHandlerChain(org.springframework.integration.handler.MessageHandlerChain) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Charset(java.nio.charset.Charset) CharacterStreamWritingMessageHandler(org.springframework.integration.stream.CharacterStreamWritingMessageHandler) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 MessageHandlerChain (org.springframework.integration.handler.MessageHandlerChain)3 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Charset (java.nio.charset.Charset)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 AbstractEndpoint (org.springframework.integration.endpoint.AbstractEndpoint)1 GatewayProxyFactoryBean (org.springframework.integration.gateway.GatewayProxyFactoryBean)1 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)1 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)1 CharacterStreamWritingMessageHandler (org.springframework.integration.stream.CharacterStreamWritingMessageHandler)1 JsonObjectMapper (org.springframework.integration.support.json.JsonObjectMapper)1 MessageTransformingHandler (org.springframework.integration.transformer.MessageTransformingHandler)1 ObjectToMapTransformer (org.springframework.integration.transformer.ObjectToMapTransformer)1 MessageHandler (org.springframework.messaging.MessageHandler)1