/*
* $Id: CxfBadSoapRequestTestCase.java 21172 2011-02-01 21:48:56Z dzapata $
* --------------------------------------------------------------------------------------
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
*
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.module.cxf;
import org.mule.DefaultMuleMessage;
import org.mule.api.MuleMessage;
import org.mule.module.client.MuleClient;
import org.mule.tck.DynamicPortTestCase;
import org.mule.transport.http.HttpConstants;
import org.mule.util.StringUtils;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
public class CxfBadSoapRequestTestCase extends DynamicPortTestCase
{
protected String getConfigResources()
{
return "soap-request-conf.xml";
}
public void testSoapDocumentError() throws Exception
{
MuleClient client = new MuleClient(muleContext);
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\">"
+ "<soap:Body>"
+ "<ssss xmlns=\"http://www.muleumo.org\">"
+ "<request xmlns=\"http://www.muleumo.org\">Bad Request</request>"
+ "</ssss>"
+ "</soap:Body>" + "</soap:Envelope>";
MuleMessage reply = client.send("http://localhost:" + getPorts().get(0) + "/services/TestComponent", new DefaultMuleMessage(
soapRequest, muleContext));
assertNotNull(reply);
assertNotNull(reply.getPayload());
String ct = reply.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE, StringUtils.EMPTY);
assertEquals("text/xml; charset=UTF-8", ct);
Document document = DocumentHelper.parseText(reply.getPayloadAsString());
List fault = document.selectNodes("//soap:Envelope/soap:Body/soap:Fault/faultcode");
assertEquals(1, fault.size());
Element faultCodeElement = (Element) fault.get(0);
assertEquals("soap:Client", faultCodeElement.getStringValue());
fault = document.selectNodes("//soap:Envelope/soap:Body/soap:Fault/faultstring");
assertEquals(1, fault.size());
Element faultStringElement = (Element) fault.get(0);
assertEquals("Message part {http://www.muleumo.org}ssss was not recognized. (Does it exist in service WSDL?)",
faultStringElement.getStringValue());
}
@Override
protected int getNumPortsToFind()
{
return 1;
}
}