1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.http.functional;
12
13 import org.mule.api.MuleEventContext;
14 import org.mule.api.MuleMessage;
15 import org.mule.module.client.MuleClient;
16 import org.mule.tck.DynamicPortTestCase;
17 import org.mule.tck.FunctionalTestCase;
18 import org.mule.tck.functional.EventCallback;
19 import org.mule.tck.functional.FunctionalTestComponent;
20 import org.mule.transport.http.HttpConnector;
21
22 public class HttpStemTestCase extends DynamicPortTestCase
23 {
24 @Override
25 protected String getConfigResources()
26 {
27 return "http-stem-test.xml";
28 }
29
30 public void testStemMatching() throws Exception
31 {
32 MuleClient client = new MuleClient(muleContext);
33 int port = getPorts().get(0);
34 doTest(client, "http://localhost:" + port + "/foo", "/foo", "/foo");
35 doTest(client, "http://localhost:" + port + "/foo/baz", "/foo", "/foo/baz");
36 doTest(client, "http://localhost:" + port + "/bar", "/bar", "/bar");
37 doTest(client, "http://localhost:" + port + "/bar/baz", "/bar", "/bar/baz");
38 }
39
40 protected void doTest(MuleClient client, final String url, final String contextPath, final String requestPath) throws Exception
41 {
42 FunctionalTestComponent testComponent = (FunctionalTestComponent) getComponent(contextPath);
43 assertNotNull(testComponent);
44
45 EventCallback callback = new EventCallback()
46 {
47 public void eventReceived(final MuleEventContext context, final Object component) throws Exception
48 {
49 MuleMessage msg = context.getMessage();
50 assertEquals(requestPath, msg.getInboundProperty(HttpConnector.HTTP_REQUEST_PROPERTY));
51 assertEquals(requestPath, msg.getInboundProperty(HttpConnector.HTTP_REQUEST_PATH_PROPERTY));
52 assertEquals(contextPath, msg.getInboundProperty(HttpConnector.HTTP_CONTEXT_PATH_PROPERTY));
53 }
54 };
55
56 testComponent.setEventCallback(callback);
57
58 MuleMessage result = client.send(url, "Hello World", null);
59 assertEquals("Hello World Received", result.getPayloadAsString());
60 final int status = result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0);
61 assertEquals(200, status);
62 }
63
64 @Override
65 protected int getNumPortsToFind()
66 {
67 return 1;
68 }
69 }