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