View Javadoc

1   /*
2    * $Id: CxfBadSoapRequestTestCase.java 22474 2011-07-20 12:18:20Z justin.calleja $
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 static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  
16  import java.util.Arrays;
17  import java.util.Collection;
18  import java.util.List;
19  
20  import org.dom4j.Document;
21  import org.dom4j.DocumentHelper;
22  import org.dom4j.Element;
23  import org.junit.Rule;
24  import org.junit.Test;
25  import org.junit.runners.Parameterized.Parameters;
26  import org.mule.DefaultMuleMessage;
27  import org.mule.api.MuleMessage;
28  import org.mule.module.client.MuleClient;
29  import org.mule.tck.AbstractServiceAndFlowTestCase;
30  import org.mule.tck.junit4.rule.DynamicPort;
31  import org.mule.transport.http.HttpConstants;
32  import org.mule.util.StringUtils;
33  
34  public class CxfBadSoapRequestTestCase extends AbstractServiceAndFlowTestCase
35  {
36  
37      @Rule
38      public DynamicPort dynamicPort = new DynamicPort("port1");
39  
40      public CxfBadSoapRequestTestCase(ConfigVariant variant, String configResources)
41      {
42          super(variant, configResources);
43      }
44          
45      @Parameters
46      public static Collection<Object[]> parameters()
47      {
48          return Arrays.asList(new Object[][]{
49              {ConfigVariant.SERVICE, "soap-request-conf-service.xml"},
50              {ConfigVariant.FLOW, "soap-request-conf-flow.xml"}
51          });
52      }
53  
54      @Test
55      public void testSoapDocumentError() throws Exception
56      {
57          MuleClient client = new MuleClient(muleContext);
58  
59          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\">"
60                               + "<soap:Body>"
61                               + "<ssss xmlns=\"http://www.muleumo.org\">"
62                               + "<request xmlns=\"http://www.muleumo.org\">Bad Request</request>"
63                               + "</ssss>"
64                               + "</soap:Body>" + "</soap:Envelope>";
65  
66          MuleMessage reply = client.send("http://localhost:" + dynamicPort.getNumber() + "/services/TestComponent", new DefaultMuleMessage(
67              soapRequest, muleContext));
68  
69          assertNotNull(reply);
70          assertNotNull(reply.getPayload());
71  
72          String ct = reply.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE, StringUtils.EMPTY);
73          assertEquals("text/xml; charset=UTF-8", ct);        
74          
75          Document document = DocumentHelper.parseText(reply.getPayloadAsString());
76          List fault = document.selectNodes("//soap:Envelope/soap:Body/soap:Fault/faultcode");
77  
78          assertEquals(1, fault.size());
79          Element faultCodeElement = (Element) fault.get(0);
80  
81          assertEquals("soap:Client", faultCodeElement.getStringValue());
82  
83          fault = document.selectNodes("//soap:Envelope/soap:Body/soap:Fault/faultstring");
84          assertEquals(1, fault.size());
85          Element faultStringElement = (Element) fault.get(0);
86          assertEquals("Message part {http://www.muleumo.org}ssss was not recognized.  (Does it exist in service WSDL?)",
87              faultStringElement.getStringValue());
88      }
89  
90  }