1
2
3
4
5
6
7 package org.mule.module.cxf.jaxws;
8
9 import org.mule.api.MuleMessage;
10 import org.mule.module.client.MuleClient;
11 import org.mule.tck.junit4.FunctionalTestCase;
12 import org.mule.tck.junit4.rule.DynamicPort;
13 import org.mule.transport.NullPayload;
14
15 import org.apache.commons.httpclient.HttpClient;
16 import org.apache.commons.httpclient.HttpMethod;
17 import org.apache.commons.httpclient.methods.GetMethod;
18 import org.junit.Rule;
19 import org.junit.Test;
20
21 import static org.junit.Assert.assertEquals;
22
23 public class CxfJaxWsTestCase extends FunctionalTestCase
24 {
25
26 @Rule
27 public DynamicPort dynamicPort = new DynamicPort("port1");
28
29 @Override
30 protected String getConfigResources()
31 {
32 return "jaxws-conf.xml";
33 }
34
35 @Test
36 public void testEchoService() throws Exception
37 {
38 String url = "cxf:http://localhost:" + dynamicPort.getNumber() + "/services/Echo?method=echo";
39
40 MuleClient client = new MuleClient(muleContext);
41 MuleMessage result = client.send(url, "Hello!", null);
42 assertEquals("Hello!", result.getPayload());
43 }
44
45 @Test
46 public void testOneWay() throws Exception
47 {
48 String url = "cxf:http://localhost:" + dynamicPort.getNumber() + "/services/async?method=send";
49
50 MuleClient client = new MuleClient(muleContext);
51 MuleMessage result = client.send(url, "Hello!", null);
52 assertEquals(NullPayload.getInstance(), result.getPayload());
53 }
54
55 @Test
56 public void testHttpCall() throws Exception
57 {
58 HttpClient client = new HttpClient();
59
60
61
62
63 HttpMethod httpMethod = new GetMethod("http://localhost:" + dynamicPort.getNumber() + "/services/Echo/echo/text/hello");
64
65 assertEquals(200, client.executeMethod(httpMethod));
66
67
68
69 assertEquals(
70 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
71 "<soap:Body>" +
72 "<ns2:echoResponse xmlns:ns2=\"http://testmodels.cxf.module.mule.org/\">" +
73 "<text>hello</text>" +
74 "</ns2:echoResponse>" +
75 "</soap:Body>" +
76 "</soap:Envelope>", httpMethod.getResponseBodyAsString());
77 }
78
79 @Test
80 public void testWebServiceContext() throws Exception
81 {
82 String url = "cxf:http://localhost:" + dynamicPort.getNumber() + "/services/Echo?method=ensureWebSerivceContextIsSet";
83
84 MuleClient client = new MuleClient(muleContext);
85 MuleMessage result = client.send(url, TEST_MESSAGE, null);
86 assertEquals(TEST_MESSAGE, result.getPayload());
87 }
88 }