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.transport.servlet;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  import org.mule.tck.util.WebServiceOnlineCheck;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertNotNull;
18  import static org.junit.Assert.assertTrue;
19  
20  public class RESTTestCase extends FunctionalTestCase
21  {
22      @Override
23      protected String getConfigResources()
24      {
25          return "rest-functional-test.xml";
26      }
27  
28      @Override
29      protected boolean isFailOnTimeout()
30      {
31          // Do not fail test case upon timeout because this probably just means
32          // that the 3rd-party web service is off-line.
33          return false;
34      }
35  
36      /**
37       * If a simple call to the web service indicates that it is not responding properly,
38       * we disable the test case so as to not report a test failure which has nothing to do
39       * with Mule.
40       *
41       * see EE-947
42       */
43      @Override
44      protected boolean isDisabledInThisEnvironment()
45      {
46          return (WebServiceOnlineCheck.isWebServiceOnline() == false);
47      }
48  
49      @Test
50      public void testRest1ParamPost() throws Exception
51      {
52          MuleClient client = new MuleClient(muleContext);
53          MuleMessage reply  = client.send("vm://in1", new DefaultMuleMessage("IBM", muleContext));
54  
55          assertNotNull(reply);
56          assertNotNull(reply.getPayloadAsString());
57          assertTrue(reply.getPayloadAsString().indexOf("Symbol>IBM<") > -1);
58      }
59  
60      @Test
61      public void testRest2ParamsPost() throws Exception
62      {
63          MuleClient client = new MuleClient(muleContext);
64          MuleMessage reply  = client.send("vm://in2", new DefaultMuleMessage(new Object[]{"ARS","ARS"}, muleContext));
65  
66          assertNotNull(reply.getPayloadAsString());
67          assertTrue(reply.getPayloadAsString().indexOf(">0</double>") > -1);
68      }
69  
70      @Test
71      public void testRest1ParamGet() throws Exception
72      {
73          MuleClient client = new MuleClient(muleContext);
74          MuleMessage reply  = client.send("vm://in3", new DefaultMuleMessage(new Object[]{"IBM"}, muleContext));
75  
76          assertNotNull(reply);
77          String replyStr = reply.getPayloadAsString();
78          assertNotNull(replyStr);
79          assertTrue("'Symbol&gt;IBM&lt;' not found in reply: " + replyStr, replyStr.indexOf("Symbol&gt;IBM&lt;") > -1);
80      }
81  
82      @Test
83      public void testRest2ParamsGet() throws Exception
84      {
85          MuleClient client = new MuleClient(muleContext);
86          MuleMessage reply  = client.send("vm://in4", new DefaultMuleMessage(new Object[]{"ARS","ARS"}, muleContext));
87  
88          String replyStr = reply.getPayloadAsString();
89          assertTrue("'>0</double>' not found in reply: " + replyStr, replyStr.indexOf(">0</double>") > -1);
90      }
91  }