View Javadoc

1   /*
2    * $Id: JettyHttpStemTestCase.java 22854 2011-09-04 11:18:35Z pablo.kraan $
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.servlet.jetty.functional;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.AbstractServiceAndFlowTestCase;
16  import org.mule.tck.junit4.rule.DynamicPort;
17  import org.mule.transport.http.HttpConnector;
18  
19  import java.util.Arrays;
20  import java.util.Collection;
21  
22  import org.junit.Rule;
23  import org.junit.Test;
24  import org.junit.runners.Parameterized.Parameters;
25  
26  import static org.junit.Assert.assertEquals;
27  
28  
29  public class JettyHttpStemTestCase extends AbstractServiceAndFlowTestCase
30  {
31  
32      @Rule
33      public DynamicPort dynamicPort1 = new DynamicPort("port1");
34  
35      @Rule
36      public DynamicPort dynamicPort2 = new DynamicPort("port2");
37      
38      public JettyHttpStemTestCase(ConfigVariant variant, String configResources)
39      {
40          super(variant, configResources);
41      }
42  
43      @Parameters
44      public static Collection<Object[]> parameters()
45      {
46          return Arrays.asList(new Object[][]{
47              {ConfigVariant.SERVICE, "jetty-http-stem-test-service.xml"},
48              {ConfigVariant.FLOW, "jetty-http-stem-test-flow.xml"}
49          });
50      }  
51      
52      @Test
53      public void testStemMatchingHttp() throws Exception
54      {
55          MuleClient client = new MuleClient(muleContext);
56          doTest(client, "http://localhost:"+ dynamicPort1.getNumber() +"/foo", "Hello World");
57          doTest(client, "http://localhost:"+ dynamicPort1.getNumber() +"/foo/bar", "Hello World");
58          doTest(client, "http://localhost:"+ dynamicPort1.getNumber() +"/foo/bestmatch", "Hello World Best Match");
59      }
60  
61      protected void doTest(MuleClient client, String url, String value) throws Exception
62      {
63          MuleMessage result = client.send(url, "Hello", null);
64          assertEquals(value, result.getPayloadAsString());
65          final int status = result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0);
66          assertEquals(200, status);
67      }
68  }