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  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        	// check manually before resource intensive xpath
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  }