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 not a SOAP Fault
31 *
32 * @author Ole.Matzura
33 */
34
35 public class NotSoapFaultAssertion extends WsdlMessageAssertion implements ResponseAssertion
36 {
37 public static final String ID = "SOAP Fault Assertion";
38 public static final String LABEL = "Not SOAP Fault";
39
40 public NotSoapFaultAssertion(TestAssertionConfig assertionConfig, Assertable assertable )
41 {
42 super(assertionConfig, assertable, false, false, false, true);
43 }
44
45 public String internalAssertResponse( MessageExchange messageExchange, SubmitContext context ) throws AssertionException
46 {
47 String responseContent = messageExchange.getResponseContent();
48 try
49 {
50
51 SoapVersion soapVersion = ((WsdlMessageExchange)messageExchange).getOperation().getInterface().getSoapVersion();
52 if( SoapUtils.isSoapFault( responseContent, soapVersion ))
53 throw new AssertionException( new AssertionError("Response is a SOAP Fault") );
54 }
55 catch (Exception e)
56 {
57 throw new AssertionException( new AssertionError(e.getMessage()) );
58 }
59
60 return "Response is not a SOAP Fault";
61 }
62
63 @Override
64 protected String internalAssertRequest( MessageExchange messageExchange, SubmitContext context ) throws AssertionException
65 {
66 return null;
67 }
68
69 public static class Factory extends AbstractTestAssertionFactory
70 {
71 public Factory()
72 {
73 super(NotSoapFaultAssertion.ID, NotSoapFaultAssertion.LABEL, NotSoapFaultAssertion.class, WsdlRequest.class);
74 }
75 }
76 }