View Javadoc

1   /*
2    * $Id: AxisSoapHeadersTestCase.java 19841 2010-10-05 23:17:20Z dzapata $
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.transport.soap.axis.functional;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.DynamicPortTestCase;
17  import org.mule.tck.FunctionalTestCase;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  public class AxisSoapHeadersTestCase extends DynamicPortTestCase
23  {
24      private static final String EXPECTED_RESPONSE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body><echoResponse soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><echoReturn xsi:type=\"xsd:string\">Test Message</echoReturn></echoResponse></soapenv:Body></soapenv:Envelope>";
25  
26      @Override
27      protected String getConfigResources()
28      {
29          return "axis-soapheader-test.xml";
30      }
31  
32      public void testSoapRequest() throws Exception
33      {
34  
35          MuleClient client = new MuleClient(muleContext);
36          Map<String, Object> properties = new HashMap<String, Object>();
37          properties.put("http.method", "POST");
38  
39          DefaultMuleMessage soapRequest = null;
40          soapRequest = new DefaultMuleMessage(
41              "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
42              + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:mule=\"http://www.muleumo.org/providers/soap/1.0\">"
43              + "<soapenv:Header>"
44              + "<Action>storeModuleInformation</Action>"
45              + // this should be ignored
46                "<mule:header>"
47              + "<mule:MULE_REPLYTO>http://localhost:62182/reply</mule:MULE_REPLYTO>"
48              + "</mule:header>"
49              + "</soapenv:Header>"
50              + "<soapenv:Body><echo soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><value0 xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">Test Message</value0></echo></soapenv:Body>"
51              + "</soapenv:Envelope>", muleContext);
52  
53          MuleMessage reply = client.send("http://localhost:" + getPorts().get(0) + "/services/component", soapRequest, properties);
54  
55          // Put this in so that no spurious exceptions are thrown
56          // TODO research and see why sometimes we get 404 or Connection refused
57          // errors without this line. Note that the test completes even when the
58          // exceptions are thrown.
59          Thread.sleep(2000);
60  
61          assertEquals(EXPECTED_RESPONSE, reply.getPayloadAsString());
62      }
63  
64      @Override
65      protected int getNumPortsToFind()
66      {
67          // TODO Auto-generated method stub
68          return 2;
69      }
70  }