| java.lang.Object org.unitils.spring.SpringModule
SpringModule | public class SpringModule implements Module(Code) | | A module for Spring enabling a test class by offering an easy way to load application contexts and
an easy way of retrieving beans from the context and injecting them in the test.
The application context loading can be achieved by using the
SpringApplicationContext annotation. These
contexts are cached, so a context will be reused when possible. For example suppose a superclass loads a context and
a test-subclass wants to use this context, it will not create a new one.
SpringModule.invalidateApplicationContext }
can be used to force a reloading of a context if needed.
Spring bean retrieval can be done by annotating the corresponding fields in the test with following
annotations:
SpringBean ,
SpringBeanByName and
SpringBeanByType .
See the javadoc of these annotations for more info on how you can use them.
author: Tim Ducheyne author: Filip Neven |
Inner Class :protected class SpringTestListener extends TestListener | |
PROPKEY_APPLICATION_CONTEXT_FACTORY_CLASS_NAME | final public static String PROPKEY_APPLICATION_CONTEXT_FACTORY_CLASS_NAME(Code) | | |
assignSpringBeans | public void assignSpringBeans(Object testObject)(Code) | | Gets the spring beans for all fields that are annotated with
SpringBean .
Parameters: testObject - The test instance, not null |
assignSpringBeansByName | public void assignSpringBeansByName(Object testObject)(Code) | | Gets the spring beans for all fields that are annotated with
SpringBeanByName .
Parameters: testObject - The test instance, not null |
assignSpringBeansByType | public void assignSpringBeansByType(Object testObject)(Code) | | Gets the spring beans for all fields methods that are annotated with
SpringBeanByType .
Parameters: testObject - The test instance, not null |
getApplicationContext | public ApplicationContext getApplicationContext(Object testObject)(Code) | | Gets the application context for this test. A new one will be created if it does not exist yet. If a superclass
has also declared the creation of an application context, this one will be retrieved (or created if it was not
created yet) and used as parent context for this classes context.
If needed, an application context will be created using the settings of the
SpringApplicationContext annotation.
If a class level
SpringApplicationContext annotation is found, the passed locations will be loaded using
a ClassPathXmlApplicationContext .
Custom creation methods can be created by annotating them with
SpringApplicationContext . They
should have an ApplicationContext as return type and either no or exactly 1 argument of type
ApplicationContext . In the latter case, the current configured application context is passed as the argument.
A UnitilsException will be thrown if no context could be retrieved or created.
Parameters: testObject - The test instance, not null The application context, not null |
getBeanPostProcessor | public T getBeanPostProcessor(Object testObject, Class<T> beanPostProcessorType)(Code) | | < Parameters: T - > The bean post processor type Parameters: testObject - The test object Parameters: beanPostProcessorType - Type bean post processor type The bean post processor of the given type that is associated with the application context that isin turn associated with the given test object |
getSpringBean | public Object getSpringBean(Object testObject, String name)(Code) | | Gets the spring bean with the given name. The given test instance, by using
SpringApplicationContext ,
determines the application context in which to look for the bean.
A UnitilsException is thrown when the no bean could be found for the given name.
Parameters: testObject - The test instance, not null Parameters: name - The name, not null The bean, not null |
getSpringBeanByType | public Object getSpringBeanByType(Object testObject, Class> type)(Code) | | Gets the spring bean with the given type. The given test instance, by using
SpringApplicationContext ,
determines the application context in which to look for the bean.
If more there is not exactly 1 possible bean assignment, an UnitilsException will be thrown.
Parameters: testObject - The test instance, not null Parameters: type - The type, not null The bean, not null |
init | public void init(Properties configuration)(Code) | | Initializes this module using the given configuration
Parameters: configuration - The configuration, not null |
injectApplicationContext | public void injectApplicationContext(Object testObject)(Code) | | Gets the application context for this class and sets it on the fields and setter methods that are
annotated with
SpringApplicationContext . If no application context could be created, an
UnitilsException will be raised.
Parameters: testObject - The test instance, not null |
invalidateApplicationContext | public void invalidateApplicationContext(Class>... classes)(Code) | | 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 |
isApplicationContextConfiguredFor | public boolean isApplicationContextConfiguredFor(Object testObject)(Code) | | Parameters: testObject - The test object Whether an ApplicationContext has been configured for the given testObject |
registerBeanPostProcessorType | public void registerBeanPostProcessorType(Class<? extends BeanPostProcessor> beanPostProcessorType)(Code) | | Register a type of bean post processor. An instance of this bean post processor type will be used
when loading an application context
Parameters: beanPostProcessorType - |
|
|