View Javadoc

1   /*
2    * $Id: AxisSoapHeadersTestCase.java 22450 2011-07-19 08:20:41Z 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.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.junit4.FunctionalTestCase;
17  import org.mule.tck.junit4.rule.DynamicPort;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.junit.Rule;
23  import org.junit.Test;
24  
25  import static org.junit.Assert.assertEquals;
26  
27  public class AxisSoapHeadersTestCase extends FunctionalTestCase
28  {
29  
30      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>";
31  
32      @Rule
33      public DynamicPort dynamicPort1 = new DynamicPort("port1");
34  
35      @Rule
36      public DynamicPort dynamicPort2 = new DynamicPort("port2");
37  
38  
39      @Override
40      protected String getConfigResources()
41      {
42          return "axis-soapheader-test.xml";
43      }
44  
45      @Test
46      public void testSoapRequest() throws Exception
47      {
48  
49          MuleClient client = new MuleClient(muleContext);
50          Map<String, Object> properties = new HashMap<String, Object>();
51          properties.put("http.method", "POST");
52  
53          DefaultMuleMessage soapRequest = null;
54          soapRequest = new DefaultMuleMessage(
55              "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
56              + "<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\">"
57              + "<soapenv:Header>"
58              + "<Action>storeModuleInformation</Action>"
59              + // this should be ignored
60                "<mule:header>"
61              + "<mule:MULE_REPLYTO>http://localhost:62182/reply</mule:MULE_REPLYTO>"
62              + "</mule:header>"
63              + "</soapenv:Header>"
64              + "<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>"
65              + "</soapenv:Envelope>", muleContext);
66  
67          MuleMessage reply = client.send("http://localhost:" + dynamicPort1.getNumber() + "/services/component", soapRequest, properties);
68  
69          // Put this in so that no spurious exceptions are thrown
70          // TODO research and see why sometimes we get 404 or Connection refused
71          // errors without this line. Note that the test completes even when the
72          // exceptions are thrown.
73          Thread.sleep(2000);
74  
75          assertEquals(EXPECTED_RESPONSE, reply.getPayloadAsString());
76      }
77  
78  }