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