View Javadoc

1   /*
2    * $Id: FilterTest.java 19980 2010-10-21 11:27:14Z rossmason $
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  package org.mule.module.atom;
11  
12  import org.mule.api.MuleMessage;
13  import org.mule.api.client.LocalMuleClient;
14  import org.mule.tck.FunctionalTestCase;
15  import org.mule.transport.http.HttpConnector;
16  import org.mule.transport.http.HttpConstants;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  public class FilterTest extends FunctionalTestCase
22  {
23      @Override
24      protected String getConfigResources()
25      {
26          return "filter-conf.xml";
27      }
28  
29      public void testAcceptFilter() throws Exception
30      {
31          LocalMuleClient client = muleContext.getClient();
32  
33          MuleMessage result;
34  //        = client.send("http://localhost:9002/bar/foo", "test", null);
35  //        assertEquals("test test", result.getPayloadAsString());
36  
37          result = client.send("http://localhost:9002/baz", "test", null);
38          assertEquals("test received", result.getPayloadAsString());
39      }
40  
41      public void testUnAcceptFilter() throws Exception
42      {
43          LocalMuleClient client = muleContext.getClient();
44  
45          Map<String, Object> props = new HashMap<String, Object>();
46          props.put(HttpConnector.HTTP_METHOD_PROPERTY, "HEAD");
47  
48          MuleMessage result = client.send("http://localhost:9002/baz", "test", props);
49          assertEquals(new Integer(0), result.getInboundProperty(HttpConstants.HEADER_CONTENT_LENGTH, new Integer(-1)));
50          assertEquals(new Integer(HttpConstants.SC_NOT_ACCEPTABLE), result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, new Integer(-1)));
51  
52          result = client.send("http://localhost:9002/quo", "test", null);
53          assertEquals(new Integer(0), result.getInboundProperty(HttpConstants.HEADER_CONTENT_LENGTH, new Integer(-1)));
54          assertEquals(new Integer(HttpConstants.SC_NOT_ACCEPTABLE), result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, new Integer(-1)));
55      }
56  
57  }