View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.config.spring.parsers.specific;
8   
9   import org.mule.api.endpoint.EndpointBuilder;
10  import org.mule.api.endpoint.InboundEndpoint;
11  import org.mule.api.processor.MessageProcessor;
12  import org.mule.processor.NullMessageProcessor;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertEquals;
18  
19  public class CompositeMessageProcessorDefinitionParserTestCase extends FunctionalTestCase
20  {
21  
22      @Override
23      protected String getConfigResources()
24      {
25          return "org/mule/config/spring/parsers/specific/composite-message-processor.xml";
26      }
27  
28      @Test
29      public void testInterceptingComposite() throws Exception
30      {
31          MessageProcessor composite = muleContext.getRegistry().lookupObject("composite1");
32          assertEquals("0123", composite.process(getTestEvent("0")).getMessageAsString());
33      }
34  
35      @Test
36      public void testInterceptingNestedComposite() throws Exception
37      {
38          MessageProcessor composite = muleContext.getRegistry().lookupObject("composite2");
39          assertEquals("01abc2", composite.process(getTestEvent("0")).getMessageAsString());
40      }
41  
42      @Test
43      public void testInterceptingCompositeOnEndpoint() throws Exception
44      {
45          EndpointBuilder endpointBuilder = muleContext.getRegistry().lookupEndpointBuilder("endpoint");
46          InboundEndpoint endpoint = endpointBuilder.buildInboundEndpoint();
47          assertEquals(3, endpoint.getMessageProcessors().size());
48  
49          MessageProcessor endpointProcessor = endpoint.getMessageProcessorsFactory()
50              .createInboundMessageProcessorChain(endpoint, null, new NullMessageProcessor());
51  
52          assertEquals("01231abc2", endpointProcessor.process(getTestEvent("0")).getMessageAsString());
53      }
54  
55  }