View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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  import com.eviware.soapui.config.RequestAssertionConfig;
16  import com.eviware.soapui.impl.wsdl.panels.support.assertions.Assertable;
17  import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
18  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
19  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlValidator;
20  import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
21  import com.eviware.soapui.model.iface.SubmitContext;
22  
23  public class SoapResponseAssertion extends WsdlMessageAssertion implements ResponseAssertion, RequestAssertion
24  {
25  	public static final String ID = "SOAP Response";
26  
27  	public SoapResponseAssertion( RequestAssertionConfig assertionConfig, Assertable assertable )
28  	{
29  		super( assertionConfig, assertable );
30  	}
31  	
32  	@Override
33  	protected String internalAssertResponse( WsdlMessageExchange messageExchange, SubmitContext context )
34  				throws AssertionException
35  	{
36  		WsdlContext wsdlContext = messageExchange.getOperation().getInterface().getWsdlContext();
37  		WsdlValidator validator = new WsdlValidator( wsdlContext );
38  		
39  		try
40  		{
41  			AssertionError[] errors = validator.assertResponse( messageExchange, true );
42  			if (errors.length > 0)
43  				throw new AssertionException(errors);
44  		}
45  		catch( AssertionException e )
46  		{
47  			throw e;
48  		}
49  		catch (Exception e)
50  		{
51  			throw new AssertionException( new AssertionError( e.getMessage() ));
52  		}
53  		
54  		return "Response Envelope OK";
55  	}
56  
57  	@Override
58  	protected String internalAssertRequest( WsdlMessageExchange messageExchange, SubmitContext context ) throws AssertionException
59  	{
60  		WsdlContext wsdlContext = messageExchange.getOperation().getInterface().getWsdlContext();
61  		WsdlValidator validator = new WsdlValidator( wsdlContext );
62  		
63  		try
64  		{
65  			AssertionError[] errors = validator.assertRequest( messageExchange, true );
66  			if (errors.length > 0)
67  				throw new AssertionException(errors);
68  		}
69  		catch( AssertionException e )
70  		{
71  			throw e;
72  		}
73  		catch (Exception e)
74  		{
75  			throw new AssertionException( new AssertionError( e.getMessage() ));
76  		}
77  		
78  		return "Request Envelope OK";
79  	}
80  }