register
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 anassert
operation. - Typically, a
source-file
property is used in theassert
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.
- The
- With the
register
operation, a file included in the ETLUnit project may be referenced by thesource-file
property of theassert
operation.- Such a file will be stored in the
/files
folder in the context of your etlunit test.
- Such a file will be stored in the
Attributes
List of register()
Attributes
- >> REF:
file: - >> TYPE: string - - REQUIRED
registered-name: - >> TYPE: string
producer: - >> TYPE: string
classifier: - >> TYPE: string
context: - >> TYPE: string
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.
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 thesource-file
property of theassert
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.
- You may register a file once in an
- You cannot register the same file twice in the same test run. It invokes duplicate file error
- Using
classifier
andcontext
- 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 acontext
property, ETLUnit will use the default classifier and context.- e.g., when the
assert
operation specifies neither thecontext
property nor theclassifier
property, it will use the implicit "default" context and classifier.
- e.g., when the
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>
Supporting Files Example
Simple register()
Example
@Test
simpleRegisterAndAssert()
{
register(
file: 'someFile'
);
assert(
source-file: 'someFile',
reference-file-type: 'test',
target: 'someDataFile'
);
}
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.
@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'
);
}
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.
@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'
);
}
Using @BeforeClass
for a common register
operation
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'
);
}
}