View Javadoc

1   /*
2    * $Id: HttpStemTestCase.java 20297 2010-11-22 18:49:18Z aperepel $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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  }