View Javadoc

1   /*
2    * $Id: RESTTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.servlet;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.FunctionalTestCase;
17  
18  public class RESTTestCase extends FunctionalTestCase
19  {
20      public RESTTestCase()
21      {
22          super();
23          
24          // Do not fail test case upon timeout because this probably just means
25          // that the 3rd-party web service is off-line.
26          setFailOnTimeout(false);
27      }
28  
29      protected String getConfigResources()
30      {
31          return "rest-functional-test.xml";
32      }
33      
34      public void testRest1ParamPost() throws Exception
35      {
36          MuleClient client = new MuleClient(muleContext);
37          MuleMessage reply  = client.send("vm://in1", new DefaultMuleMessage("IBM", muleContext));
38          
39          assertNotNull(reply);
40          assertNotNull(reply.getPayloadAsString());
41          assertTrue(reply.getPayloadAsString().indexOf("Symbol>IBM<") > -1);
42      }
43      
44      public void testRest2ParamsPost() throws Exception
45      {
46          MuleClient client = new MuleClient(muleContext);
47          MuleMessage reply  = client.send("vm://in2", new DefaultMuleMessage(new Object[]{"MTL","MTL"}, muleContext));
48          
49          assertNotNull(reply.getPayloadAsString());
50          assertTrue(reply.getPayloadAsString().indexOf(">1</double>") > -1);
51      }
52      
53      public void testRest1ParamGet() throws Exception
54      {
55          MuleClient client = new MuleClient(muleContext);
56          MuleMessage reply  = client.send("vm://in3", new DefaultMuleMessage(new Object[]{"IBM"}, muleContext));
57          
58          assertNotNull(reply);
59          String replyStr = reply.getPayloadAsString();
60          assertNotNull(replyStr);
61          assertTrue("'Symbol&gt;IBM&lt;' not found in reply: " + replyStr, replyStr.indexOf("Symbol&gt;IBM&lt;") > -1);
62      }
63      
64      public void testRest2ParamsGet() throws Exception
65      {
66          MuleClient client = new MuleClient(muleContext);
67          MuleMessage reply  = client.send("vm://in4", new DefaultMuleMessage(new Object[]{"MTL","MTL"}, muleContext));
68          
69          String replyStr = reply.getPayloadAsString();
70          assertNotNull(replyStr);
71          assertTrue("'>1</double>' not found in reply: " + replyStr, replyStr.indexOf(">1</double>") > -1);
72      }
73  
74  }
75  
76