1
2
3
4
5
6
7
8
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.junit4.FunctionalTestCase;
17 import org.mule.tck.util.WebServiceOnlineCheck;
18
19 import org.junit.Test;
20
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertTrue;
23
24 public class RESTTestCase extends FunctionalTestCase
25 {
26 @Override
27 protected String getConfigResources()
28 {
29 return "rest-functional-test.xml";
30 }
31
32 @Override
33 protected boolean isFailOnTimeout()
34 {
35
36
37 return false;
38 }
39
40
41
42
43
44
45
46
47 @Override
48 protected boolean isDisabledInThisEnvironment()
49 {
50 return (WebServiceOnlineCheck.isWebServiceOnline() == false);
51 }
52
53 @Test
54 public void testRest1ParamPost() throws Exception
55 {
56 MuleClient client = new MuleClient(muleContext);
57 MuleMessage reply = client.send("vm://in1", new DefaultMuleMessage("IBM", muleContext));
58
59 assertNotNull(reply);
60 assertNotNull(reply.getPayloadAsString());
61 assertTrue(reply.getPayloadAsString().indexOf("Symbol>IBM<") > -1);
62 }
63
64 @Test
65 public void testRest2ParamsPost() throws Exception
66 {
67 MuleClient client = new MuleClient(muleContext);
68 MuleMessage reply = client.send("vm://in2", new DefaultMuleMessage(new Object[]{"ARS","ARS"}, muleContext));
69
70 assertNotNull(reply.getPayloadAsString());
71 assertTrue(reply.getPayloadAsString().indexOf(">0</double>") > -1);
72 }
73
74 @Test
75 public void testRest1ParamGet() throws Exception
76 {
77 MuleClient client = new MuleClient(muleContext);
78 MuleMessage reply = client.send("vm://in3", new DefaultMuleMessage(new Object[]{"IBM"}, muleContext));
79
80 assertNotNull(reply);
81 String replyStr = reply.getPayloadAsString();
82 assertNotNull(replyStr);
83 assertTrue("'Symbol>IBM<' not found in reply: " + replyStr, replyStr.indexOf("Symbol>IBM<") > -1);
84 }
85
86 @Test
87 public void testRest2ParamsGet() throws Exception
88 {
89 MuleClient client = new MuleClient(muleContext);
90 MuleMessage reply = client.send("vm://in4", new DefaultMuleMessage(new Object[]{"ARS","ARS"}, muleContext));
91
92 String replyStr = reply.getPayloadAsString();
93 System.out.println(replyStr);
94 assertTrue("'>0</double>' not found in reply: " + replyStr, replyStr.indexOf(">0</double>") > -1);
95 }
96 }