View Javadoc

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