View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.example.echo;
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.transport.NullPayload;
13  import org.mule.util.IOUtils;
14  
15  import java.io.IOException;
16  import java.util.HashMap;
17  import java.util.Map;
18  
19  import org.custommonkey.xmlunit.XMLAssert;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertFalse;
24  import static org.junit.Assert.assertNotNull;
25  import static org.junit.Assert.assertNull;
26  import static org.junit.Assert.fail;
27  
28  /**
29   * Tests the echo example using CXF.
30   */
31  public class CxfEchoTestCase extends FunctionalTestCase
32  {
33      private String expectedGetResponse;
34  
35      @Override
36      protected String getConfigResources()
37      {
38          return "echo-cxf-config.xml";
39      }
40  
41      @Override
42      protected void doSetUp() throws Exception
43      {
44          try
45          {
46              expectedGetResponse = IOUtils.getResourceAsString("echo-cxf-response.xml", getClass());
47          }
48          catch (IOException ioex)
49          {
50              fail(ioex.getMessage());
51          }
52      }
53  
54      @Test
55      public void testGetEcho() throws Exception
56      {
57          // CXF has built in support for understanding GET requests. They are of the form:
58          // http://host/service/OPERATION/PARAM_NAME/PARAM_VALUE
59          
60          MuleClient client = new MuleClient(muleContext);
61          Map<String, String> props = new HashMap<String, String>();
62          props.put("http.method", "GET");
63          MuleMessage result = client.send("http://localhost:65082/services/EchoUMO/echo/text/hello", "", props);
64          assertNotNull(result);
65          assertFalse(result.getPayload() instanceof NullPayload);
66          XMLAssert.assertXMLEqual(expectedGetResponse, result.getPayloadAsString());
67      }
68  
69      @Test
70      public void testSoapPostEcho() throws Exception
71      {
72          MuleClient client = new MuleClient(muleContext);
73          MuleMessage result = client.send("cxf:http://localhost:65082/services/EchoUMO?method=echo", 
74              "hello", null);
75          assertNotNull(result);
76          assertNull(result.getExceptionPayload());
77          assertFalse(result.getPayload() instanceof NullPayload);
78          assertEquals("hello", result.getPayload());
79      }
80  }