View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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.submit.WsdlMessageExchange;
17  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
18  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlValidator;
19  import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
20  import com.eviware.soapui.impl.wsdl.teststeps.WsdlMockResponseTestStep;
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  
29  /***
30   * Asserts that the specified message is a valid SOAP Message
31   * 
32   * @author ole.matzura
33   */
34  
35  public class SoapRequestAssertion extends WsdlMessageAssertion implements RequestAssertion
36  {
37  	public static final String ID = "SOAP Request";
38  	public static final String LABEL = "SOAP Request";
39  
40  	public SoapRequestAssertion( TestAssertionConfig assertionConfig, Assertable assertable )
41  	{
42  		super( assertionConfig, assertable, false, false, false, false );
43  	}
44  
45  	@Override
46  	protected String internalAssertRequest( MessageExchange messageExchange, SubmitContext context )
47  			throws AssertionException
48  	{
49  		WsdlContext wsdlContext = ( ( WsdlMessageExchange )messageExchange ).getOperation().getInterface()
50  				.getWsdlContext();
51  		WsdlValidator validator = new WsdlValidator( wsdlContext );
52  
53  		try
54  		{
55  			AssertionError[] errors = validator.assertRequest( ( WsdlMessageExchange )messageExchange, true );
56  			if( errors.length > 0 )
57  				throw new AssertionException( errors );
58  		}
59  		catch( AssertionException e )
60  		{
61  			throw e;
62  		}
63  		catch( Exception e )
64  		{
65  			throw new AssertionException( new AssertionError( e.getMessage() ) );
66  		}
67  
68  		return "Request Envelope OK";
69  	}
70  
71  	public static class Factory extends AbstractTestAssertionFactory
72  	{
73  		public Factory()
74  		{
75  			super( SoapRequestAssertion.ID, SoapRequestAssertion.LABEL, SoapRequestAssertion.class,
76  					WsdlMockResponseTestStep.class );
77  		}
78  
79  		@Override
80  		public Class<? extends WsdlMessageAssertion> getAssertionClassType()
81  		{
82  			return SoapRequestAssertion.class;
83  		}
84  	}
85  
86  	@Override
87  	protected String internalAssertResponse( MessageExchange messageExchange, SubmitContext context )
88  			throws AssertionException
89  	{
90  		return null;
91  	}
92  }