1
2
3
4
5
6
7
8
9
10
11 package org.mule.config.spring.parsers.endpoint;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17 import org.mule.api.MuleException;
18 import org.mule.api.endpoint.ImmutableEndpoint;
19 import org.mule.api.processor.MessageProcessor;
20 import org.mule.api.processor.MessageProcessorChain;
21 import org.mule.api.routing.OutboundRouterCollection;
22 import org.mule.construct.Flow;
23 import org.mule.endpoint.DefaultInboundEndpoint;
24 import org.mule.routing.outbound.OutboundPassThroughRouter;
25 import org.mule.service.ServiceCompositeMessageSource;
26 import org.mule.tck.AbstractServiceAndFlowTestCase;
27 import org.mule.tck.testmodels.mule.TestMessageProcessor;
28
29 import java.util.Arrays;
30 import java.util.Collection;
31 import java.util.List;
32
33 import org.junit.Test;
34 import org.junit.runners.Parameterized.Parameters;
35
36 public class EndpointMessageProcessorsTestCase extends AbstractServiceAndFlowTestCase
37 {
38 public EndpointMessageProcessorsTestCase(ConfigVariant variant, String configResources)
39 {
40 super(variant, configResources);
41 }
42
43 @Parameters
44 public static Collection<Object[]> parameters()
45 {
46 return Arrays.asList(new Object[][]{
47 {ConfigVariant.SERVICE, "org/mule/config/spring/parsers/endpoint/endpoint-message-processors-service.xml"},
48 {ConfigVariant.FLOW, "org/mule/config/spring/parsers/endpoint/endpoint-message-processors-flow.xml"}
49 });
50 }
51
52 @Test
53 public void testGlobalEndpoint1() throws MuleException
54 {
55 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep1");
56
57 List<MessageProcessor> processors = endpoint.getMessageProcessors();
58 assertNotNull(processors);
59 assertEquals(2, processors.size());
60 assertTrue(processors.get(0) instanceof TestMessageProcessor);
61
62 processors = endpoint.getResponseMessageProcessors();
63 assertNotNull(processors);
64 assertEquals(1, processors.size());
65 assertTrue(processors.get(0) instanceof MessageProcessorChain);
66 }
67
68 @Test
69 public void testGlobalEndpoint2() throws MuleException
70 {
71 ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("ep2");
72
73 List<MessageProcessor> processors = endpoint.getMessageProcessors();
74 assertNotNull(processors);
75 assertEquals(3, processors.size());
76 assertEquals("1", ((TestMessageProcessor) processors.get(0)).getLabel());
77 assertEquals("2", ((TestMessageProcessor) processors.get(1)).getLabel());
78
79 processors = endpoint.getResponseMessageProcessors();
80 assertNotNull(processors);
81
82 assertEquals(1, processors.size());
83 assertTrue(processors.get(0) instanceof MessageProcessorChain);
84 MessageProcessorChain chain = (MessageProcessorChain) processors.get(0);
85 assertEquals("3", ((TestMessageProcessor) chain.getMessageProcessors().get(0)).getLabel());
86 assertEquals("4", ((TestMessageProcessor) chain.getMessageProcessors().get(1)).getLabel());
87 }
88
89 @Test
90 public void testLocalEndpoints() throws MuleException
91 {
92 ImmutableEndpoint endpoint;
93
94 if (variant.equals(ConfigVariant.FLOW))
95 {
96 Flow service = muleContext.getRegistry().lookupObject("localEndpoints");
97 endpoint = (ImmutableEndpoint) service.getMessageSource();
98 }
99 else
100 {
101 endpoint = ((ServiceCompositeMessageSource) muleContext.getRegistry()
102 .lookupService("localEndpoints")
103 .getMessageSource()).getEndpoint("ep3");
104 }
105
106 List<MessageProcessor> processors = endpoint.getMessageProcessors();
107 assertNotNull(processors);
108 assertEquals(3, processors.size());
109 assertEquals("A", ((TestMessageProcessor) processors.get(0)).getLabel());
110 assertEquals("B", ((TestMessageProcessor) processors.get(1)).getLabel());
111
112 processors = endpoint.getResponseMessageProcessors();
113 assertNotNull(processors);
114 assertEquals(1, processors.size());
115 assertTrue(processors.get(0) instanceof MessageProcessorChain);
116 MessageProcessorChain chain = (MessageProcessorChain) processors.get(0);
117 assertEquals(2, chain.getMessageProcessors().size());
118 assertEquals("C", ((TestMessageProcessor) chain.getMessageProcessors().get(0)).getLabel());
119 assertEquals("D", ((TestMessageProcessor) chain.getMessageProcessors().get(1)).getLabel());
120
121 MessageProcessor mp;
122
123 if (variant.equals(ConfigVariant.FLOW))
124 {
125 mp = ((Flow) muleContext.getRegistry().lookupObject("localEndpoints")).getMessageProcessors()
126 .get(0);
127 }
128 else
129 {
130 mp = ((OutboundPassThroughRouter) ((OutboundRouterCollection) muleContext.getRegistry()
131 .lookupService("localEndpoints")
132 .getOutboundMessageProcessor()).getRoutes().get(0)).getRoute("ep4");
133 }
134
135 endpoint = (ImmutableEndpoint) mp;
136 processors = endpoint.getMessageProcessors();
137 assertNotNull(processors);
138 assertEquals(2, processors.size());
139 assertEquals("E", ((TestMessageProcessor) processors.get(0)).getLabel());
140 assertEquals("F", ((TestMessageProcessor) processors.get(1)).getLabel());
141
142 processors = endpoint.getResponseMessageProcessors();
143 assertNotNull(processors);
144 assertEquals(1, processors.size());
145 assertTrue(processors.get(0) instanceof MessageProcessorChain);
146 chain = (MessageProcessorChain) processors.get(0);
147 assertEquals(2, chain.getMessageProcessors().size());
148 assertEquals("G", ((TestMessageProcessor) chain.getMessageProcessors().get(0)).getLabel());
149 assertEquals("H", ((TestMessageProcessor) chain.getMessageProcessors().get(1)).getLabel());
150 }
151 }