View Javadoc

1   /*
2    *  soapui, copyright (C) 2005 Ole Matzura / eviware.com 
3    *
4    *  SoapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
7    *
8    *  SoapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.teststeps.assertions;
14  
15  import org.apache.xmlbeans.XmlException;
16  import org.apache.xmlbeans.XmlObject;
17  
18  import com.eviware.soapui.config.RequestAssertionConfig;
19  import com.eviware.soapui.impl.wsdl.teststeps.WsdlAssertion;
20  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
21  
22  /***
23   * Assertion that checks that the associated WsdlTestRequests response is not a SOAP Fault
24   * 
25   * @author Ole.Matzura
26   */
27  
28  public class SoapFaultAssertion extends WsdlAssertion
29  {
30     public SoapFaultAssertion(RequestAssertionConfig assertionConfig, WsdlTestRequest request)
31     {
32        super(assertionConfig, request);
33     }
34  
35     public String assertRequest(WsdlTestRequest request) throws AssertionException
36     {
37        String response = request.getResponseContent();
38        try
39        {
40           XmlObject xml = XmlObject.Factory.parse( response );
41           XmlObject[] paths = xml.selectPath( "declare namespace env='http://schemas.xmlsoap.org/soap/envelope/';" + 
42                 "$this/env:Envelope/env:Body/env:Fault");
43           if( paths.length > 0 )
44              throw new AssertionException( new AssertionError("Response contains SOAP Fault") );
45        }
46        catch (XmlException e)
47        {
48           throw new AssertionException( new AssertionError(e.getMessage()) );
49        }
50        
51        return "Response is not a SOAP Fault";
52     }
53  }