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 javax.jms.Message;
16  
17  import com.eviware.soapui.config.TestAssertionConfig;
18  import com.eviware.soapui.impl.wsdl.WsdlRequest;
19  import com.eviware.soapui.impl.wsdl.submit.transports.jms.HermesJmsRequestTransport;
20  import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
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  import com.eviware.soapui.model.testsuite.ResponseAssertion;
29  
30  /***
31   * Asserts JMS response within timeout
32   * 
33   * @author nebojsa.tasic
34   */
35  
36  public class JMSTimeoutAssertion extends WsdlMessageAssertion implements ResponseAssertion, RequestAssertion
37  {
38  	public static final String ID = "JMS Timeout";
39  	public static final String LABEL = "JMS Timeout";
40  	
41  	public JMSTimeoutAssertion(TestAssertionConfig assertionConfig, Assertable assertable)
42  	{
43  		super(assertionConfig, assertable, false, false, false, true);
44  	}
45  
46  	@Override
47  	protected String internalAssertResponse(MessageExchange messageExchange, SubmitContext context)
48  			throws AssertionException
49  	{
50  		
51  		Message message =(Message) context.getProperty(HermesJmsRequestTransport.JMS_MESSAGE_RECEIVE);
52  		 context.setProperty(HermesJmsRequestTransport.JMS_MESSAGE_RECEIVE,null);
53  		Long timeout =(Long) context.getProperty(HermesJmsRequestTransport.JMS_RECEIVE_TIMEOUT);
54  		if(message==null){
55  			throw new AssertionException(new AssertionError("JMS Message timeout error! Message is not received in "+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  
69  	
70  	public static class Factory extends AbstractTestAssertionFactory
71  	{
72  		public Factory()
73  		{
74  			super(JMSTimeoutAssertion.ID, JMSTimeoutAssertion.LABEL, JMSTimeoutAssertion.class, WsdlRequest.class);
75  		}
76  	}
77  }