View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.teststeps.assertions;
14  
15  
16  import com.eviware.soapui.config.RequestAssertionConfig;
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.model.iface.SubmitContext;
22  import com.eviware.soapui.model.testsuite.Assertable;
23  import com.eviware.soapui.model.testsuite.AssertionError;
24  import com.eviware.soapui.model.testsuite.AssertionException;
25  import com.eviware.soapui.model.testsuite.ResponseAssertion;
26  
27  /***
28   * Assertion that checks that the associated WsdlTestRequests response is a SOAP Fault
29   * 
30   * @author Ole.Matzura
31   */
32  
33  public class SoapFaultAssertion extends WsdlMessageAssertion implements ResponseAssertion
34  {
35  	public static final String ID = "Not SOAP Fault Assertion";
36  //	public static final String ID = "SOAP Fault";
37  
38  	public SoapFaultAssertion(RequestAssertionConfig assertionConfig, Assertable assertable )
39     {
40        super(assertionConfig, assertable, false, false, false, true);
41     }
42  
43     public String internalAssertResponse(WsdlMessageExchange messageExchange, SubmitContext context ) throws AssertionException
44     {
45        String responseContent = messageExchange.getResponseContent();
46        try
47        {
48        	SoapVersion soapVersion = messageExchange.getOperation().getInterface().getSoapVersion();
49        	
50        	if( !SoapUtils.isSoapFault( responseContent, soapVersion ))
51        		throw new AssertionException( new AssertionError("Response is not a SOAP Fault") );
52        }
53        catch (Exception 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  }