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.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.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.RequestAssertion;
28  import com.eviware.soapui.model.testsuite.ResponseAssertion;
29  
30  /***
31   * Asserts that the specified message is a valid SOAP Message 
32   * 
33   * @author ole.matzura
34   */
35  
36  public class SoapResponseAssertion extends WsdlMessageAssertion implements ResponseAssertion, RequestAssertion
37  {
38  	public static final String ID = "SOAP Response";
39  	public static final String LABEL = "SOAP Response";
40  
41  	public SoapResponseAssertion( TestAssertionConfig assertionConfig, Assertable assertable )
42  	{
43  		super( assertionConfig, assertable, false, false, false, true );
44  	}
45  	
46  	@Override
47  	protected String internalAssertResponse( MessageExchange messageExchange, SubmitContext context )
48  				throws AssertionException
49  	{
50  		WsdlContext wsdlContext = ((WsdlMessageExchange)messageExchange).getOperation().getInterface().getWsdlContext();
51  		WsdlValidator validator = new WsdlValidator( wsdlContext );
52  		
53  		try
54  		{
55  			AssertionError[] errors = validator.assertResponse( (WsdlMessageExchange) messageExchange, true );
56  			if (errors.length > 0)
57  				throw new AssertionException(errors);
58  		}
59  		catch( AssertionException e )
60  		{
61  			throw e;
62  		}
63  		catch (Exception e)
64  		{
65  			throw new AssertionException( new AssertionError( e.getMessage() ));
66  		}
67  		
68  		return "Response Envelope OK";
69  	}
70  
71  	@Override
72  	protected String internalAssertRequest( MessageExchange messageExchange, SubmitContext context ) throws AssertionException
73  	{
74  		WsdlContext wsdlContext = ((WsdlMessageExchange)messageExchange).getOperation().getInterface().getWsdlContext();
75  		WsdlValidator validator = new WsdlValidator( wsdlContext );
76  		
77  		try
78  		{
79  			AssertionError[] errors = validator.assertRequest( (WsdlMessageExchange) messageExchange, true );
80  			if (errors.length > 0)
81  				throw new AssertionException(errors);
82  		}
83  		catch( AssertionException e )
84  		{
85  			throw e;
86  		}
87  		catch (Exception e)
88  		{
89  			throw new AssertionException( new AssertionError( e.getMessage() ));
90  		}
91  		
92  		return "Request Envelope OK";
93  	}
94  	
95  	public static class Factory extends AbstractTestAssertionFactory
96  	{
97  		public Factory()
98  		{
99  			super(SoapResponseAssertion.ID, SoapResponseAssertion.LABEL, SoapResponseAssertion.class, WsdlRequest.class);
100 		}
101 	}
102 }