public class SpringModule extends Object implements Module
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. invalidateApplicationContext(java.lang.Class<?>...) }
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.| Modifier and Type | Class and Description |
|---|---|
protected class |
SpringModule.SpringTestListener
The
TestListener for this module |
| Modifier and Type | Field and Description |
|---|---|
static String |
PROPKEY_APPLICATION_CONTEXT_FACTORY_CLASS_NAME |
| Constructor and Description |
|---|
SpringModule() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterInit()
No after initialization needed for this module
|
protected void |
closeApplicationContextIfNeeded(Object testObject) |
LoadTime |
findLoadTime(Class<?> clzz) |
org.springframework.context.ApplicationContext |
getApplicationContext(Object testObject)
Gets the application context for this test.
|
protected DatabaseModule |
getDatabaseModule() |
Object |
getSpringBean(Object testObject,
String name)
Gets the spring bean with the given name.
|
<T> T |
getSpringBeanByType(Object testObject,
Class<T> type)
Gets the spring bean with the given type.
|
TestListener |
getTestListener() |
void |
init(Properties configuration)
Initializes this module using the given configuration
|
void |
initialize(Object testObject) |
void |
injectApplicationContext(Object testObject)
Gets the application context for this class and sets it on the fields and setter methods that are
annotated with
SpringApplicationContext. |
void |
injectSpringBeans(Object testObject)
Injects spring beans into all fields that are annotated with
SpringBean. |
void |
injectSpringBeansByName(Object testObject)
Injects spring beans into all fields that are annotated with
SpringBeanByName. |
void |
injectSpringBeansByType(Object testObject)
Injects spring beans into all fields methods that are annotated with
SpringBeanByType. |
void |
invalidateApplicationContext(Class<?>... classes)
Forces the reloading of the application context the next time that it is requested.
|
boolean |
isApplicationContextConfiguredFor(Object testObject) |
protected boolean |
isDatabaseModuleEnabled() |
public static final String PROPKEY_APPLICATION_CONTEXT_FACTORY_CLASS_NAME
public void init(Properties configuration)
public void afterInit()
public Object getSpringBean(Object testObject, String name)
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.testObject - The test instance, not nullname - The name, not nullpublic <T> T getSpringBeanByType(Object testObject, Class<T> type)
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.testObject - The test instance, not nulltype - The type, not nullpublic boolean isApplicationContextConfiguredFor(Object testObject)
testObject - The test objectpublic org.springframework.context.ApplicationContext getApplicationContext(Object testObject)
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.testObject - The test instance, not nullpublic void invalidateApplicationContext(Class<?>... classes)
classes - The classes for which to reset the contextspublic void injectApplicationContext(Object testObject)
SpringApplicationContext. If no application context could be created, an
UnitilsException will be raised.testObject - The test instance, not nullpublic void injectSpringBeans(Object testObject)
SpringBean.testObject - The test instance, not nullpublic void injectSpringBeansByType(Object testObject)
SpringBeanByType.testObject - The test instance, not nullpublic void injectSpringBeansByName(Object testObject)
SpringBeanByName.testObject - The test instance, not nullprotected void closeApplicationContextIfNeeded(Object testObject)
protected boolean isDatabaseModuleEnabled()
protected DatabaseModule getDatabaseModule()
public void initialize(Object testObject)
public TestListener getTestListener()
getTestListener in interface ModuleTestListener for this moduleCopyright © 2016. All Rights Reserved.