View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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.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  }