View Javadoc

1   /*
2    * $Id: RestServiceWrapperFunctionalTestCase.java 10538 2008-01-25 14:43:19Z marie.rizzo $
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.components;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.DynamicPortTestCase;
16  import org.mule.tck.FunctionalTestCase;
17  import org.mule.transport.NullPayload;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  public class RestServiceWrapperFunctionalTestCase extends DynamicPortTestCase
23  {
24      protected static String TEST_REQUEST = "Test Http Request";
25  
26      protected String getConfigResources()
27      {
28          return "http-rest-service-wrapper-functional-test.xml";
29      }
30  
31      public void testErrorExpressionOnRegexFilterFail() throws Exception
32      {
33          MuleClient client = new MuleClient(muleContext);
34          MuleMessage result = client.send("restServiceEndpoint", TEST_REQUEST, null);
35          assertTrue(result.getPayload() instanceof NullPayload);
36      }
37  
38      public void testErrorExpressionOnRegexFilterPass() throws Exception
39      {
40          MuleClient client = new MuleClient(muleContext);
41          MuleMessage result = client.send("restServiceEndpoint2", TEST_REQUEST, null);
42          assertEquals("echo=" + TEST_REQUEST,result.getPayloadAsString());
43      }
44  
45      public void testRequiredParameters() throws Exception
46      {
47          MuleClient client = new MuleClient(muleContext);
48          Map<String, Object> props = new HashMap<String, Object>();
49          props.put("baz-header", "baz");
50          props.put("bar-optional-header", "bar");
51          MuleMessage result = client.send("restServiceEndpoint3", null, props);
52          assertEquals("foo=boo&faz=baz&far=bar",result.getPayloadAsString());
53      }
54  
55      public void testOptionalParametersMissing() throws Exception
56      {
57          MuleClient client = new MuleClient(muleContext);
58          Map<String, Object> props = new HashMap<String, Object>();
59          props.put("baz-header", "baz");
60          MuleMessage result = client.send("restServiceEndpoint3", null, props);
61          assertEquals("foo=boo&faz=baz",result.getPayloadAsString());
62      }
63  
64      public void testRequiredParametersMissing() throws Exception
65      {
66          MuleClient client = new MuleClient(muleContext);
67          Map props = new HashMap();
68  
69          MuleMessage result = client.send("restServiceEndpoint3", null, props);
70          assertEquals(NullPayload.getInstance(),result.getPayload());
71          assertNotNull(result.getExceptionPayload());
72      }
73  
74      @Override
75      protected int getNumPortsToFind()
76      {
77          return 1;
78      }
79  }