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 com.eviware.soapui.config.RequestAssertionConfig;
    16  import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
    17  import com.eviware.soapui.impl.wsdl.support.assertions.Assertable;
    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.model.iface.SubmitContext;
    22
    23  /***
    24   * Asserts that the specified message is a valid SOAP Message
    25   *
    26   * @author ole.matzura
    27   */
    28
    29  public class SoapResponseAssertion extends WsdlMessageAssertion implements ResponseAssertion, RequestAssertion
    30  {
    31  	public static final String ID = "SOAP Response";
    32
    33  	public SoapResponseAssertion( RequestAssertionConfig assertionConfig, Assertable assertable )
    34  	{
    35  		super( assertionConfig, assertable, false, false );
    36  	}
    37
    38  	@Override
    39  	protected String internalAssertResponse( WsdlMessageExchange messageExchange, SubmitContext context )
    40  				throws AssertionException
    41  	{
    42  		WsdlContext wsdlContext = messageExchange.getOperation().getInterface().getWsdlContext();
    43  		WsdlValidator validator = new WsdlValidator( wsdlContext );
    44
    45  		try
    46  		{
    47  			AssertionError[] errors = validator.assertResponse( messageExchange, true );
    48  			if (errors.length > 0)
    49  				throw new AssertionException(errors);
    50  		}
    51  		catch( AssertionException e )
    52  		{
    53  			throw e;
    54  		}
    55  		catch (Exception e)
    56  		{
    57  			throw new AssertionException( new AssertionError( e.getMessage() ));
    58  		}
    59
    60  		return "Response Envelope OK";
    61  	}
    62
    63  	@Override
    64  	protected String internalAssertRequest( WsdlMessageExchange messageExchange, SubmitContext context ) throws AssertionException
    65  	{
    66  		WsdlContext wsdlContext = messageExchange.getOperation().getInterface().getWsdlContext();
    67  		WsdlValidator validator = new WsdlValidator( wsdlContext );
    68
    69  		try
    70  		{
    71  			AssertionError[] errors = validator.assertRequest( messageExchange, true );
    72  			if (errors.length > 0)
    73  				throw new AssertionException(errors);
    74  		}
    75  		catch( AssertionException e )
    76  		{
    77  			throw e;
    78  		}
    79  		catch (Exception e)
    80  		{
    81  			throw new AssertionException( new AssertionError( e.getMessage() ));
    82  		}
    83
    84  		return "Request Envelope OK";
    85  	}
    86  }