View Javadoc

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