ch.elca.el4j.tests.core
Class ModuleTestContextLoader

java.lang.Object
  extended by org.springframework.test.context.support.AbstractContextLoader
      extended by ch.elca.el4j.tests.core.ModuleTestContextLoader
All Implemented Interfaces:
ModuleApplicationContextCreationListener, ContextLoader

public class ModuleTestContextLoader
extends AbstractContextLoader
implements ModuleApplicationContextCreationListener

Application context loader for tests with the module application context.

Author:
Simon Stelling (SST), Martin Zeltner (MZE)
File-location:
ModuleTestContextLoader
Last check-in date:
2010-12-21 11:08:04 +0100 (Di, 21. Dez 2010) by swismer for revision 4253

Nested Class Summary
private  class ModuleTestContextLoader.TernaryBoolean
          Helper class.
 
Field Summary
private static org.slf4j.Logger s_logger
          Private logger.
private static ThreadLocal<Class<?>> s_testedClass
          Set by EL4JJunit4ClassRunner upon instanciation of the test class.
 
Constructor Summary
ModuleTestContextLoader()
           
 
Method Summary
private  ModuleApplicationContextConfiguration createModuleApplicationContextConfiguration()
          Finds @ExtendedContextConfiguration annotations along the inheritance graph of the test class and aggregates the information into an instance of ModuleApplicationsContextConfiguration.
protected  void customizeModuleApplicationContextConfiguration(ModuleApplicationContextConfiguration config)
          Interception method to customize the configuration of the module application context, before the module application context will be created.
 void finishRefresh(ModuleApplicationContext context)
          
 String getResourceSuffix()
          Returns "-context.xml".
 ConfigurableApplicationContext loadContext(String... locations)
          Loads a ModuleApplicationContext from the supplied locations using the ModuleApplicationContextConfiguration created in createModuleApplicationContextConfiguration.
 void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
          
private  void recursivelyConfigure(Class<?> annotatedClass, ModuleApplicationContextConfiguration config)
          recusively walks through the inheritance tree and applies attributes from the @ExtendedContextConfiguration annotations most-specific-last.
static void setTestedClass(Class<?> testClass)
           
 
Methods inherited from class org.springframework.test.context.support.AbstractContextLoader
generateDefaultLocations, isGenerateDefaultLocations, modifyLocations, processLocations
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_logger

private static final org.slf4j.Logger s_logger
Private logger.


s_testedClass

private static ThreadLocal<Class<?>> s_testedClass
Set by EL4JJunit4ClassRunner upon instanciation of the test class. Needed to discover @ExtendedContextConfiguration annotations which influence the configuration of the ModuleApplicationContext to be loaded.

Constructor Detail

ModuleTestContextLoader

public ModuleTestContextLoader()
Method Detail

loadContext

public ConfigurableApplicationContext loadContext(String... locations)
                                           throws Exception
Loads a ModuleApplicationContext from the supplied locations using the ModuleApplicationContextConfiguration created in createModuleApplicationContextConfiguration.

Specified by:
loadContext in interface ContextLoader
Throws:
Exception

createModuleApplicationContextConfiguration

private ModuleApplicationContextConfiguration createModuleApplicationContextConfiguration()
                                                                                   throws IllegalStateException
Finds @ExtendedContextConfiguration annotations along the inheritance graph of the test class and aggregates the information into an instance of ModuleApplicationsContextConfiguration.

Returns:
the aggregated context configuration
Throws:
IllegalStateException - if the tested class or a superclass of it is annotated with a @ExtendedContextConfiguration but none of its transitive superclasses are annotated with a @ContextConfiguration.

recursivelyConfigure

private void recursivelyConfigure(Class<?> annotatedClass,
                                  ModuleApplicationContextConfiguration config)
recusively walks through the inheritance tree and applies attributes from the @ExtendedContextConfiguration annotations most-specific-last.

Parameters:
annotatedClass - the class whose annotations should get inspected
config - the ModuleApplicationContextConfiguration to modify

customizeModuleApplicationContextConfiguration

protected void customizeModuleApplicationContextConfiguration(ModuleApplicationContextConfiguration config)
Interception method to customize the configuration of the module application context, before the module application context will be created.

Parameters:
config - Is the module application context configuration.

getResourceSuffix

public String getResourceSuffix()
Returns "-context.xml".

Specified by:
getResourceSuffix in class AbstractContextLoader

postProcessBeanFactory

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)

Specified by:
postProcessBeanFactory in interface ModuleApplicationContextCreationListener

finishRefresh

public void finishRefresh(ModuleApplicationContext context)

Specified by:
finishRefresh in interface ModuleApplicationContextCreationListener

setTestedClass

public static void setTestedClass(Class<?> testClass)
Parameters:
testClass - the test class which is annotated with @ConfigurationContext and possibly @ExtendedConfigurationContext


Copyright © 2005-2011 ELCA. All Rights Reserved.