register

ETLUnit 3.9.6

 

Draft in Progress

This document is a draft and is under development.

 

Description

  • Register a file included in your project so that ETLUnit may use it as a source-file in an assert operation.
  • Typically, a source-file property is used in the assert operation after running an Informatica workflow, for example.
    • The source-file property refers to a file dynamically generated deep in the /target folder structure by the Informatica workflow itself. 
    • The user may not control where that file is placed.
  • With the register operation, a file included in the ETLUnit project may be referenced by the source-file property of the assert operation.
    • Such a file will be stored in the /files folder in the context of your etlunit test.

Attributes

List of register() Attributes

 

 

 

 

 

 

- >> REF:

 File Feature Module - Configuration

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

reference-file-types:  - >> TYPE:  object (key-value pairs)

{

<reference-file-type-name>:  - >> TYPE:  string

{

default-version:  - >> TYPE:  string

default-remote-version:  - >> TYPE:  string

default-classifier:  - >> TYPE:  string

default-remote-classifier:  - >> TYPE:  string

classifiers:  - >> TYPE:  object (key-value pairs)

{

<classifier-name>:  - >> TYPE:  string

{

default-version:  - >> TYPE:  string

default-remote-version:  - >> TYPE:  string

}, ... multiple classifiers possible

}

}, ... multiple reference file types possible

} 


 

file:  - >> TYPE:  string  - - REQUIRED

registered-name:  - >> TYPE:  string

producer:  - >> TYPE:  string

classifier:  - >> TYPE:  string

context:  - >> TYPE:  string

 


 

Go to top

Individual register() Attributes

[File Feature Module - Configuration properties not listed here.]

file:

  • Name of the file to register.
  • Should reside in the files/ folder, a sibling of the test class.
  • Include the file name extension, if any.  E.g., test_file.txt would be registered with the attribute file: 'test_file.txt'

registered-name:

  • Use this attribute if you want to register under a different name.
  • This registered name will be used instead of the file name for any assert operation.

producer:

classifier:

  • This classifier, if present, must match the one used in the assert operation.

context:

  • This context, if present, must match the one used in the assert operation.

Go to top

Rules

  • The register operation makes ETLUnit aware of a file, which you have included in the project structure under the /files folder, in such a way that its name can be supplied to the source-file property of the assert operation.
  • In the past, source-file could only be used to refer to a file produced by running an Informatica workflow.
  • The file you register does not have to exist yet when you register it.
    • You won't be able to assert against it until it does exist.
  • Duplicate File Errors
    • You cannot register the same file twice in the same test run.  It invokes duplicate file error ERR_REGISTER_FILE_NAME_DUPLICATED.
    • If you have multiple tests that register the same file, and they run from a single 'test' command, there will be a duplicate file error.

    • For example, if you register the same file in tests in two different classes, and you run both test classes with one 'test' CLI command, you will get a duplicate error.
    • If you register the same file in the @BeforeClass method in two different classes, and you run both test classes with a single 'test' CLI command, you will get a duplicate error.
    • Some ways to prevent duplicate registration
      • You may register a file once in an @BeforeClass method, if you need it registered for multiple tests in one class.
      • You may use a different registered-name property to prevent a duplicate error when registering the same file twice.  SEE list of attributes, above.
      • You may use the context property to prevent a duplicate error.  SEE list of attributes, above.
      • You may use the classifier property to prevent a duplicate error.  SEE list of attributes, above.
  • Using classifier and context
    • The file registered must be asserted against using the same classifier and context with which it was registered.
    • If you specify neither a classifier nor a context property, ETLUnit will use the default classifier and context.
      • e.g., when the assert operation specifies neither the context property nor the classifier property, it will use the implicit "default" context and classifier.

Go to top

Examples

Prerequisites

  • etlunit-core dependency.
  • etlunit-file dependency.
    • This dependency may be a secondary dependency, not explicitly declared in the POM. 
    • Below is what it will look like if you do include the dependency in the POM.

 

<dependencies>
	<dependency>
		<groupId>org.bitbucket.bradleysmithllc.etlunit</groupId>
		<artifactId>etlunit-core</artifactId>
		<version>${etlunit.project.version}</version>
	</dependency>
    <dependency>
        <groupId>org.bitbucket.bradleysmithllc.etlunit</groupId>
        <artifactId>etlunit-file</artifactId>
        <version>${etlunit.project.version}</version>
    </dependency> 
 </dependencies>

 

Go to top

Supporting Files Example

 

Go to top

Simple register() Example

 

Simple register example

@Test

simpleRegisterAndAssert()

{

register(

file: 'someFile'

);

 

assert(

source-file: 'someFile',

reference-file-type: 'test',

target: 'someDataFile'

);

}

 

Go to top

Four register operations in single test

These four register operations all register the same file, yet there is no duplicate registration error.  This is because they are differentiated by classifier and context.

 

Four register operations on the same file do not clash

@Test

classifiersAndContextsDontDuplicate()

{

// default classifier and context

register(

file: 'classifiersAndContextsDontDuplicate'

);

 

// default classifier

register(

file: 'classifiersAndContextsDontDuplicate',

context: 'con'

);

 

// default context

register(

file: 'classifiersAndContextsDontDuplicate',

classifier: 'cla'

);

 

// neither default

register(

file: 'classifiersAndContextsDontDuplicate',

classifier: 'cla2',

context: 'con2'

);

}

 

Go to top

Using Runtime Name

You can register a runtime name for the registered file and assert against that name, instead of the name of the file.

 

Register and use a runtime name

@Test

assertAgainstRegisteredDuplicateFileByUsingRuntimeName()

{

register(

file: 'oneFileTwoAsserts',

registered-name: 'oneFileTwoAsserts1'

);

 

register(

file: 'oneFileTwoAsserts',

registered-name: 'oneFileTwoAsserts2'

);

 

assert(

source-file: 'oneFileTwoAsserts1',

reference-file-type: 'test',

target: 'register'

);

 

assert(

source-file: 'oneFileTwoAsserts2',

reference-file-type: 'test',

target: 'register'

);

}

 

Go to top

Using @BeforeClass for a common register operation

 

Let one register operation serve all tests in a test class

class file_register

{

@BeforeClass

beforeClass()

{

register(

file: 'register',

registered-name: 'runtime'

);

}

 

@Test

registerAssertWithDatasetName()

{

assert(

source-file: 'runtime',

reference-file-type: 'test',

data-set-name: 'ds1'

);

}

 

@Test

registerAssertWithDatasetNameAndId()

{

assert(

source-file: 'runtime',

reference-file-type: 'test',

data-set-name: 'ds2',

data-set-id: 'ds_id2'

);

}

}

 

Go to top