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
19 import java.util.ArrayList;
20 import java.util.List;
21
22 public class JettyTwoEndpointsSinglePortTestCase extends FunctionalTestCase
23 {
24
25 protected String getConfigResources()
26 {
27 return "jetty-two-endpoints-single-port.xml";
28 }
29
30 public void testSendToEach() throws Exception
31 {
32
33 sendWithResponse("http://localhost:60211/mycomponent1", "test", "mycomponent1", 10);
34 sendWithResponse("http://localhost:60211/mycomponent2", "test", "mycomponent2", 10);
35 }
36
37 public void testSendToEachWithBadEndpoint() throws Exception
38 {
39
40 MuleClient client = new MuleClient(muleContext);
41
42 sendWithResponse("http://localhost:60211/mycomponent1", "test", "mycomponent1", 5);
43 sendWithResponse("http://localhost:60211/mycomponent2", "test", "mycomponent2", 5);
44
45 MuleMessage result = client.send("http://localhost:60211/mycomponent-notfound", "test", null);
46 assertNotNull(result);
47 assertNotNull(result.getExceptionPayload());
48 final int status = result.getInboundProperty("http.status", 0);
49 assertEquals(404, status);
50
51
52 sendWithResponse("http://localhost:60211/mycomponent1", "test", "mycomponent1", 5);
53 sendWithResponse("http://localhost:60211/mycomponent2", "test", "mycomponent2", 5);
54 }
55
56 protected void sendWithResponse(String endpoint, String message, String response, int noOfMessages)
57 throws MuleException
58 {
59 MuleClient client = new MuleClient(muleContext);
60
61 List results = new ArrayList();
62 for (int i = 0; i < noOfMessages; i++)
63 {
64 MuleMessage result = client.send(endpoint, message, null);
65 results.add(result.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 }