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