View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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  
16  import com.eviware.soapui.config.TestAssertionConfig;
17  import com.eviware.soapui.impl.wsdl.WsdlRequest;
18  import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
19  import com.eviware.soapui.impl.wsdl.support.soap.SoapUtils;
20  import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
21  import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
22  import com.eviware.soapui.impl.wsdl.teststeps.assertions.AbstractTestAssertionFactory;
23  import com.eviware.soapui.model.iface.MessageExchange;
24  import com.eviware.soapui.model.iface.SubmitContext;
25  import com.eviware.soapui.model.testsuite.Assertable;
26  import com.eviware.soapui.model.testsuite.AssertionError;
27  import com.eviware.soapui.model.testsuite.AssertionException;
28  import com.eviware.soapui.model.testsuite.ResponseAssertion;
29  
30  /***
31   * Assertion that checks that the associated WsdlTestRequests response is a SOAP 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 ) throws AssertionException
47     {
48        String responseContent = messageExchange.getResponseContent();
49        try
50        {
51        	SoapVersion soapVersion = ((WsdlMessageExchange)messageExchange).getOperation().getInterface().getSoapVersion();
52        	
53        	if( !SoapUtils.isSoapFault( responseContent, soapVersion ))
54        		throw new AssertionException( new AssertionError("Response is not a SOAP Fault") );
55        }
56        catch (Exception e)
57        {
58           throw new AssertionException( new AssertionError(e.getMessage()) );
59        }
60        
61        return "Response is a SOAP Fault";
62     }
63  
64  	@Override
65  	protected String internalAssertRequest( MessageExchange messageExchange, SubmitContext context ) throws AssertionException
66  	{
67  		return null;
68  	}
69  	
70  	public static class Factory extends AbstractTestAssertionFactory
71  	{
72  		public Factory()
73  		{
74  			super(SoapFaultAssertion.ID, SoapFaultAssertion.LABEL, SoapFaultAssertion.class, WsdlRequest.class);
75  		}
76  	}
77  }