Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

Description

  • Basic configuration of databases to be used in a test class or a test method.

Attributes

Attribute

Name

Required?Type

Possible

Values

Info
idYesString 
  • Identifies which database is being used.
  • SEE the database-definitions JSON element of etlunit.json in src/main/resources/config or src/main/resources/config. depending on how you are set up.
modesNoList of Strings
  • lkp
  • src
  • tgt
  • <custom>
  • ETLUnit creates a separate database connection at runtime for each mode.
  • A table named 'foo' may exist in both the src and the tgt instance of the database, for instance.
  • The first mode in the list is the default mode.

Location in the test class file

  1. At file level, outside the class definition
  2. 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, use connection-id for the database, and mode to specify a globally available mode.

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'])


 

  • No labels