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