View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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()
51  				.getWsdlContext();
52  		WsdlValidator validator = new WsdlValidator( wsdlContext );
53  
54  		try
55  		{
56  			AssertionError[] errors = validator.assertResponse( ( WsdlMessageExchange )messageExchange, true );
57  			if( errors.length > 0 )
58  				throw new AssertionException( errors );
59  		}
60  		catch( AssertionException e )
61  		{
62  			throw e;
63  		}
64  		catch( Exception e )
65  		{
66  			throw new AssertionException( new AssertionError( e.getMessage() ) );
67  		}
68  
69  		return "Response Envelope OK";
70  	}
71  
72  	@Override
73  	protected String internalAssertRequest( MessageExchange messageExchange, SubmitContext context )
74  			throws AssertionException
75  	{
76  		WsdlContext wsdlContext = ( ( WsdlMessageExchange )messageExchange ).getOperation().getInterface()
77  				.getWsdlContext();
78  		WsdlValidator validator = new WsdlValidator( wsdlContext );
79  
80  		try
81  		{
82  			AssertionError[] errors = validator.assertRequest( ( WsdlMessageExchange )messageExchange, true );
83  			if( errors.length > 0 )
84  				throw new AssertionException( errors );
85  		}
86  		catch( AssertionException e )
87  		{
88  			throw e;
89  		}
90  		catch( Exception e )
91  		{
92  			throw new AssertionException( new AssertionError( e.getMessage() ) );
93  		}
94  
95  		return "Request Envelope OK";
96  	}
97  
98  	public static class Factory extends AbstractTestAssertionFactory
99  	{
100 		public Factory()
101 		{
102 			super( SoapResponseAssertion.ID, SoapResponseAssertion.LABEL, SoapResponseAssertion.class, WsdlRequest.class );
103 		}
104 	}
105 }