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