View Javadoc

1   /*
2    * $Id: EndpointMessageProcessorsTestCase.java 20781 2010-12-16 13:19:09Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.config.spring.parsers.endpoint;
12  
13  import org.mule.api.MuleException;
14  import org.mule.api.endpoint.ImmutableEndpoint;
15  import org.mule.api.processor.MessageProcessor;
16  import org.mule.api.processor.MessageProcessorChain;
17  import org.mule.api.routing.OutboundRouterCollection;
18  import org.mule.routing.outbound.OutboundPassThroughRouter;
19  import org.mule.service.ServiceCompositeMessageSource;
20  import org.mule.tck.FunctionalTestCase;
21  import org.mule.tck.testmodels.mule.TestMessageProcessor;
22  
23  import java.util.List;
24  
25  public class EndpointMessageProcessorsTestCase extends FunctionalTestCase
26  {
27  
28      protected String getConfigResources()
29      {
30          return "org/mule/config/spring/parsers/endpoint/endpoint-message-processors.xml";
31      }
32  
33      public void testGlobalEndpoint1() throws MuleException
34      {
35          ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep1");
36          
37          List <MessageProcessor> processors = endpoint.getMessageProcessors();
38          assertNotNull(processors);
39          assertEquals(1, processors.size());
40          assertTrue(processors.get(0) instanceof TestMessageProcessor);
41  
42          processors = endpoint.getResponseMessageProcessors();
43          assertNotNull(processors);
44          assertEquals(1, processors.size());
45          assertTrue(processors.get(0) instanceof MessageProcessorChain);
46      }
47  
48      public void testGlobalEndpoint2() throws MuleException
49      {
50          ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep2");
51          
52          List <MessageProcessor> processors = endpoint.getMessageProcessors();
53          assertNotNull(processors);
54          assertEquals(2, processors.size());
55          assertEquals("1", ((TestMessageProcessor) processors.get(0)).getLabel());
56          assertEquals("2", ((TestMessageProcessor) processors.get(1)).getLabel());
57  
58          processors = endpoint.getResponseMessageProcessors();
59          assertNotNull(processors);
60  
61          assertEquals(1, processors.size());
62          assertTrue(processors.get(0) instanceof MessageProcessorChain);
63          MessageProcessorChain chain = (MessageProcessorChain) processors.get(0);
64          assertEquals("3", ((TestMessageProcessor) chain.getMessageProcessors().get(0)).getLabel());
65          assertEquals("4", ((TestMessageProcessor) chain.getMessageProcessors().get(1)).getLabel());
66      }
67      
68      public void testLocalEndpoints() throws MuleException
69      {
70          ImmutableEndpoint endpoint = 
71              ((ServiceCompositeMessageSource) muleContext.getRegistry().lookupService("localEndpoints").getMessageSource()).getEndpoint("ep3");
72  
73          List <MessageProcessor> processors = endpoint.getMessageProcessors();
74          assertNotNull(processors);
75          assertEquals(2, processors.size());
76          assertEquals("A", ((TestMessageProcessor) processors.get(0)).getLabel());
77          assertEquals("B", ((TestMessageProcessor) processors.get(1)).getLabel());
78  
79          processors = endpoint.getResponseMessageProcessors();
80          assertNotNull(processors);
81          assertEquals(1, processors.size());
82          assertTrue(processors.get(0) instanceof MessageProcessorChain);
83          MessageProcessorChain chain = (MessageProcessorChain) processors.get(0);
84          assertEquals(2, chain.getMessageProcessors().size());
85          assertEquals("C", ((TestMessageProcessor) chain.getMessageProcessors().get(0)).getLabel());
86          assertEquals("D", ((TestMessageProcessor) chain.getMessageProcessors().get(1)).getLabel());
87  
88          MessageProcessor mp =
89              ((OutboundPassThroughRouter) ((OutboundRouterCollection)muleContext.getRegistry().lookupService("localEndpoints").
90                  getOutboundMessageProcessor()).getRoutes().get(0)).getRoute("ep4");
91  
92          endpoint = (ImmutableEndpoint) mp;
93          processors = endpoint.getMessageProcessors();
94          assertNotNull(processors);
95          assertEquals(2, processors.size());
96          assertEquals("E", ((TestMessageProcessor) processors.get(0)).getLabel());
97          assertEquals("F", ((TestMessageProcessor) processors.get(1)).getLabel());
98  
99          processors = endpoint.getResponseMessageProcessors();
100         assertNotNull(processors);
101         assertEquals(1, processors.size());
102         assertTrue(processors.get(0) instanceof MessageProcessorChain);
103         chain = (MessageProcessorChain) processors.get(0);
104         assertEquals(2, chain.getMessageProcessors().size());
105         assertEquals("G", ((TestMessageProcessor) chain.getMessageProcessors().get(0)).getLabel());
106         assertEquals("H", ((TestMessageProcessor) chain.getMessageProcessors().get(1)).getLabel());
107     }
108 }