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
Constructors -
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 customModuleDependencyResolveris configured.protected Class<?>[]build()Creates the internalAcrossContextand bootstraps it.protected voidconfigureApplicationContext(AcrossConfigurableApplicationContext applicationContext) configurer(AcrossContextConfigurer... configurer) Add one or moreAcrossContextConfigurerinstances that are to be called after the initialAcrossContexthas been created.protected AcrossConfigurableApplicationContextprotected AcrossTestContextcreateTestContext(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 forModuleConfigurationclasses.moduleDependencyResolver(ModuleDependencyResolver moduleDependencyResolver) Set theModuleDependencyResolverthat should be used for looking up modules by name.modules(AcrossModule... modules) Array ofAcrossModuleinstances to add to the context.Array ofAcrossModulenames 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 aPropertySourceto the environment of the parentApplicationContext.Set a property value on the environment of the parentApplicationContext.Add one or more annotated classes to the parentApplicationContextthat 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 theResetDatabaseConfigurerto 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
TestDataSourceConfigurerthe 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 parentApplicationContextthat 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 ofAcrossModulenames that should be configured. These will be resolved using the configuredmoduleDependencyResolver(ModuleDependencyResolver), before any configured module instances and before theAcrossContextConfigurerinstances are called. If noModuleDependencyResolverwas set explicitly, the default will be used.Subsequent calls will add modules.
- Parameters:
moduleNames- names- Returns:
- self
-
modules
Array ofAcrossModuleinstances 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 theModuleDependencyResolverthat should be used for looking up modules by name. If none is set, a defaultClassPathScanningModuleDependencyResolverwill be used.- Parameters:
moduleDependencyResolver- instance- Returns:
- self
- See Also:
-
additionalModulePackages
Additional packages that should be scanned for modules if no customModuleDependencyResolveris configured. In case of a custom resolver, this setting will be ignored.The default
AcrossContextBuilder.STANDARD_MODULES_PACKAGEwill always be added as the first one. If you do not want this, you should set a customModuleDependencyResolverusingmoduleDependencyResolver(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_PACKAGEwill always be added as the first one. If you do not want this, you should set a customModuleDependencyResolverusingmoduleDependencyResolver(ModuleDependencyResolver).Subsequent calls will add additional packages.
- Parameters:
classes- list- Returns:
- self
-
moduleConfigurationPackages
Add one or more custom packages that should be scanned forModuleConfigurationclasses. 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 moreAcrossContextConfigurerinstances that are to be called after the initialAcrossContexthas 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 aPropertySourceto the environment of the parentApplicationContext.- Parameters:
propertySource- instance- Returns:
- self
-
build
Creates the internalAcrossContextand bootstraps it. Then wraps it in aAcrossTestContextinstance 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
-