@Database
ETLUnit 3.9.6
Â
Description
- Basic configuration of databases to be used in a test class or a test method.
Attributes
Attribute Name | Required? | Type | Possible Values | Info |
---|---|---|---|---|
id | Yes | String |
| |
modes | No | List of Strings |
|
|
Location in the test class file
- At file level, outside the class definition
- Before an individual test method. Available to that test method.
Scopes
Global Scope
- When specified above the class declaration, the database (and its modes) is available to every method that does not have its own
@Database
annotation pointing to different database(s). - If the method has its own
@Database
annotation pointing to a different database, the global database can still be accessed, with further configuration:- In the stage operation, use
connections.
Include any available global modes you want to use. - In the
assert
operation, useconnection-id
for the database, andmode
to specify a globally available mode.
- In the stage operation, use
A good example is found in the database-samples
module of etlunit-samples
, on Bitbucket.
stage_with_modes.etlunit
@Description( description: [ 'Each database mode is a separate real database. Data can be staged into', 'each database independently, or to multiple at once.' ] ) @Database(id: 'edw', modes: ['lkp', 'tgt']) class stage_with_modes { @Description( description: [ 'Stages the data to a single database mode' ] ) @Test stageToSingleMode(){ stage( source: 'DATA_FILE', target-table: 'TEST_TABLE', mode: 'lkp' ); assert(source-table: 'TEST_TABLE', target: 'DATA_FILE', mode: 'lkp'); // because we staged to the lkp mode, the tgt mode is still empty assert(assertion-mode: 'empty', source-table: 'TEST_TABLE', mode: 'tgt'); } @Description( description: [ 'Stages the data to multiple database modes at once' ] ) @Test stageToMultipleModes(){ stage( source: 'DATA_FILE', target-table: 'TEST_TABLE', modes: ['lkp', 'tgt'] ); // because we staged to both modes, both databases contain the data assert(source-table: 'TEST_TABLE', target: 'DATA_FILE', mode: 'tgt'); assert(source-table: 'TEST_TABLE', target: 'DATA_FILE', mode: 'lkp'); } @Database(id: 'edw-ii', modes: ['src']) @Description( description: [ 'Stages the data to multiple database connections at once', 'These dont have to be related at all except that they contain the same table.', 'Additionally, the Database tag on this test prepares a database that is available', 'for this test only.' ] ) @Test stageToMultipleConnections(){ stage( source: 'DATA_FILE', target-table: 'TEST_TABLE', connections: { edw: { modes: ['lkp', 'tgt'] }, edw-ii: { mode: 'src' } } ); // because we staged to both modes, both databases contain the data assert(source-table: 'TEST_TABLE', target: 'DATA_FILE', connection-id: 'edw', mode: 'tgt'); assert(source-table: 'TEST_TABLE', target: 'DATA_FILE', connection-id: 'edw', mode: 'lkp'); // we also posted it here assert(source-table: 'TEST_TABLE', target: 'DATA_FILE', connection-id: 'edw-ii', mode: 'src'); } }
Local Scope
- When specified above a method declaration, a database is available only inside that method.
Examples
@Database
@Database(id: 'informatica-control') // Defaults to mode 'src'
@Database(id: 'pos-alx-mart', modes: ['src','tgt','lkp'])
@Database(id: 'edw', modes: ['src'])
@Database(id: 'pos_ods', modes: ['src','lkp'])