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