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 not a SOAP Fault
27 *
28 * @author Ole.Matzura
29 */
30
31 public class NotSoapFaultAssertion extends WsdlMessageAssertion implements ResponseAssertion
32 {
33 public static final String ID = "SOAP Fault Assertion";
34
35 public static final String LABEL = "Not SOAP Fault";
36
37 public NotSoapFaultAssertion(RequestAssertionConfig assertionConfig, Assertable assertable )
38 {
39 super(assertionConfig, assertable);
40 }
41
42 public String internalAssertResponse(WsdlMessageExchange messageExchange, SubmitContext context ) throws AssertionException
43 {
44 String responseContent = messageExchange.getResponseContent();
45 try
46 {
47
48 if( responseContent.indexOf( ":Fault" ) > 0 || responseContent.indexOf( "<Fault" ) > 0 )
49 {
50 SoapVersion soapVersion = messageExchange.getOperation().getInterface().getSoapVersion();
51 XmlObject xml = XmlObject.Factory.parse( responseContent );
52 XmlObject[] paths = xml.selectPath( "declare namespace env='" + soapVersion.getEnvelopeNamespace() + "';" +
53 "//env:Fault");
54 if( paths.length > 0 )
55 throw new AssertionException( new AssertionError("Response is a SOAP Fault") );
56 }
57 }
58 catch (XmlException e)
59 {
60 throw new AssertionException( new AssertionError(e.getMessage()) );
61 }
62
63 return "Response is not a SOAP Fault";
64 }
65
66 @Override
67 protected String internalAssertRequest( WsdlMessageExchange messageExchange, SubmitContext context ) throws AssertionException
68 {
69 return null;
70 }
71 }