View Javadoc

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