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