1   /*
2    * $Id: AxisEchoTestCase.java 11728 2008-05-13 07:31:11Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.samples.echo;
12  
13  import org.mule.extras.client.MuleClient;
14  import org.mule.providers.NullPayload;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.umo.UMOMessage;
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 Axis
27   */
28  public class AxisEchoTestCase extends FunctionalTestCase
29  {
30  
31      private String expectedGetResponse;
32      private String expectedPostResponse;
33  
34      public AxisEchoTestCase()
35      {
36          this.setDisposeManagerPerSuite(true);
37      }
38  
39      protected void doPreFunctionalSetUp() throws Exception
40      {
41          super.doPreFunctionalSetUp();
42  
43          try
44          {
45              expectedGetResponse = IOUtils.getResourceAsString(getExpectedGetResponseResource(),
46                  this.getClass());
47              expectedPostResponse = IOUtils.getResourceAsString(getExpectedPostResponseResource(),
48                  this.getClass());
49          }
50          catch (IOException ioex)
51          {
52              fail(ioex.getMessage());
53          }
54      }
55  
56      protected String getExpectedGetResponseResource()
57      {
58          return "echo-axis-get-response.xml";
59      }
60  
61      protected String getExpectedPostResponseResource()
62      {
63          return "echo-axis-post-response.xml";
64      }
65  
66      protected String getConfigResources()
67      {
68          return "echo-axis-config.xml";
69      }
70  
71      protected String getProtocol()
72      {
73          return "axis";
74      }
75  
76      public void testPostEcho() throws Exception
77      {
78          MuleClient client = new MuleClient();
79          UMOMessage result = client.send("http://localhost:65081/services/EchoUMO?method=echo", "hello", null);
80          assertNotNull(result);
81          assertNull(result.getExceptionPayload());
82          assertFalse(result.getPayload() instanceof NullPayload);
83          XMLAssert.assertXMLEqual(expectedPostResponse, result.getPayloadAsString());
84      }
85  
86      public void testGetEcho() throws Exception
87      {
88          MuleClient client = new MuleClient();
89          Map props = new HashMap();
90          props.put("http.method", "GET");
91          UMOMessage result = client.send("http://localhost:65081/services/EchoUMO?method=echo", "hello", props);
92          assertNotNull(result);
93          // TODO: MULE-1113
94          if (this instanceof XFireEchoTestCase)
95          {
96              assertNull(result.getExceptionPayload());
97          }
98          assertFalse(result.getPayload() instanceof NullPayload);
99          XMLAssert.assertXMLEqual(expectedGetResponse, result.getPayloadAsString());
100     }
101 
102     public void testSoapPostEcho() throws Exception
103     {
104         MuleClient client = new MuleClient();
105         UMOMessage result = client.send(
106             getProtocol() + ":http://localhost:65082/services/EchoUMO?method=echo", "hello", null);
107         assertNotNull(result);
108         assertNull(result.getExceptionPayload());
109         assertFalse(result.getPayload() instanceof NullPayload);
110         assertEquals("hello", result.getPayload());
111     }
112 
113 }