1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.http.functional;
12
13 import org.mule.api.MuleException;
14 import org.mule.api.MuleMessage;
15 import org.mule.api.endpoint.InboundEndpoint;
16 import org.mule.api.transformer.DataType;
17 import org.mule.module.client.MuleClient;
18 import org.mule.tck.DynamicPortTestCase;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 public class TwoEndpointsSinglePortTestCase extends DynamicPortTestCase
24 {
25
26 protected String getConfigResources()
27 {
28 return "two-endpoints-single-port.xml";
29 }
30
31 public void testSendToEach() throws Exception
32 {
33
34 sendWithResponse("inMyComponent1", "test", "mycomponent1", 10);
35 sendWithResponse("inMyComponent2", "test", "mycomponent2", 10);
36 }
37
38 public void testSendToEachWithBadEndpoint() throws Exception
39 {
40
41 MuleClient client = new MuleClient(muleContext);
42
43 sendWithResponse("inMyComponent1", "test", "mycomponent1", 5);
44 sendWithResponse("inMyComponent2", "test", "mycomponent2", 5);
45
46 MuleMessage result = client.send("http://localhost:" + getPorts().get(0) + "/mycomponent-notfound", "test", null);
47 assertNotNull(result);
48 assertNotNull(result.getExceptionPayload());
49 final int status = result.getInboundProperty("http.status", 0);
50 assertEquals(404, status);
51
52
53 sendWithResponse("inMyComponent1", "test", "mycomponent1", 5);
54 sendWithResponse("inMyComponent2", "test", "mycomponent2", 5);
55 }
56
57 protected void sendWithResponse(String endPointName, String message, String response, int noOfMessages)
58 throws MuleException
59 {
60 MuleClient client = new MuleClient(muleContext);
61
62 List results = new ArrayList();
63 for (int i = 0; i < noOfMessages; i++)
64 {
65 results.add(client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject(endPointName)).getAddress(), message, null).getPayload(DataType.BYTE_ARRAY_DATA_TYPE));
66 }
67
68 assertEquals(noOfMessages, results.size());
69 for (int i = 0; i < noOfMessages; i++)
70 {
71 assertEquals(response, new String((byte[])results.get(i)));
72 }
73 }
74
75 @Override
76 protected int getNumPortsToFind()
77 {
78 return 1;
79 }
80 }