@OperationDefault

ETLUnit 3.9.6

 

Draft in Progress

This document is a draft and is under development.

 

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
operationYes
  • A string.
  • Name of the operation being overridden.
defaultValueYes
  • An "object" (list of key-value pairs delimited with curly braces)
  • Each item in the list is the name of a property and its default value
matchWhenNo
  • A list of strings
  • Each item in the list is the name of a property that should resolve to true to invoke the operation default.
doNotMatchWhenNo
  • A list of strings
  • Each item in the list is the name of a property that should resolve to false to invoke the operation default.

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.

 

Example copied from etlunit-samples project

// 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

 
Example of @OperationDefault

@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'

);

}

}