View Javadoc

1   /*
2    * $Id: RestServiceWrapperFunctionalTestCase.java 20353 2010-11-26 10:18:16Z 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  
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.transport.NullPayload;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  public class RestServiceWrapperFunctionalTestCase extends DynamicPortTestCase
22  {
23      protected static String TEST_REQUEST = "Test Http Request";
24  
25      @Override
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<String, Object> props = new HashMap<String, Object>();
68  
69          MuleMessage result = client.send("restServiceEndpoint3", null, props);
70          assertEquals(NullPayload.getInstance(),result.getPayload());
71          assertNotNull(result.getExceptionPayload());
72      }
73  
74      public void testRestServiceComponentInFlow() throws Exception
75      {
76          MuleClient client = new MuleClient(muleContext);
77          
78          MuleMessage result = client.send("vm://toFlow", TEST_REQUEST, null);
79          assertNotNull(result);
80          assertEquals("echo=Test Http Request", result.getPayloadAsString());
81      }
82      
83      @Override
84      protected int getNumPortsToFind()
85      {
86          return 1;
87      }
88  }