View Javadoc

1   /*
2    * $Id: EndpointMessageProcessorsTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.routing.OutboundRouterCollection;
17  import org.mule.routing.outbound.OutboundPassThroughRouter;
18  import org.mule.service.ServiceCompositeMessageSource;
19  import org.mule.tck.FunctionalTestCase;
20  import org.mule.tck.testmodels.mule.TestMessageProcessor;
21  
22  import java.util.List;
23  
24  public class EndpointMessageProcessorsTestCase extends FunctionalTestCase
25  {
26  
27      protected String getConfigResources()
28      {
29          return "org/mule/config/spring/parsers/endpoint/endpoint-message-processors.xml";
30      }
31  
32      public void testGlobalEndpoint1() throws MuleException
33      {
34          ImmutableEndpoint endpoint = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint("ep1");
35          
36          List <MessageProcessor> processors = endpoint.getMessageProcessors();
37          assertNotNull(processors);
38          assertEquals(1, processors.size());
39          assertTrue(processors.get(0) instanceof TestMessageProcessor);
40  
41          processors = endpoint.getResponseMessageProcessors();
42          assertNotNull(processors);
43          assertEquals(1, processors.size());
44          assertTrue(processors.get(0) instanceof TestMessageProcessor);
45      }
46  
47      public void testGlobalEndpoint2() throws MuleException
48      {
49          ImmutableEndpoint endpoint = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint("ep2");
50          
51          List <MessageProcessor> processors = endpoint.getMessageProcessors();
52          assertNotNull(processors);
53          assertEquals(2, processors.size());
54          assertEquals("1", ((TestMessageProcessor) processors.get(0)).getLabel());
55          assertEquals("2", ((TestMessageProcessor) processors.get(1)).getLabel());
56  
57          processors = endpoint.getResponseMessageProcessors();
58          assertNotNull(processors);
59          assertEquals(2, processors.size());
60          assertEquals("3", ((TestMessageProcessor) processors.get(0)).getLabel());
61          assertEquals("4", ((TestMessageProcessor) processors.get(1)).getLabel());
62  }
63  
64      public void testLocalEndpoints() throws MuleException
65      {
66          ImmutableEndpoint endpoint = 
67              ((ServiceCompositeMessageSource) muleContext.getRegistry().lookupService("localEndpoints").getMessageSource()).getEndpoint("ep3");
68  
69          List <MessageProcessor> processors = endpoint.getMessageProcessors();
70          assertNotNull(processors);
71          assertEquals(2, processors.size());
72          assertEquals("A", ((TestMessageProcessor) processors.get(0)).getLabel());
73          assertEquals("B", ((TestMessageProcessor) processors.get(1)).getLabel());
74  
75          processors = endpoint.getResponseMessageProcessors();
76          assertNotNull(processors);
77          assertEquals(2, processors.size());
78          assertEquals("C", ((TestMessageProcessor) processors.get(0)).getLabel());
79          assertEquals("D", ((TestMessageProcessor) processors.get(1)).getLabel());
80  
81          MessageProcessor mp =
82              ((OutboundPassThroughRouter) ((OutboundRouterCollection)muleContext.getRegistry().lookupService("localEndpoints").
83                  getOutboundMessageProcessor()).getRoutes().get(0)).getRoute("ep4");
84  
85          endpoint = (ImmutableEndpoint) mp;
86          processors = endpoint.getMessageProcessors();
87          assertNotNull(processors);
88          assertEquals(2, processors.size());
89          assertEquals("E", ((TestMessageProcessor) processors.get(0)).getLabel());
90          assertEquals("F", ((TestMessageProcessor) processors.get(1)).getLabel());
91  
92          processors = endpoint.getResponseMessageProcessors();
93          assertNotNull(processors);
94          assertEquals(2, processors.size());
95          assertEquals("G", ((TestMessageProcessor) processors.get(0)).getLabel());
96          assertEquals("H", ((TestMessageProcessor) processors.get(1)).getLabel());
97      }
98  }