View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.cxf;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  import org.mule.tck.junit4.rule.DynamicPort;
14  import org.mule.transport.http.HttpConstants;
15  import org.mule.util.StringUtils;
16  
17  import java.util.List;
18  
19  import org.dom4j.Document;
20  import org.dom4j.DocumentHelper;
21  import org.dom4j.Element;
22  import org.junit.Rule;
23  import org.junit.Test;
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertNotNull;
27  
28  public class CxfBadSoapRequestTestCase extends FunctionalTestCase
29  {
30  
31      @Rule
32      public DynamicPort dynamicPort = new DynamicPort("port1");
33  
34      @Override
35      protected String getConfigResources()
36      {
37          return "soap-request-conf.xml";
38      }
39  
40      @Test
41      public void testSoapDocumentError() throws Exception
42      {
43          MuleClient client = new MuleClient(muleContext);
44  
45          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\">"
46                               + "<soap:Body>"
47                               + "<ssss xmlns=\"http://www.muleumo.org\">"
48                               + "<request xmlns=\"http://www.muleumo.org\">Bad Request</request>"
49                               + "</ssss>"
50                               + "</soap:Body>" + "</soap:Envelope>";
51  
52          MuleMessage reply = client.send("http://localhost:" + dynamicPort.getNumber() + "/services/TestComponent", new DefaultMuleMessage(
53              soapRequest, muleContext));
54  
55          assertNotNull(reply);
56          assertNotNull(reply.getPayload());
57  
58          String ct = reply.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE, StringUtils.EMPTY);
59          assertEquals("text/xml; charset=UTF-8", ct);        
60          
61          Document document = DocumentHelper.parseText(reply.getPayloadAsString());
62          List fault = document.selectNodes("//soap:Envelope/soap:Body/soap:Fault/faultcode");
63  
64          assertEquals(1, fault.size());
65          Element faultCodeElement = (Element) fault.get(0);
66  
67          assertEquals("soap:Client", faultCodeElement.getStringValue());
68  
69          fault = document.selectNodes("//soap:Envelope/soap:Body/soap:Fault/faultstring");
70          assertEquals(1, fault.size());
71          Element faultStringElement = (Element) fault.get(0);
72          assertEquals("Message part {http://www.muleumo.org}ssss was not recognized.  (Does it exist in service WSDL?)",
73              faultStringElement.getStringValue());
74      }
75  
76  }