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.jms;
14  
15  import com.eviware.soapui.config.TestAssertionConfig;
16  import com.eviware.soapui.impl.wsdl.WsdlRequest;
17  import com.eviware.soapui.impl.wsdl.submit.transports.jms.HermesJmsRequestTransport;
18  import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
19  import com.eviware.soapui.impl.wsdl.teststeps.assertions.AbstractTestAssertionFactory;
20  import com.eviware.soapui.model.iface.MessageExchange;
21  import com.eviware.soapui.model.iface.SubmitContext;
22  import com.eviware.soapui.model.testsuite.Assertable;
23  import com.eviware.soapui.model.testsuite.AssertionError;
24  import com.eviware.soapui.model.testsuite.AssertionException;
25  import com.eviware.soapui.model.testsuite.RequestAssertion;
26  import com.eviware.soapui.model.testsuite.ResponseAssertion;
27  
28  /***
29   * Asserts JMS response within timeout
30   * 
31   * @author nebojsa.tasic
32   */
33  
34  public class JMSTimeoutAssertion extends WsdlMessageAssertion implements ResponseAssertion, RequestAssertion
35  {
36  	public static final String ID = "JMS Timeout";
37  	public static final String LABEL = "JMS Timeout";
38  
39  	public JMSTimeoutAssertion( TestAssertionConfig assertionConfig, Assertable assertable )
40  	{
41  		super( assertionConfig, assertable, false, false, false, true );
42  	}
43  
44  	@Override
45  	protected String internalAssertResponse( MessageExchange messageExchange, SubmitContext context )
46  			throws AssertionException
47  	{
48  		Boolean temp = ( Boolean )context.getProperty( HermesJmsRequestTransport.IS_JMS_MESSAGE_RECEIVED );
49  		Boolean messageReceived = temp != null ? temp : false;
50  
51  		Long timeout = ( Long )context.getProperty( HermesJmsRequestTransport.JMS_RECEIVE_TIMEOUT );
52  		if( messageReceived != null && !messageReceived )
53  		{
54  			throw new AssertionException( new AssertionError( "JMS Message timeout error! Message is not received in "
55  					+ timeout + " ms." ) );
56  		}
57  
58  		return "JMS Timeout OK";
59  	}
60  
61  	@Override
62  	protected String internalAssertRequest( MessageExchange messageExchange, SubmitContext context )
63  			throws AssertionException
64  	{
65  		return "JMS Timeout OK";
66  	}
67  
68  	public static class Factory extends AbstractTestAssertionFactory
69  	{
70  		public Factory()
71  		{
72  			super( JMSTimeoutAssertion.ID, JMSTimeoutAssertion.LABEL, JMSTimeoutAssertion.class, WsdlRequest.class );
73  		}
74  
75  		@Override
76  		public Class<? extends WsdlMessageAssertion> getAssertionClassType()
77  		{
78  			return JMSTimeoutAssertion.class;
79  		}
80  	}
81  }