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.endpoint;
8   
9   import org.mule.api.MuleException;
10  import org.mule.api.endpoint.ImmutableEndpoint;
11  import org.mule.api.processor.MessageProcessor;
12  import org.mule.api.processor.MessageProcessorChain;
13  import org.mule.api.routing.OutboundRouterCollection;
14  import org.mule.routing.outbound.OutboundPassThroughRouter;
15  import org.mule.service.ServiceCompositeMessageSource;
16  import org.mule.tck.junit4.FunctionalTestCase;
17  import org.mule.tck.testmodels.mule.TestMessageProcessor;
18  
19  import java.util.List;
20  
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNotNull;
25  import static org.junit.Assert.assertTrue;
26  
27  public class EndpointMessageProcessorsTestCase extends FunctionalTestCase
28  {
29  
30      @Override
31      protected String getConfigResources()
32      {
33          return "org/mule/config/spring/parsers/endpoint/endpoint-message-processors.xml";
34      }
35  
36      @Test
37      public void testGlobalEndpoint1() throws MuleException
38      {
39          ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep1");
40          
41          List <MessageProcessor> processors = endpoint.getMessageProcessors();
42          assertNotNull(processors);
43          assertEquals(2, processors.size());
44          assertTrue(processors.get(0) instanceof TestMessageProcessor);
45  
46          processors = endpoint.getResponseMessageProcessors();
47          assertNotNull(processors);
48          assertEquals(1, processors.size());
49          assertTrue(processors.get(0) instanceof MessageProcessorChain);
50      }
51  
52      @Test
53      public void testGlobalEndpoint2() throws MuleException
54      {
55          ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep2");
56          
57          List <MessageProcessor> processors = endpoint.getMessageProcessors();
58          assertNotNull(processors);
59          assertEquals(3, processors.size());
60          assertEquals("1", ((TestMessageProcessor) processors.get(0)).getLabel());
61          assertEquals("2", ((TestMessageProcessor) processors.get(1)).getLabel());
62  
63          processors = endpoint.getResponseMessageProcessors();
64          assertNotNull(processors);
65  
66          assertEquals(1, processors.size());
67          assertTrue(processors.get(0) instanceof MessageProcessorChain);
68          MessageProcessorChain chain = (MessageProcessorChain) processors.get(0);
69          assertEquals("3", ((TestMessageProcessor) chain.getMessageProcessors().get(0)).getLabel());
70          assertEquals("4", ((TestMessageProcessor) chain.getMessageProcessors().get(1)).getLabel());
71      }
72      
73      @Test
74      public void testLocalEndpoints() throws MuleException
75      {
76          ImmutableEndpoint endpoint = 
77              ((ServiceCompositeMessageSource) muleContext.getRegistry().lookupService("localEndpoints").getMessageSource()).getEndpoint("ep3");
78  
79          List <MessageProcessor> processors = endpoint.getMessageProcessors();
80          assertNotNull(processors);
81          assertEquals(3, processors.size());
82          assertEquals("A", ((TestMessageProcessor) processors.get(0)).getLabel());
83          assertEquals("B", ((TestMessageProcessor) processors.get(1)).getLabel());
84  
85          processors = endpoint.getResponseMessageProcessors();
86          assertNotNull(processors);
87          assertEquals(1, processors.size());
88          assertTrue(processors.get(0) instanceof MessageProcessorChain);
89          MessageProcessorChain chain = (MessageProcessorChain) processors.get(0);
90          assertEquals(2, chain.getMessageProcessors().size());
91          assertEquals("C", ((TestMessageProcessor) chain.getMessageProcessors().get(0)).getLabel());
92          assertEquals("D", ((TestMessageProcessor) chain.getMessageProcessors().get(1)).getLabel());
93  
94          MessageProcessor mp =
95              ((OutboundPassThroughRouter) ((OutboundRouterCollection)muleContext.getRegistry().lookupService("localEndpoints").
96                  getOutboundMessageProcessor()).getRoutes().get(0)).getRoute("ep4");
97  
98          endpoint = (ImmutableEndpoint) mp;
99          processors = endpoint.getMessageProcessors();
100         assertNotNull(processors);
101         assertEquals(2, processors.size());
102         assertEquals("E", ((TestMessageProcessor) processors.get(0)).getLabel());
103         assertEquals("F", ((TestMessageProcessor) processors.get(1)).getLabel());
104 
105         processors = endpoint.getResponseMessageProcessors();
106         assertNotNull(processors);
107         assertEquals(1, processors.size());
108         assertTrue(processors.get(0) instanceof MessageProcessorChain);
109         chain = (MessageProcessorChain) processors.get(0);
110         assertEquals(2, chain.getMessageProcessors().size());
111         assertEquals("G", ((TestMessageProcessor) chain.getMessageProcessors().get(0)).getLabel());
112         assertEquals("H", ((TestMessageProcessor) chain.getMessageProcessors().get(1)).getLabel());
113     }
114 }