View Javadoc

1   /*
2    * $Id: FilterTest.java 22401 2011-07-13 09:10:18Z dirk.olmes $
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.junit4.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  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  
25  public class FilterTest extends FunctionalTestCase
26  {
27  
28      @Override
29      protected String getConfigResources()
30      {
31          return "filter-conf.xml";
32      }
33  
34      @Test
35      public void testAcceptFilter() throws Exception
36      {
37          LocalMuleClient client = muleContext.getClient();
38  
39          MuleMessage result;
40  //        = client.send("http://localhost:9002/bar/foo", "test", null);
41  //        assertEquals("test test", result.getPayloadAsString());
42  
43          result = client.send("http://localhost:9002/baz", "test", null);
44          assertEquals("test received", result.getPayloadAsString());
45      }
46  
47      @Test
48      public void testUnAcceptFilter() throws Exception
49      {
50          LocalMuleClient client = muleContext.getClient();
51  
52          Map<String, Object> props = new HashMap<String, Object>();
53          props.put(HttpConnector.HTTP_METHOD_PROPERTY, "HEAD");
54  
55          MuleMessage result = client.send("http://localhost:9002/baz", "test", props);
56          //assertEquals(new Integer(0), result.getInboundProperty(HttpConstants.HEADER_CONTENT_LENGTH, new Integer(-1)));
57          assertEquals(new Integer(HttpConstants.SC_NOT_ACCEPTABLE), result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, new Integer(-1)));
58  
59          result = client.send("http://localhost:9002/quo", "test", null);
60          //assertEquals(new Integer(0), result.getInboundProperty(HttpConstants.HEADER_CONTENT_LENGTH, new Integer(-1)));
61          assertEquals(new Integer(HttpConstants.SC_NOT_ACCEPTABLE), result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, new Integer(-1)));
62      }
63  
64  }