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.http.filters;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.endpoint.InboundEndpoint;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  import org.mule.tck.junit4.rule.DynamicPort;
14  import org.mule.transport.http.HttpConnector;
15  import org.mule.transport.http.HttpConstants;
16  
17  import java.util.HashMap;
18  import java.util.Map;
19  
20  import org.junit.Rule;
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNotNull;
25  
26  public class HttpRequestWildcardFilterTestCase extends FunctionalTestCase
27  {
28      
29      private static final String TEST_HTTP_MESSAGE = "Hello=World";
30      private static final String TEST_BAD_MESSAGE = "xyz";
31  
32      @Rule
33      public DynamicPort dynamicPort1 = new DynamicPort("port1");
34  
35      @Rule
36      public DynamicPort dynamicPort2 = new DynamicPort("port2");
37  
38      @Override
39      protected String getConfigResources()
40      {
41          return "http-wildcard-filter-test.xml";
42      }
43  
44      @Test
45      public void testReference() throws Exception
46      {
47          MuleClient client = new MuleClient(muleContext);
48          MuleMessage result = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("inReference")).getAddress(), TEST_HTTP_MESSAGE, null);
49  
50          assertEquals(TEST_HTTP_MESSAGE, result.getPayloadAsString());
51      }
52  
53      @Test
54      public void testHttpPost() throws Exception
55      {
56          MuleClient client = new MuleClient(muleContext);
57          MuleMessage result = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("inHttpIn")).getAddress(), TEST_HTTP_MESSAGE, null);
58  
59          assertEquals(TEST_HTTP_MESSAGE, result.getPayloadAsString());
60      }
61  
62      @Test
63      public void testHttpGetNotFiltered() throws Exception
64      {
65          Map<String, Object> props = new HashMap<String, Object>();
66          props.put(HttpConstants.METHOD_GET, "true");
67  
68          MuleClient client = new MuleClient(muleContext);
69          MuleMessage result = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("inHttpIn")).getAddress() + "/" + "mulerulez", TEST_HTTP_MESSAGE, props);
70  
71          assertEquals(TEST_HTTP_MESSAGE, result.getPayloadAsString());
72      }
73  
74      @Test
75      public void testHttpGetFiltered() throws Exception
76      {
77          Map<String, Object> props = new HashMap<String, Object>();
78          props.put(HttpConnector.HTTP_METHOD_PROPERTY, HttpConstants.METHOD_GET);
79          //props.put(HttpConstants.METHOD_GET, "true");
80  
81          MuleClient client = new MuleClient(muleContext);
82          MuleMessage result = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("inHttpIn")).getAddress() + "/" + TEST_BAD_MESSAGE, "mule", props);
83  
84          final int status = result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0);
85          assertEquals(HttpConstants.SC_NOT_ACCEPTABLE, status);
86          assertNotNull(result.getExceptionPayload());
87      }
88  
89  }