View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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.ResponseAssertion;
28  
29  /***
30   * Asserts that the specified message is a valid SOAP Message
31   * 
32   * @author ole.matzura
33   */
34  
35  public class SoapResponseAssertion extends WsdlMessageAssertion implements ResponseAssertion
36  {
37  	public static final String ID = "SOAP Response";
38  	public static final String LABEL = "SOAP Response";
39  
40  	public SoapResponseAssertion( TestAssertionConfig assertionConfig, Assertable assertable )
41  	{
42  		super( assertionConfig, assertable, false, false, false, true );
43  	}
44  
45  	@Override
46  	protected String internalAssertResponse( MessageExchange messageExchange, SubmitContext context )
47  			throws AssertionException
48  	{
49  		WsdlContext wsdlContext = ( ( WsdlMessageExchange )messageExchange ).getOperation().getInterface()
50  				.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  	public static class Factory extends AbstractTestAssertionFactory
72  	{
73  		public Factory()
74  		{
75  			super( SoapResponseAssertion.ID, SoapResponseAssertion.LABEL, SoapResponseAssertion.class, WsdlRequest.class );
76  		}
77  
78  		@Override
79  		public Class<? extends WsdlMessageAssertion> getAssertionClassType()
80  		{
81  			return SoapResponseAssertion.class;
82  		}
83  	}
84  
85  	@Override
86  	protected String internalAssertRequest( MessageExchange messageExchange, SubmitContext context )
87  			throws AssertionException
88  	{
89  		return null;
90  	}
91  }