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.api.transformer.DataType;
16 import org.mule.module.client.MuleClient;
17 import org.mule.tck.FunctionalTestCase;
18 import org.mule.util.SystemUtils;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 public class JettyContinuationsTwoEndpointsSinglePortTestCase extends FunctionalTestCase
24 {
25
26
27
28
29 @Override
30 protected boolean isDisabledInThisEnvironment()
31 {
32 return SystemUtils.IS_JAVA_1_6;
33 }
34
35 protected String getConfigResources()
36 {
37 return "jetty-continuations-two-endpoints-single-port.xml";
38 }
39
40 public void testSendToEach() throws Exception
41 {
42 sendWithResponse("http://localhost:60211/mycomponent1", "test", "mycomponent1", 10);
43 sendWithResponse("http://localhost:60211/mycomponent2", "test", "mycomponent2", 10);
44 }
45
46 public void testSendToEachWithBadEndpoint() throws Exception
47 {
48
49 MuleClient client = new MuleClient(muleContext);
50
51 sendWithResponse("http://localhost:60211/mycomponent1", "test", "mycomponent1", 5);
52 sendWithResponse("http://localhost:60211/mycomponent2", "test", "mycomponent2", 5);
53
54 MuleMessage result = client.send("http://localhost:60211/mycomponent-notfound", "test", null);
55 assertNotNull(result);
56 assertNotNull(result.getExceptionPayload());
57 final int status = result.getOutboundProperty("http.status", 0);
58 assertEquals(404, status);
59
60
61 sendWithResponse("http://localhost:60211/mycomponent1", "test", "mycomponent1", 5);
62 sendWithResponse("http://localhost:60211/mycomponent2", "test", "mycomponent2", 5);
63 }
64
65 protected void sendWithResponse(String endpoint, String message, String response, int noOfMessages)
66 throws MuleException
67 {
68 MuleClient client = new MuleClient(muleContext);
69
70 List results = new ArrayList();
71 for (int i = 0; i < noOfMessages; i++)
72 {
73 results.add(client.send(endpoint, message, null).getPayload(DataType.BYTE_ARRAY_DATA_TYPE));
74 }
75 assertEquals(noOfMessages, results.size());
76 for (int i = 0; i < noOfMessages; i++)
77 {
78 assertEquals(response, new String((byte[])results.get(i)));
79 }
80 }
81 }