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) 2005 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.core;
18  
19  import org.junit.AfterClass;
20  import org.springframework.context.ConfigurableApplicationContext;
21  
22  /**
23   * This class is a base class for tests in the EL4J framework. By default it keeps the created application context
24   * during all the tests in a test class.
25   *
26   * @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/modules/core/src/test/java/ch/elca/el4j/tests/core/AbstractTest.java $
27   *
28   * @author Martin Zeltner (MZE)
29   * @author Stefan Wismer (SWI)
30   */
31  public abstract class AbstractTest {
32  	/**
33  	 * Application context to load beans.
34  	 */
35  	private ConfigurableApplicationContext m_applicationContext;
36  
37  	/**
38  	 * Hide default constructor.
39  	 */
40  	protected AbstractTest() { }
41  
42  	/**
43  	 * @return Returns the application context.
44  	 */
45  	protected synchronized ConfigurableApplicationContext getApplicationContext() {
46  		if (m_applicationContext == null) {
47  			
48  			m_applicationContext = ModuleTestContextCache.get(getIncludeConfigLocations(),
49  				getExcludeConfigLocations(), isBeanOverridingAllowed());
50  		}
51  		return m_applicationContext;
52  	}
53  	
54  	/**
55  	 * Close all application contexts. This method gets executed "@AfterClass", but something like
56  	 * TestNG's "@AfterSuite" would be more efficient.
57  	 */
58  	@AfterClass
59  	public static void closeAllApplicationContexts() {
60  		ModuleTestContextCache.clear();
61  	}
62  
63  	/**
64  	 * @return Returns <code>true</code> if bean definition overriding should
65  	 *         be allowed.
66  	 */
67  	protected boolean isBeanOverridingAllowed() {
68  		return false;
69  	}
70  
71  	/**
72  	 * @return Returns the string array with exclude locations.
73  	 */
74  	protected String[] getExcludeConfigLocations() {
75  		return null;
76  	}
77  
78  	/**
79  	 * @return Returns the string array with include locations.
80  	 */
81  	protected abstract String[] getIncludeConfigLocations();
82  }