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