1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers.http.functional;
12
13 import org.mule.extras.client.MuleClient;
14 import org.mule.tck.FunctionalTestCase;
15 import org.mule.umo.UMOException;
16 import org.mule.umo.UMOMessage;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 public class TwoEndpointsSinglePortTestCase extends FunctionalTestCase
22 {
23 public TwoEndpointsSinglePortTestCase()
24 {
25 setDisposeManagerPerSuite(true);
26 }
27
28 protected String getConfigResources()
29 {
30 return "two-endpoints-single-port.xml";
31 }
32
33 public void testSendToEach() throws Exception
34 {
35
36 sendWithResponse("http://localhost:60211/mycomponent1", "test", "mycomponent1", 10);
37 sendWithResponse("http://localhost:60211/mycomponent2", "test", "mycomponent2", 10);
38 }
39
40 public void testSendToEachWithBadEndpoint() throws Exception
41 {
42
43 MuleClient client = new MuleClient();
44
45 sendWithResponse("http://localhost:60211/mycomponent1", "test", "mycomponent1", 5);
46 sendWithResponse("http://localhost:60211/mycomponent2", "test", "mycomponent2", 5);
47
48 UMOMessage result = client.send("http://localhost:60211/mycomponent-notfound", "test", null);
49 assertNotNull(result);
50 assertNotNull(result.getExceptionPayload());
51 assertEquals(404, result.getIntProperty("http.status", 0));
52
53
54 sendWithResponse("http://localhost:60211/mycomponent1", "test", "mycomponent1", 5);
55 sendWithResponse("http://localhost:60211/mycomponent2", "test", "mycomponent2", 5);
56 }
57
58 protected void sendWithResponse(String endpoint, String message, String response, int noOfMessages)
59 throws UMOException
60 {
61 MuleClient client = new MuleClient();
62
63 List results = new ArrayList();
64 for (int i = 0; i < noOfMessages; i++)
65 {
66 results.add(client.send(endpoint, message, null).getPayload());
67 }
68
69 assertEquals(noOfMessages, results.size());
70 for (int i = 0; i < noOfMessages; i++)
71 {
72 assertEquals(response, new String((byte[])results.get(i)));
73 }
74 }
75 }