Class AcrossTestContextBuilder
- Direct Known Subclasses:
AcrossTestWebContextBuilder
AcrossTestContext
.
This builder allows easy configuration of properties and modules to add to an AcrossTestContext
.
Once build()
has been called, the AcrossTestContext
will be created and the internal
AcrossContext
bootstrapped.
- Since:
- 1.1.2
- Author:
- Arne Vandamme
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadditionalModulePackageClasses
(Class<?>... classes) Type-safe alternative foradditionalModulePackages(String...)
where the packages of the classes will be added for module scanning.additionalModulePackages
(String... packageNames) Additional packages that should be scanned for modules if no customModuleDependencyResolver
is configured.protected Class<?>[]
build()
Creates the internalAcrossContext
and bootstraps it.protected void
configureApplicationContext
(AcrossConfigurableApplicationContext applicationContext) configurer
(AcrossContextConfigurer... configurer) Add one or moreAcrossContextConfigurer
instances that are to be called after the initialAcrossContext
has been created.protected AcrossConfigurableApplicationContext
protected AcrossTestContext
createTestContext
(AcrossConfigurableApplicationContext applicationContext, AcrossContext context) dataSource
(DataSource dataSource) Set the core across datasource.developmentMode
(boolean developmentMode) dropFirst
(boolean dropFirst) Should the database be reset before bootstrapping theAcrossContext
.Add one or more types (classes, interfaces, annotations) that should be exposed in this test context.installerDataSource
(DataSource installerDataSource) Set the installer datasource.moduleConfigurationPackageClasses
(Class<?>... classes) Type-safe alternative formoduleConfigurationPackages(String...)
.moduleConfigurationPackages
(String... packageNames) Add one or more custom packages that should be scanned forModuleConfiguration
classes.moduleDependencyResolver
(ModuleDependencyResolver moduleDependencyResolver) Set theModuleDependencyResolver
that should be used for looking up modules by name.modules
(AcrossModule... modules) Array ofAcrossModule
instances to add to the context.Array ofAcrossModule
names that should be configured.properties
(Map<String, Object> properties) Add a properties map to the environment of the parentApplicationContext
.properties
(Properties properties) Add a properties collection to the environment of the parentApplicationContext
.properties
(org.springframework.core.env.PropertySource propertySource) Add aPropertySource
to the environment of the parentApplicationContext
.Set a property value on the environment of the parentApplicationContext
.Add one or more annotated classes to the parentApplicationContext
that is attached to theAcrossContext
.useTestDataSource
(boolean useTestDataSource) Should default test datasources be created.
-
Constructor Details
-
AcrossTestContextBuilder
public AcrossTestContextBuilder()
-
-
Method Details
-
dropFirst
Should the database be reset before bootstrapping theAcrossContext
. Whentrue
, this adds theResetDatabaseConfigurer
to the parentApplicationContext
. This is the default case.- Parameters:
dropFirst
- true if datasource tables should be dropped before starting the context- Returns:
- self
- See Also:
-
useTestDataSource
Should default test datasources be created. This will use the datasource specified by the property acrossTest.datasource or create a memory HSQLDB if none is specified.Using test datasource is the default. This is the equivalent to adding
TestDataSourceConfigurer
the the parentApplicationContext
.- Parameters:
useTestDataSource
- true if test datasource should be created automatically- Returns:
- self
- See Also:
-
register
Add one or more annotated classes to the parentApplicationContext
that is attached to theAcrossContext
.- Parameters:
annotatedClasses
- list- Returns:
- self
-
expose
Add one or more types (classes, interfaces, annotations) that should be exposed in this test context.- Parameters:
classesToExpose
- list- Returns:
- self
-
dataSource
Set the core across datasource. If no separateinstallerDataSource(DataSource)
is configured, this datasource will also be used for installers. If neither datasource is configured, installers will be disabled.- Parameters:
dataSource
- instance- Returns:
- self
-
installerDataSource
Set the installer datasource.- Parameters:
installerDataSource
- instance- Returns:
- self
-
modules
Array ofAcrossModule
names that should be configured. These will be resolved using the configuredmoduleDependencyResolver(ModuleDependencyResolver)
, before any configured module instances and before theAcrossContextConfigurer
instances are called. If noModuleDependencyResolver
was set explicitly, the default will be used.Subsequent calls will add modules.
- Parameters:
moduleNames
- names- Returns:
- self
-
modules
Array ofAcrossModule
instances to add to the context. These will be added after the modules added usingmodules(String...)
have been resolved. Subsequent calls will add modules.- Parameters:
modules
- collection- Returns:
- self
-
moduleDependencyResolver
public AcrossTestContextBuilder moduleDependencyResolver(ModuleDependencyResolver moduleDependencyResolver) Set theModuleDependencyResolver
that should be used for looking up modules by name. If none is set, a defaultClassPathScanningModuleDependencyResolver
will be used.- Parameters:
moduleDependencyResolver
- instance- Returns:
- self
- See Also:
-
additionalModulePackages
Additional packages that should be scanned for modules if no customModuleDependencyResolver
is configured. In case of a custom resolver, this setting will be ignored.The default
AcrossContextBuilder.STANDARD_MODULES_PACKAGE
will always be added as the first one. If you do not want this, you should set a customModuleDependencyResolver
usingmoduleDependencyResolver(ModuleDependencyResolver)
.Subsequent calls will add additional packages.
- Parameters:
packageNames
- list- Returns:
- self
- See Also:
-
additionalModulePackageClasses
Type-safe alternative foradditionalModulePackages(String...)
where the packages of the classes will be added for module scanning. In case of a custom resolver, this setting will be ignored.The default
AcrossContextBuilder.STANDARD_MODULES_PACKAGE
will always be added as the first one. If you do not want this, you should set a customModuleDependencyResolver
usingmoduleDependencyResolver(ModuleDependencyResolver)
.Subsequent calls will add additional packages.
- Parameters:
classes
- list- Returns:
- self
-
moduleConfigurationPackages
Add one or more custom packages that should be scanned forModuleConfiguration
classes. Subsequent calls will add additional packages.- Parameters:
packageNames
- list- Returns:
- self
-
moduleConfigurationPackageClasses
Type-safe alternative formoduleConfigurationPackages(String...)
.- Parameters:
classes
- list- Returns:
- self
-
developmentMode
- Parameters:
developmentMode
- true if development mode should be active on the created context- Returns:
- self
-
configurer
Add one or moreAcrossContextConfigurer
instances that are to be called after the initialAcrossContext
has been created. Subsequent calls will add additional configurers.- Parameters:
configurer
- one or more instances- Returns:
- self
-
property
Set a property value on the environment of the parentApplicationContext
.- Parameters:
key
- property keyvalue
- property value- Returns:
- self
-
properties
Add a properties collection to the environment of the parentApplicationContext
.- Parameters:
properties
- instance- Returns:
- self
-
properties
Add a properties map to the environment of the parentApplicationContext
.- Parameters:
properties
- map- Returns:
- self
-
properties
public AcrossTestContextBuilder properties(org.springframework.core.env.PropertySource propertySource) Add aPropertySource
to the environment of the parentApplicationContext
.- Parameters:
propertySource
- instance- Returns:
- self
-
build
Creates the internalAcrossContext
and bootstraps it. Then wraps it in aAcrossTestContext
instance that gives easy access to querying functionality.- Returns:
- queryable context containing the bootstrapped
AcrossContext
-
createTestContext
protected AcrossTestContext createTestContext(AcrossConfigurableApplicationContext applicationContext, AcrossContext context) -
createDefaultApplicationContext
-
configureApplicationContext
-
annotatedClasses
-