View Javadoc

1   /*
2    * $Id: CxfEchoTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.example.echo;
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  import org.mule.util.IOUtils;
18  
19  import java.io.IOException;
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import org.custommonkey.xmlunit.XMLAssert;
24  
25  /**
26   * Tests the echo example using CXF.
27   */
28  public class CxfEchoTestCase extends FunctionalTestCase
29  {
30      private String expectedGetResponse;
31  
32      @Override
33      protected String getConfigResources()
34      {
35          return "echo-cxf-config.xml";
36      }
37  
38      @Override
39      protected void doSetUp() throws Exception
40      {
41          try
42          {
43              expectedGetResponse = IOUtils.getResourceAsString("echo-cxf-response.xml", getClass());
44          }
45          catch (IOException ioex)
46          {
47              fail(ioex.getMessage());
48          }
49      }
50  
51      public void testGetEcho() throws Exception
52      {
53          // CXF has built in support for understanding GET requests. They are of the form:
54          // http://host/service/OPERATION/PARAM_NAME/PARAM_VALUE
55          
56          MuleClient client = new MuleClient(muleContext);
57          Map<String, String> props = new HashMap<String, String>();
58          props.put("http.method", "GET");
59          MuleMessage result = client.send("http://localhost:65082/services/EchoUMO/echo/text/hello", "", props);
60          assertNotNull(result);
61          assertFalse(result.getPayload() instanceof NullPayload);
62          XMLAssert.assertXMLEqual(expectedGetResponse, result.getPayloadAsString());
63      }
64  
65      public void testSoapPostEcho() throws Exception
66      {
67          MuleClient client = new MuleClient(muleContext);
68          MuleMessage result = client.send("cxf:http://localhost:65082/services/EchoUMO?method=echo", 
69              "hello", null);
70          assertNotNull(result);
71          assertNull(result.getExceptionPayload());
72          assertFalse(result.getPayload() instanceof NullPayload);
73          assertEquals("hello", result.getPayload());
74      }
75  }