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.panels.support.assertions.Assertable;
20 import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
21 import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
22 import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
23 import com.eviware.soapui.model.iface.SubmitContext;
24
25 /***
26 * Assertion that checks that the associated WsdlTestRequests response is a SOAP Fault
27 *
28 * @author Ole.Matzura
29 */
30
31 public class SoapFaultAssertion extends WsdlMessageAssertion implements ResponseAssertion
32 {
33 public static final String ID = "Not SOAP Fault Assertion";
34
35
36 public SoapFaultAssertion(RequestAssertionConfig assertionConfig, Assertable assertable )
37 {
38 super(assertionConfig, assertable);
39 }
40
41 public String internalAssertResponse(WsdlMessageExchange messageExchange, SubmitContext context ) throws AssertionException
42 {
43 String responseContent = messageExchange.getResponseContent();
44 try
45 {
46 SoapVersion soapVersion = messageExchange.getOperation().getInterface().getSoapVersion();
47 XmlObject xml = XmlObject.Factory.parse( responseContent );
48 XmlObject[] paths = xml.selectPath( "declare namespace env='" + soapVersion.getEnvelopeNamespace() + "';" +
49 "//env:Fault");
50 if( paths.length == 0 )
51 throw new AssertionException( new AssertionError("Response is not a SOAP Fault") );
52 }
53 catch (XmlException e)
54 {
55 throw new AssertionException( new AssertionError(e.getMessage()) );
56 }
57
58 return "Response is a SOAP Fault";
59 }
60
61 @Override
62 protected String internalAssertRequest( WsdlMessageExchange messageExchange, SubmitContext context ) throws AssertionException
63 {
64 return null;
65 }
66 }