View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 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;
14  
15  import java.util.Vector;
16  
17  import com.eviware.soapui.config.RequestAssertionConfig;
18  import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
19  import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
20  import com.eviware.soapui.model.iface.SubmitContext;
21  import com.eviware.soapui.model.testsuite.Assertable;
22  import com.eviware.soapui.model.testsuite.AssertionError;
23  import com.eviware.soapui.model.testsuite.AssertionException;
24  import com.eviware.soapui.model.testsuite.RequestAssertion;
25  import com.eviware.soapui.model.testsuite.ResponseAssertion;
26  
27  /***
28   * Assertion for verifiying that WS-Security processing was ok
29   * 
30   * @author Ole.Matzura
31   */
32  
33  public class WSSStatusAssertion extends WsdlMessageAssertion implements ResponseAssertion, RequestAssertion
34  {
35  	public static final String ID = "WSS Status Assertion";
36  
37  	/***
38  	 * Constructor for our assertion.
39  	 * 
40  	 * @param assertionConfig
41  	 * @param modelItem
42  	 */
43  	public WSSStatusAssertion( RequestAssertionConfig assertionConfig, Assertable modelItem )
44  	{
45  		super( assertionConfig, modelItem, false, false, false, true );
46  	}
47  
48  	/***
49  	 * @see com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion#internalAssertRequest(com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange,
50  	 *      com.eviware.soapui.model.iface.SubmitContext)
51  	 */
52  	protected String internalAssertRequest( WsdlMessageExchange messageExchange, SubmitContext context )
53  				throws AssertionException
54  	{
55  		Vector result = messageExchange.getRequestWssResult();
56  		
57  		if( result == null || result.isEmpty() )
58  			throw new AssertionException( new AssertionError( "Missing WS-Security results" ));
59  		
60  		for( int c = 0; c < result.size(); c++ )
61  		{
62  			if( result.get( c ) instanceof Exception )
63  			{
64  				throw new AssertionException( new AssertionError( "WS-Security validation failed: " + result.get( c )));
65  			}
66  		}
67  		
68  		return "WS-Security status OK";
69  	}
70  
71  	/***
72  	 * @see com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion#internalAssertResponse(com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange,
73  	 *      com.eviware.soapui.model.iface.SubmitContext)
74  	 */
75  	protected String internalAssertResponse( WsdlMessageExchange messageExchange, SubmitContext context )
76  				throws AssertionException
77  	{
78  		Vector result = messageExchange.getResponseWssResult();
79  		
80  		if( result == null || result.isEmpty() )
81  			throw new AssertionException( new AssertionError( "Missing WS-Security results" ));
82  		
83  		for( int c = 0; c < result.size(); c++ )
84  		{
85  			if( result.get( c ) instanceof Exception )
86  			{
87  				throw new AssertionException( new AssertionError( "WS-Security validation failed: " + result.get( c )));
88  			}
89  		}
90  		
91  		return "WS-Security status OK";
92  	}
93  }