View Javadoc

1   /*
2    * $Id: CxfJaxWsTestCase.java 19999 2010-10-24 14:41:51Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.cxf.jaxws;
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.NullPayload;
17  
18  import org.apache.commons.httpclient.HttpClient;
19  import org.apache.commons.httpclient.HttpMethod;
20  import org.apache.commons.httpclient.methods.GetMethod;
21  
22  public class CxfJaxWsTestCase extends FunctionalTestCase
23  {
24      public void testEchoService() throws Exception
25      {
26          String url = "cxf:http://localhost:63081/services/Echo?method=echo";
27  
28          MuleClient client = new MuleClient(muleContext);
29          MuleMessage result = client.send(url, "Hello!", null);
30          assertEquals("Hello!", result.getPayload());
31      }
32  
33      public void testOneWay() throws Exception
34      {
35          String url = "cxf:http://localhost:63081/services/async?method=send";
36  
37          MuleClient client = new MuleClient(muleContext);
38          MuleMessage result = client.send(url, "Hello!", null);
39          assertEquals(NullPayload.getInstance(), result.getPayload());
40      }
41  
42      public void testHttpCall() throws Exception
43      {
44          HttpClient client =  new HttpClient();
45          // The format in which CXF processes the request in Http GET is:
46          // http://host/service/OPERATION/PARAM_NAME/PARAM_VALUE
47          // In this case: http://localhost:63081/Echo/echo/text/hello
48          // (service: Echo corresponds to the name in the mule config file: TC-HTTP-CALL.xml)
49          HttpMethod httpMethod = new GetMethod("http://localhost:63081/services/Echo/echo/text/hello");
50          // Http Status Code 200 means OK, the request has succeeded. (500 would indicate an error)
51          assertEquals(200, client.executeMethod(httpMethod));
52          // By default the class package - in its other way round - is used for the namespace:
53          // Here, EchoServiceImpl classpath is: com\mulesoft\test\connectors\module\cxf
54          // Therefore namespace should be: http://cxf.transport.connectors.test.mulesoft.com
55          assertEquals(
56                  "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
57                      "<soap:Body>" +
58                          "<ns2:echoResponse xmlns:ns2=\"http://testmodels.cxf.module.mule.org/\">" +
59                              "<text>hello</text>" +
60                          "</ns2:echoResponse>" +
61                      "</soap:Body>" +
62                  "</soap:Envelope>", httpMethod.getResponseBodyAsString());
63      }
64  
65      public void testWebServiceContext() throws Exception
66      {
67          String url = "cxf:http://localhost:63081/services/Echo?method=ensureWebSerivceContextIsSet";
68  
69          MuleClient client = new MuleClient(muleContext);
70          MuleMessage result = client.send(url, TEST_MESSAGE, null);
71          assertEquals(TEST_MESSAGE, result.getPayload());
72      }
73  
74      @Override
75      protected String getConfigResources()
76      {
77          return "jaxws-conf.xml";
78      }
79  }