1   /*
2    * $Id: CxfBadSoapRequestTestCase.java 11867 2008-05-29 00:18:24Z dandiep $
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.transport.cxf;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.FunctionalTestCase;
17  import org.mule.transport.http.HttpConstants;
18  
19  import java.util.List;
20  
21  import org.dom4j.Document;
22  import org.dom4j.DocumentHelper;
23  import org.dom4j.Element;
24  
25  public class CxfBadSoapRequestTestCase extends FunctionalTestCase
26  {
27  
28      protected String getConfigResources()
29      {
30          return "soap-request-conf.xml";
31      }
32  
33      public void testSoapDocumentError() throws Exception
34      {
35          MuleClient client = new MuleClient();
36  
37          String soapRequest = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
38                               + "<soap:Body>"
39                               + "<ssss xmlns=\"http://www.muleumo.org\">"
40                               + "<request xmlns=\"http://www.muleumo.org\">Bad Request</request>"
41                               + "</ssss>"
42                               + "</soap:Body>" + "</soap:Envelope>";
43  
44          MuleMessage reply = client.send("http://localhost:63381/services/TestComponent", new DefaultMuleMessage(
45              soapRequest));
46  
47          assertNotNull(reply);
48          assertNotNull(reply.getPayload());
49  
50          String ct = reply.getStringProperty(HttpConstants.HEADER_CONTENT_TYPE, "");
51          assertEquals("text/xml", ct);
52          
53          Document document = DocumentHelper.parseText(reply.getPayloadAsString());
54          List fault = document.selectNodes("//soap:Envelope/soap:Body/soap:Fault/faultcode");
55  
56          assertEquals(1, fault.size());
57          Element faultCodeElement = (Element) fault.get(0);
58  
59          assertEquals("soap:Client", faultCodeElement.getStringValue());
60  
61          fault = document.selectNodes("//soap:Envelope/soap:Body/soap:Fault/faultstring");
62          assertEquals(1, fault.size());
63          Element faultStringElement = (Element) fault.get(0);
64          assertEquals("Message part {http://www.muleumo.org}ssss was not recognized.  (Does it exist in service WSDL?)",
65              faultStringElement.getStringValue());
66      }
67  
68  }