1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.jersey;
12
13 import org.mule.api.MuleMessage;
14 import org.mule.module.client.MuleClient;
15 import org.mule.tck.FunctionalTestCase;
16 import org.mule.transport.http.HttpConnector;
17 import org.mule.transport.http.HttpConstants;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 public class BasicJerseyTestCase extends FunctionalTestCase {
23
24 public void testBasic() throws Exception
25 {
26 MuleClient client = new MuleClient(muleContext);
27
28 MuleMessage result = client.send("http://localhost:63081/helloworld", "", null);
29 assertEquals((Integer)200, result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0));
30 assertEquals("Hello World", result.getPayloadAsString());
31
32
33 result = client.send("http://localhost:63081/hello", "", null);
34 assertEquals((Integer)404, result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0));
35
36 Map<String, String> props = new HashMap<String, String>();
37 props.put(HttpConnector.HTTP_METHOD_PROPERTY, HttpConstants.METHOD_GET);
38 result = client.send("http://localhost:63081/helloworld", "", props);
39 assertEquals((Integer)405, result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0));
40
41 props.put(HttpConnector.HTTP_METHOD_PROPERTY, HttpConstants.METHOD_DELETE);
42 result = client.send("http://localhost:63081/helloworld", "", props);
43 assertEquals("Hello World Delete", result.getPayloadAsString());
44 assertEquals((Integer)200, result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0));
45 }
46
47 public void testParams() throws Exception
48 {
49 MuleClient client = new MuleClient(muleContext);
50
51 Map<String, String> props = new HashMap<String, String>();
52 props.put(HttpConnector.HTTP_METHOD_PROPERTY, HttpConstants.METHOD_GET);
53 MuleMessage result = client.send("http://localhost:63081/helloworld/sayHelloWithUri/Dan", "", props);
54 assertEquals((Integer)200, result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0));
55 assertEquals("Hello Dan", result.getPayloadAsString());
56
57
58 result = client.send("http://localhost:63081/helloworld/sayHelloWithJson/Dan", "", props);
59 assertEquals((Integer)200, result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0));
60 assertEquals("{\"message\":\"Hello Dan\"}", result.getPayloadAsString());
61
62 result = client.send("http://localhost:63081/helloworld/sayHelloWithQuery?name=Dan", "", props);
63 assertEquals((Integer)200, result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0));
64 assertEquals("Hello Dan", result.getPayloadAsString());
65
66 props.put("X-Name", "Dan");
67 result = client.send("http://localhost:63081/helloworld/sayHelloWithHeader", "", props);
68 assertEquals((Integer)201, result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0));
69 assertEquals("Hello Dan", result.getPayloadAsString());
70 assertEquals("Dan", result.getInboundProperty("X-ResponseName"));
71 }
72
73 @Override
74 protected String getConfigResources()
75 {
76 return "basic-conf.xml";
77 }
78
79 }