View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2006 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.tests.services.remoting.rmi;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.fail;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  import org.junit.Test;
25  import org.springframework.beans.factory.BeanFactory;
26  import org.springframework.context.ApplicationContext;
27  
28  import ch.elca.el4j.core.context.ModuleApplicationContext;
29  import ch.elca.el4j.tests.services.remoting.loadbalancing.common.BusinessObject;
30  
31  /**
32   * This class tests the idempotent invocation interceptor that handles retrials
33   * by itself.
34   *
35   * @svnLink $Revision: 3873 $;$Date: 2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/tests/remoting/apps/functional_tests/src/test/java/ch/elca/el4j/tests/services/remoting/rmi/ClientTestCaseNoContextPassing.java $
36   *
37   * @author Stefan Pleisch (SPL)
38   */
39  public class ClientTestCaseNoContextPassing {
40  
41  	public ClientTestCaseNoContextPassing() {
42  		super();
43  		m_applicationContext = new ModuleApplicationContext(
44  			getInclusiveConfigLocations(),
45  			(String[]) null,
46  			false,
47  			null);
48  	} // <init>
49  
50  	/**
51  	 * Tests whether the server/DB properly abort the transaction upon reception
52  	 * of a special flag.
53  	 *
54  	 * @see #THROW_IDEMPOTENTINVOCATION_EXCEPTION
55  	 */
56  	@Test
57  	public void testNextProtocol() {
58  		getLog().debug("Starting test 'testIdempotence'....");
59  		try {
60  			s_logger.debug("-- Calling with hello 1") ;
61  			String result = getTestObj().call("hello1") ;
62  			assertEquals("Server 1 should have executed this code.",
63  				"localhost:8089",
64  				result);
65  			s_logger.debug("-- Calling with hello 2") ;
66  			result = getTestObj().call("hello2") ;
67  			assertEquals("Server 1 should have executed this code.",
68  				"localhost:8089",
69  				result);
70  			s_logger.debug("-- Calling with hello 3") ;
71  			result = getTestObj().call("hello3") ;
72  			assertEquals("Server 1 should have executed this code.",
73  				"localhost:8089",
74  				result);
75  			s_logger.debug("-- Calling with hello 4") ;
76  			result = getTestObj().call("hello4") ;
77  			assertEquals("Server 1 should have executed this code.",
78  				"localhost:8089",
79  				result);
80  			s_logger.debug("-- Calling with hello 5") ;
81  			result = getTestObj().call("hello5") ;
82  			assertEquals("Server 1 should have executed this code.",
83  				"localhost:8089",
84  				result);
85  
86  		} catch (Exception e) {
87  			e.printStackTrace();
88  			fail("Exception occurred: " + e.getMessage());
89  		} // catch
90  	} // testSecondAccess()
91  
92  	/** {@inheritDoc} */
93  	protected void runTest() {
94  		testNextProtocol();
95  	} // runTest()
96  
97  	/** {@inheritDoc} */
98  	protected String[] getInclusiveConfigLocations() {
99  		return new String[] {
100 			"classpath*:mandatory/*.xml",
101 			"classpath:rmi/rmi-nocontext-protocol-config.xml",
102 			"classpath:rmi/startup-client.xml"};
103 	} // getInclusiveConfigLocations()
104 
105 	protected Logger getLog() {
106 		return s_logger;
107 	} // getLog()
108 
109 	protected BusinessObject getTestObj() {
110 		if (m_obj == null) {
111 			BeanFactory factory = (BeanFactory) m_applicationContext;
112 
113 			m_obj = (BusinessObject) factory.getBean("rmiBusinessObj");
114 
115 		} // if
116 		return m_obj;
117 	} // getTestObj
118 
119 	/**
120 	 * Private logger.
121 	 */
122 	private static Logger s_logger = LoggerFactory
123 		.getLogger(ClientTestCaseNoContextPassing.class);
124 
125 	private ApplicationContext m_applicationContext ;
126 	
127 	private BusinessObject m_obj ;
128 	
129 } // CLASS ClientMultipleServerTestCase