public class TestHelper extends Object
Like BatchLauncher
, it provides a "serverless" environment for executing EBX®
(the Java Virtual Machine does not require a running application server).
The main difference compared to BatchLauncher
, is that TestHelper
does not
execute tests on the repository that is specified by 'ebx.properties' file. Each test runs
on its own newly created repository.
In order to be used, the environment must conform to the following principles:
prepareEnvironment(File, File)
).ebx.properties
,
cannot be used (it is not initialized): a sandbox repository
must be used instead, it is provided by the method getNewRepository(File)
.ebx.properties
,
so that sessions can be authenticated through at least one
defined user (see DirectoryFactory
); a hard-coded
directory can be used.Here, a JUnit test class performs some updates on the EBX® repository and checks those updates:
In order to run such a test, it is necessary for the classpath to include:
Constructor and Description |
---|
TestHelper() |
Modifier and Type | Method and Description |
---|---|
static File |
createTemporaryDirectory(String aDirectoryPrefix)
Creates a new temporary directory.
|
static Repository |
getNewRepository(File aTargetDirectory)
Creates a new temporary repository for running tests with workflow API disabled.
|
static Repository |
getNewRepository(File aTargetDirectory,
boolean isWorkflowEnabled)
Creates a new temporary repository for running tests.
|
static Repository |
getRepositoryCopyOfExistingH2StandaloneDB(File aSourceDirectory,
File aTargetDirectory,
String aPrefix)
Creates a temporary copy of the specified existing repository for running
tests with workflow API disabled.
|
static Repository |
getRepositoryCopyOfExistingH2StandaloneDB(File aSourceDirectory,
File aTargetDirectory,
String aPrefix,
boolean isWorkflowEnabled)
Creates a temporary copy of the specified existing repository for running tests.
|
static Repository |
getRepositoryExistingH2StandaloneDB(File aSourceDirectory,
String aPrefix)
Gets an existing H2 repository to use for running tests with workflow API disabled.
|
static Repository |
getRepositoryExistingH2StandaloneDB(File aSourceDirectory,
String aPrefix,
boolean isWorkflowEnabled)
Gets an existing H2 repository to use for running tests.
|
static void |
prepareEnvironment(File modulesRootDir,
File propertiesFile)
Prepares the environment for the test.
|
static void |
shutdownRepository(boolean checkConnectionsHaveBeenClosed,
Repository aRepository)
Shuts down the specified repository.
|
static void |
shutdownRepository(Repository aRepository)
Shuts down the repository, and checks that all connections
to the database have been closed.
|
public static void prepareEnvironment(File modulesRootDir, File propertiesFile) throws Exception
getNewRepository(File)
.modulesRootDir
- indicates the root directory in which to look for EBX® modules to be
registered.
The search is recursively executed under the specified directory,
according to the following regexp: */webapps/*
.
This means that every required EBX® module, including the root module and the
manager module,
must be placed in a directory named webapps
.
Additionally, all modules must be expanded
(they must not remain packaged as WAR files).
Here is an example of a directory tree structure with two
modules (predefined ebx-root-1.0
, ebx-manager
and
specific module-sample
) and where modulesRootDir is the "Root" directory :
Root `-- test-project `-- webapps |-- ebx-root-1.0 | |-- META-INF | | `-- MANIFEST.MF | |-- WEB-INF | | |-- ebx | | | |-- ... | | | |-- module.xml | | | `-- ... | | |-- lib | | | `-- ebx-root-1.0.jar | | `-- web.xml | `-- www | `-- common | `-- ... |-- ebx-manager | `-- ... `-- module-sample `-- WEB-INF |-- ebx | |-- module.xml | `-- schema | `-- sample-many-simple-tables-100.xsd `-- web.xml
propertiesFile
- the path to the ebx.properties
file.Exception
public static File createTemporaryDirectory(String aDirectoryPrefix) throws Exception
The actual location of the directory to be created is:
${ebx.temp.directory}/ebx.platform.test/${aDirectoryPrefix}${index}/
Where the property ebx.temp.directory
is specified
in the ebx.properties
file, and index
is an increment
that ensures a new unique directory is used.
Exception
public static Repository getNewRepository(File aTargetDirectory)
This method is equivalent to:
TestHelper.getNewRepository(aTargetDirectory, false);
getNewRepository(File, boolean)
public static Repository getNewRepository(File aTargetDirectory, boolean isWorkflowEnabled)
Repository.getDefault()
.
The created repository will be based on a standalone H2 database. The database files will have the following physical location:
{aTargetDirectory}/h2/repository*
Warning:
aTargetDirectory
- location of the created H2 database. Tests will run on this database.isWorkflowEnabled
- must be true
to enable the workflow API. If false
workflow will be disabled and repository initialization will be faster.shutdownRepository(Repository)
public static Repository getRepositoryExistingH2StandaloneDB(File aSourceDirectory, String aPrefix)
This method is equivalent to:
TestHelper.getRepositoryExistingH2StandaloneDB(aSourceDirectory, aPrefix, false);
public static Repository getRepositoryExistingH2StandaloneDB(File aSourceDirectory, String aPrefix, boolean isWorkflowEnabled)
The H2 database files must exist at the following location:
{aSourceDirectory}/h2/repository*
Note: This will modify the existing database directly. To run
tests on a copy of an existing database, use
getRepositoryCopyOfExistingH2StandaloneDB(File, File, String)
.
aSourceDirectory
- location of the existing H2 database.isWorkflowEnabled
- must be true
to enable the workflow API. If false
workflow will be disabled and repository initialization will be faster.public static Repository getRepositoryCopyOfExistingH2StandaloneDB(File aSourceDirectory, File aTargetDirectory, String aPrefix)
This method is equivalent to:
TestHelper.getRepositoryCopyOfExistingH2StandaloneDB(aSourceDirectory, aTargetDirectory, aPrefix, false);
public static Repository getRepositoryCopyOfExistingH2StandaloneDB(File aSourceDirectory, File aTargetDirectory, String aPrefix, boolean isWorkflowEnabled)
aSourceDirectory
- location of the existing H2 database.aTargetDirectory
- location to copy the existing H2 database. Tests will run on this database.aPrefix
- prefix used in the provided source H2 database. Can be null
.isWorkflowEnabled
- must be true
to enable the workflow API. If false
workflow will be disabled and repository initialization will be faster.shutdownRepository(Repository)
public static void shutdownRepository(Repository aRepository)
This method is equivalent to:
TestHelper.shutdownRepository(true, aRepository);
shutdownRepository(boolean, Repository)
public static void shutdownRepository(boolean checkConnectionsHaveBeenClosed, Repository aRepository)
This method must be called for any test repository obtained using this class
(one of the methods getNewRepository(File)
,
getRepositoryCopyOfExistingH2StandaloneDB(File, File, String)
, or
getRepositoryExistingH2StandaloneDB(File, String)
).
checkConnectionsHaveBeenClosed
- if true
, verifies that all connections have been
properly closed; if not, an exception is thrown.aRepository
- the test repository to be shut down.IllegalStateException
- if checkConnectionsHaveBeenClosed
is set to true
and connections to the database have not been closed properly.RequestResult.close()