1
2
3
4
5
6
7
8
9
10
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 }