1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.teststeps.assertions.soap;
14
15 import com.eviware.soapui.config.TestAssertionConfig;
16 import com.eviware.soapui.impl.wsdl.WsdlRequest;
17 import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
18 import com.eviware.soapui.impl.wsdl.support.soap.SoapUtils;
19 import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
20 import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
21 import com.eviware.soapui.impl.wsdl.teststeps.assertions.AbstractTestAssertionFactory;
22 import com.eviware.soapui.model.iface.MessageExchange;
23 import com.eviware.soapui.model.iface.SubmitContext;
24 import com.eviware.soapui.model.testsuite.Assertable;
25 import com.eviware.soapui.model.testsuite.AssertionError;
26 import com.eviware.soapui.model.testsuite.AssertionException;
27 import com.eviware.soapui.model.testsuite.ResponseAssertion;
28
29 /***
30 * Assertion that checks that the associated WsdlTestRequests response is a SOAP
31 * Fault
32 *
33 * @author Ole.Matzura
34 */
35
36 public class SoapFaultAssertion extends WsdlMessageAssertion implements ResponseAssertion
37 {
38 public static final String ID = "Not SOAP Fault Assertion";
39 public static final String LABEL = "SOAP Fault";
40
41 public SoapFaultAssertion( TestAssertionConfig assertionConfig, Assertable assertable )
42 {
43 super( assertionConfig, assertable, false, false, false, true );
44 }
45
46 public String internalAssertResponse( MessageExchange messageExchange, SubmitContext context )
47 throws AssertionException
48 {
49 String responseContent = messageExchange.getResponseContent();
50 try
51 {
52 SoapVersion soapVersion = ( ( WsdlMessageExchange )messageExchange ).getOperation().getInterface()
53 .getSoapVersion();
54
55 if( !SoapUtils.isSoapFault( responseContent, soapVersion ) )
56 throw new AssertionException( new AssertionError( "Response is not a SOAP Fault" ) );
57 }
58 catch( Exception e )
59 {
60 throw new AssertionException( new AssertionError( e.getMessage() ) );
61 }
62
63 return "Response is a SOAP Fault";
64 }
65
66 @Override
67 protected String internalAssertRequest( MessageExchange messageExchange, SubmitContext context )
68 throws AssertionException
69 {
70 return null;
71 }
72
73 public static class Factory extends AbstractTestAssertionFactory
74 {
75 public Factory()
76 {
77 super( SoapFaultAssertion.ID, SoapFaultAssertion.LABEL, SoapFaultAssertion.class, WsdlRequest.class );
78 }
79 }
80 }