1
2
3
4
5
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
32
33 return false;
34 }
35
36
37
38
39
40
41
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>IBM<' not found in reply: " + replyStr, replyStr.indexOf("Symbol>IBM<") > -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 }