org.unitils.spring.util
Class ApplicationContextManager

java.lang.Object
  extended by org.unitils.core.util.AnnotatedInstanceManager<org.springframework.context.ApplicationContext,SpringApplicationContext>
      extended by org.unitils.spring.util.ApplicationContextManager

public class ApplicationContextManager
extends AnnotatedInstanceManager<org.springframework.context.ApplicationContext,SpringApplicationContext>

A class for managing and creating Spring application contexts.

todo javadoc

Author:
Tim Ducheyne, Filip Neven

Field Summary
protected  ApplicationContextFactory applicationContextFactory
          Factory for creating ApplicationContexts
 
Fields inherited from class org.unitils.core.util.AnnotatedInstanceManager
annotationClass, instanceClass, instances
 
Constructor Summary
ApplicationContextManager(ApplicationContextFactory applicationContextFactory)
          Creates a new instance, using the given ApplicationContextFactory.
 
Method Summary
protected  org.springframework.context.ApplicationContext createInstanceForValues(Object testObject, Class<?> testClass, List<String> locations)
          Creates a new application context for the given locations.
protected  List<String> getAnnotationValues(SpringApplicationContext annotation)
          Gets the locations that are specified for the given SpringApplicationContext annotation.
 org.springframework.context.ApplicationContext getApplicationContext(Object testObject)
          Gets the application context for the given test as described in the class javadoc.
 boolean hasApplicationContext(Object testObject)
          Checks whether the given test object has an application context linked to it.
 void invalidateApplicationContext(Class<?>... classes)
          Forces the reloading of the application context the next time that it is requested.
 
Methods inherited from class org.unitils.core.util.AnnotatedInstanceManager
afterInstanceCreate, createCustomCreatedInstance, createCustomCreatedInstanceFromCustomCreateMethodResult, getAnnotationValues, getCustomCreateMethod, getCustomCreateMethodReturnType, getInstance, getInstanceImpl, hasInstance, hasInstanceImpl, invalidateInstance, invokeCustomCreateMethod, isCustomCreateMethod, registerInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

applicationContextFactory

protected ApplicationContextFactory applicationContextFactory
Factory for creating ApplicationContexts

Constructor Detail

ApplicationContextManager

public ApplicationContextManager(ApplicationContextFactory applicationContextFactory)
Creates a new instance, using the given ApplicationContextFactory. The given list of BeanPostProcessors will be registered on all ApplicationContexts that are created.

Parameters:
applicationContextFactory - The factory for creating ApplicationContexts, not null.
Method Detail

getApplicationContext

public org.springframework.context.ApplicationContext getApplicationContext(Object testObject)
Gets the application context for the given test as described in the class javadoc. A UnitilsException will be thrown if no context could be retrieved or created.

Parameters:
testObject - The test instance, not null
Returns:
The application context, not null

hasApplicationContext

public boolean hasApplicationContext(Object testObject)
Checks whether the given test object has an application context linked to it. If true is returned, getApplicationContext(java.lang.Object) will return an application context, If false is returned, it will raise an exception.

Parameters:
testObject - The test instance, not null
Returns:
True if an application context is linked

invalidateApplicationContext

public void invalidateApplicationContext(Class<?>... classes)
Forces the reloading of the application context the next time that it is requested. If classes are given only contexts that are linked to those classes will be reset. If no classes are given, all cached contexts will be reset.

Parameters:
classes - The classes for which to reset the contexts

createInstanceForValues

protected org.springframework.context.ApplicationContext createInstanceForValues(Object testObject,
                                                                                 Class<?> testClass,
                                                                                 List<String> locations)
Creates a new application context for the given locations. The application context factory is used to create the instance. After creating the context, this will also register all BeanPostProcessors and refresh the context.

Note: for this to work, the application context may not have been refreshed in the factory. By registering the bean post processors before the refresh, we can intercept bean creation and bean wiring. This is no longer possible if the context is already refreshed.

Specified by:
createInstanceForValues in class AnnotatedInstanceManager<org.springframework.context.ApplicationContext,SpringApplicationContext>
Parameters:
locations - The locations where to find configuration files, not null
testObject - TODO
testClass - TODO
Returns:
the context, not null

getAnnotationValues

protected List<String> getAnnotationValues(SpringApplicationContext annotation)
Gets the locations that are specified for the given SpringApplicationContext annotation. An array with 1 empty string should be considered to be empty and null should be returned.

Specified by:
getAnnotationValues in class AnnotatedInstanceManager<org.springframework.context.ApplicationContext,SpringApplicationContext>
Parameters:
annotation - The annotation, not null
Returns:
The locations, null if no values were specified


Copyright © 2011. All Rights Reserved.