_@OperationDefault
Description
- Provide a default for an operation's property, to be applied to all operations within scope of the annotation's placement. @OperationDefault provides a single place to put property values that may otherwise be repeated several times in the ETLUnit test.
- Possible scopes for this annotation:
- File level (outside a test class declaration).
- Class level (inside a test class; outside any test methods).
- This might be called "method scope"
- It applies only to the method following the annotation
- If another method appears beneath this one, and both methods are being executed with the same 'test' command, the method scope @OperationDefault will not apply to the second method.
@OperationDefault
does not work with data set properties for the stage operation.
Â
Attributes
Attribute Name | Required? | Possible Values | Info |
---|---|---|---|
operation | Yes |
|
|
defaultValue | Yes |
|
|
matchWhen | No |
|
|
doNotMatchWhen | No |
|
|
Location in the test class file
- At the file level (annotates the following test class(es)).
- At the class level (annotates the following test methods).
Examples
Simple examples from etlunit-samples
The following example was shamelessly copied from project etlunit-samples, downloadable from the Bradley Smith LLC Bitbucket account.
Â
// Declared 'edw' connection first - so it is default
@Database(id: 'edw', modes: ['c', 'd'])
Â
// 'a' mode is the default since it was declared first
@Database(id: 'edw-ii', modes: ['a', 'b', 'c', 'd'])
Â
/*
provide an operation default that applies to the entire class.
Make all stage operations connect to edw-ii by default
*/
@OperationDefault
(
operation: 'stage',
defaultValue:
{
connection-id: 'edw-ii',
mode: 'b'
}
)
class stage_operation_default {
@Description(
description: [
'this data goes to edw-ii.b connection because of the operation defaults.',
'To verify, the assert has to have the connection id and the mode specified.',
'You can also look into the log where the stage appears. You will see the defaulted attributes present.',
"Look for this text: Searching for handler for operation: 'stage'"
]
)
@Test
stageToOperationalDefaultMode()
{
stage(
source: 'DATA_FILE',
target-table: 'TEST_TABLE'
);
Â
assert(
source-table: 'TEST_TABLE',
target: 'DATA_FILE',
connection-id: 'edw-ii',
mode: 'b'
);
}
Â
@Description(
description: [
'Here a local operation default overrides just one component (mode) of the class defaults.'
]
)
@OperationDefault
(
operation: 'stage',
defaultValue:
{
mode: 'c'
}
)
@Test
stageWithLocalOD()
{
stage(
source: 'DATA_FILE',
target-table: 'TEST_TABLE'
);
Â
assert(
source-table: 'TEST_TABLE',
target: 'DATA_FILE',
connection-id: 'edw-ii',
mode: 'c'
);
}
Â
@Description(
description: [
'In this example class and local defaults are applied, and some overridden by the operation.'
]
)
@OperationDefault
(
operation: 'stage',
defaultValue:
{
mode: 'd'
}
)
@Test
stageWithOverridesAndOD()
{
stage(
source: 'DATA_FILE',
target-table: 'TEST_TABLE',
connection-id: 'edw'
);
Â
assert(
source-table: 'TEST_TABLE',
target: 'DATA_FILE',
connection-id: 'edw',
mode: 'd'
);
}
}
Â
Example - assert()
and execute()
operations are overridden
@OperationDefault(
operation: 'assert',
defaultValue: {
source-file: 'PLANT_DAILY_ICNT.txt',
source-reference-file-type: 'FF_PLANT_DAILY_ICNT'
}
)
@OperationDefault(
operation: 'execute',
defaultValue: {
folder: 'EDW_EXTRACTS',
workflow: 'wkf_PLANT_DAILY_ICNT_EXTRACT'
}
)
class plant_daily_icnt {
Â
@Database(id: 'edw')
@Test
extractFromEdw(){
stage(
data-set-name: 'extract_data',
data-set-id: 'ITEM_EDW_TBL'
);
Â
set (variable: 'schema', value: 'DBO');
Â
stage(
data-set-name: 'extract_data',
data-set-id: 'PLANT_DAILY_ITEM_EDW_TBL'
);
Â
execute(
context:
{
plant-connection-src: 'informatica.connections.edw.default'
}
);
Â
assert(
data-set-name: 'extract_data',
data-set-id: 'PLANT_DAILY_ICNT'
);
}
Â
@Database(id: 'edw')
@Test
extractEmptyEDW(){
set (variable: 'schema', value: 'dbo');
execute(
context:
{
plant-connection-src: 'informatica.connections.edw.default'
}
);
Â
assert(
assertion-mode: 'empty'
);
}
Â
Â
@Database(id: 'qpt-bmw-mart')
@Test
extractEmptyBMW(){
set (variable: 'schema', value: 'AGG');
execute(
context:
{
plant-connection-src: 'informatica.connections.qpt-bmw-plant.default'
}
);
Â
assert(
assertion-mode: 'empty'
);
}
  Â
@Database(id: 'qpt-bmw-plant')
@Test
extractFromBmwPlant(){
stage(
data-set-name: 'extract_data',
data-set-id: 'ITEM_EDW_TBL'
);
     Â
set (variable: 'schema', value: 'AGG');
Â
stage(
data-set-name: 'extract_data',
data-set-id: 'PLANT_DAILY_ITEM_EDW_TBL',
target-schema:'AGG'
);
Â
execute(
context:
{
plant-connection-src: 'informatica.connections.qpt-bmw-plant.default'
}
);
Â
assert(
data-set-name: 'extract_data',
data-set-id: 'PLANT_DAILY_ITEM'
);
}
}
Â