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