1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.integration;
12
13 import org.mule.DefaultMuleEvent;
14 import org.mule.DefaultMuleMessage;
15 import org.mule.MessageExchangePattern;
16 import org.mule.api.MuleEvent;
17 import org.mule.api.endpoint.ImmutableEndpoint;
18 import org.mule.api.endpoint.InboundEndpoint;
19 import org.mule.api.endpoint.OutboundEndpoint;
20 import org.mule.api.processor.MessageProcessor;
21 import org.mule.api.routing.OutboundRouter;
22 import org.mule.construct.Flow;
23 import org.mule.endpoint.DefaultInboundEndpoint;
24 import org.mule.module.xml.transformer.ObjectToXml;
25 import org.mule.tck.MuleTestUtils;
26 import org.mule.tck.junit4.FunctionalTestCase;
27 import org.mule.transport.tcp.TcpConnector;
28 import org.mule.transport.vm.VMConnector;
29
30 import java.util.List;
31
32 import org.junit.Test;
33
34 import static org.junit.Assert.assertEquals;
35 import static org.junit.Assert.assertFalse;
36 import static org.junit.Assert.assertNotNull;
37 import static org.junit.Assert.assertTrue;
38
39
40
41
42 public class MuleEndpointConfigurationFlowTestCase extends FunctionalTestCase
43 {
44 @Override
45 protected String getConfigResources()
46 {
47 return "org/mule/test/integration/test-endpoints-config-flow.xml";
48 }
49
50 @Test
51 public void testComponent3RouterEndpoints() throws Exception
52 {
53 Object flow = muleContext.getRegistry().lookupObject("TestComponent3");
54
55 assertNotNull(flow);
56 List<MessageProcessor> messageProcessors = ((Flow) flow).getMessageProcessors();
57
58 assertNotNull(messageProcessors);
59 assertEquals(2, messageProcessors.size());
60
61
62 OutboundRouter allRouter = (OutboundRouter) messageProcessors.get(1);
63 assertEquals(3, allRouter.getRoutes().size());
64 ImmutableEndpoint endpoint = (ImmutableEndpoint) allRouter.getRoutes().get(0);
65 assertEquals("tcp", endpoint.getConnector().getProtocol().toLowerCase());
66 assertEquals("tcp://localhost:60201", endpoint.getEndpointURI().getAddress());
67 assertTrue(endpoint instanceof OutboundEndpoint);
68
69 endpoint = (ImmutableEndpoint) allRouter.getRoutes().get(1);
70 assertEquals("udp", endpoint.getConnector().getProtocol().toLowerCase());
71 assertEquals("udp://localhost:56731", endpoint.getEndpointURI().getAddress());
72 assertTrue(endpoint instanceof OutboundEndpoint);
73
74 endpoint = (ImmutableEndpoint) allRouter.getRoutes().get(2);
75 assertEquals("test", endpoint.getConnector().getProtocol().toLowerCase());
76 assertEquals("test.queue2", endpoint.getEndpointURI().getAddress());
77 assertTrue(endpoint instanceof OutboundEndpoint);
78 }
79
80 @Test
81 public void testComponent4InboundEndpoint() throws Exception
82 {
83 Object flow = muleContext.getRegistry().lookupObject("TestComponent4");
84
85 assertNotNull(flow);
86 assertNotNull(((Flow) flow).getMessageSource());
87
88 assertEquals(2, ((DefaultInboundEndpoint) ((Flow) flow).getMessageSource()).getMessageProcessors()
89 .size());
90
91 ImmutableEndpoint endpoint = ((DefaultInboundEndpoint) ((Flow) flow).getMessageSource());
92 assertNotNull(endpoint);
93 assertEquals(VMConnector.VM, endpoint.getConnector().getProtocol().toLowerCase());
94 assertEquals("queue4", endpoint.getEndpointURI().getAddress());
95 assertFalse(endpoint.getTransformers().isEmpty());
96 assertTrue(endpoint.getTransformers().get(0) instanceof ObjectToXml);
97 assertTrue(endpoint instanceof InboundEndpoint);
98 }
99
100 @Test
101 public void testComponent4OutboundEndpoint() throws Exception
102 {
103 Object flow = muleContext.getRegistry().lookupObject("TestComponent4");
104
105 assertNotNull(flow);
106 List<MessageProcessor> messageProcessors = ((Flow) flow).getMessageProcessors();
107 assertNotNull(messageProcessors);
108
109 ImmutableEndpoint endpoint = (ImmutableEndpoint) messageProcessors.get(1);
110 assertEquals("udp", endpoint.getConnector().getProtocol().toLowerCase());
111 assertEquals("udp://localhost:56731", endpoint.getEndpointURI().getAddress());
112
113
114
115 assertTrue(endpoint instanceof OutboundEndpoint);
116 }
117
118 @Test
119 public void testComponent5RouterEndpoints() throws Exception
120 {
121 Object flow = muleContext.getRegistry().lookupObject("TestComponent5");
122
123 assertNotNull(flow);
124 List<MessageProcessor> messageProcessors = ((Flow) flow).getMessageProcessors();
125 assertNotNull(messageProcessors);
126
127 ImmutableEndpoint endpoint = (ImmutableEndpoint) messageProcessors.get(1);
128 assertEquals(TcpConnector.TCP, endpoint.getConnector().getProtocol().toLowerCase());
129 assertEquals("tcp://localhost:45431", endpoint.getEndpointURI().getAddress());
130
131
132
133 assertTrue(endpoint instanceof OutboundEndpoint);
134 }
135
136 @Test
137 public void testEndpointFromURI() throws Exception
138 {
139 ImmutableEndpoint ep = muleContext.getEndpointFactory().getInboundEndpoint(
140 "test://hello?exchangePattern=request-response&responseTimeout=2002&connector=testConnector1");
141 assertEquals(MessageExchangePattern.REQUEST_RESPONSE, ep.getExchangePattern());
142 assertEquals(2002, ep.getResponseTimeout());
143 assertTrue(ep instanceof InboundEndpoint);
144
145
146 MuleEvent event = new DefaultMuleEvent(new DefaultMuleMessage("hello", muleContext),
147 (InboundEndpoint) ep, MuleTestUtils.getTestSession(muleContext));
148 assertEquals(2002, event.getTimeout());
149
150 ImmutableEndpoint ep2 = muleContext.getEndpointFactory().getInboundEndpoint(
151 "test://hello?connector=testConnector1");
152
153 event = new DefaultMuleEvent(new DefaultMuleMessage("hello", muleContext), (InboundEndpoint) ep2,
154 MuleTestUtils.getTestSession(muleContext));
155
156 assertEquals(1001, event.getTimeout());
157 }
158 }