View Javadoc

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