View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.servlet.jetty.functional;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  import org.mule.tck.junit4.rule.DynamicPort;
13  import org.mule.transport.http.HttpConnector;
14  
15  import org.junit.Rule;
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  
20  
21  public class JettyHttpStemTestCase extends FunctionalTestCase
22  {
23  
24      @Rule
25      public DynamicPort dynamicPort1 = new DynamicPort("port1");
26  
27      @Rule
28      public DynamicPort dynamicPort2 = new DynamicPort("port2");
29  
30      @Override
31      protected String getConfigResources()
32      {
33          return "jetty-http-stem-test.xml";
34      }
35  
36      @Test
37      public void testStemMatchingHttp() throws Exception
38      {
39          MuleClient client = new MuleClient(muleContext);
40          doTest(client, "http://localhost:"+ dynamicPort1.getNumber() +"/foo", "Hello World");
41          doTest(client, "http://localhost:"+ dynamicPort1.getNumber() +"/foo/bar", "Hello World");
42          doTest(client, "http://localhost:"+ dynamicPort1.getNumber() +"/foo/bestmatch", "Hello World Best Match");
43      }
44  
45      protected void doTest(MuleClient client, String url, String value) throws Exception
46      {
47          MuleMessage result = client.send(url, "Hello", null);
48          assertEquals(value, result.getPayloadAsString());
49          final int status = result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0);
50          assertEquals(200, status);
51      }
52  }