@LogAssertion
Draft in Progress
This document is a draft and is under development.
Description
- Make an assertion regarding a log file name and its contents.
Attributes
Attribute Name | Required? | Possible Values | Info | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
expected-log | Either this or expected-logs must be present. | A JSON object (key-value pairs):
| Same possibilities as the | |||||||||||||||||||||
expected-logs | Either this or expected-log must be present. | A list of JSON objects. Each object matches the list above. | Each object in the list has the same possibilities as the |
Here is another view of the @LogAssertion
attributes
- >> REF:
Individual @LogAssertion
attributes
TODO: Fix these links:
SEE the Individual assert-log() Attributes section of the assert-log page, since these form the core of the @LogAssertion
annotation.
Location in the test class file
Before a test method.
Rules and Recommendations
Assertion-mode
- Default assertion-mode is '
contains
.' assertion-mode
applies to the contents of the log file (expected-log-expression
), not to the log name (log-name-pattern
).
Examples
@LogAssertion expected-log
, using a regex-like log-name-pattern
@Test(expected-error-id: 'ERR_EXECUTE_WORKFLOW')
@LogAssertion(
expected-log: {
assertion-mode: 'contains',
classifier: 'sessionLog',
expected-log-expression: 'Field Widths less than or equal to 0 not supported',
log-name-pattern: '.log([0-9]+)?'
}
)
lineLengthNegative() {
set(variable: 'inputgrouptest', value: '1');
stage(
file: 'fyq_qpt_data_format_NegativeFieldWidth.txt',
destination-name: 'fwq_qpt_data_format_src.txt'
);
execute(
workflow: 'wkf_TEST_FORMAT_QPT_DATA_FYQ',
folder: 'SHARED_QPT_PET'
);
}
@LogAssertion expected-log
with no assertion-mode
specified
@Test(expected-error-id: 'ERR_EXECUTE_WORKFLOW')
@LogAssertion(
expected-log: {
classifier: 'targetFiles',
expected-log-expression: 'FIELD_WIDTH',
log-name-pattern: 'fwq_qpt_data_format_tgt_1'
}
)
lineLengthNegative() {
set(variable: 'inputgrouptest', value: '1');
stage(
file: 'fwq_qpt_data_format_NegativeFieldWidth.txt',
destination-name: 'fwq_qpt_data_format_src.txt'
);
execute(
workflow: 'wkf_TEST_FORMAT_QPT_DATA_EXP',
folder: 'SHARED_QPT_PET'
);
}
@LogAssertion expected-log
with assertion-mode
'contains-pattern
'
@Test(expected-error-id: 'ERR_EXECUTE_WORKFLOW')
@LogAssertion(
expected-log: {
assertion-mode: 'contains-pattern',
classifier: 'targetFiles',
expected-log-expression: '#FIELD_WIDTH|INT_INPUT|SIGNED_INT_INPUT|SMALLINT_INPUT',
log-name-pattern: 'fwq_qpt_data_format_tgt_1'
}
)
lineLengthNegative() {
set(variable: 'inputgrouptest', value: '1');
stage(
file: 'fwq_qpt_data_format_NegativeFieldWidth.txt',
destination-name: 'fwq_qpt_data_format_src.txt'
);
execute(
workflow: 'wkf_TEST_FORMAT_QPT_DATA_FWQ',
folder: 'SHARED_QPT_PET'
);
}
@LogAssertion expected-log
with assertion-mode
'equals
' (rare)
@LogAssertion(
expected-log: {
assertion-mode: 'equals',
classifier: 'targetFiles',
expected-log-expression: '#FIELD_WIDTH|INT_INPUT|SIGNED_INT_INPUT|SMALLINT_INPUT|NUMERIC_INPUT|INT_OUTPUT\n',
log-name-pattern: 'fwq_qpt_data_format_tgt_1'
}
)
For assertion-mode
'equals,' the expected-log-expression
reports the entire contents of the log file. An edge case, to be sure. (Above and below).
#FIELD_WIDTH|INT_INPUT|SIGNED_INT_INPUT|SMALLINT_INPUT|NUMERIC_INPUT|INT_OUTPUT
@LogAssertion expected-logs
. You can assert against multiple logs in the same test.
@Test
@LogAssertion(
expected-logs:
[
{
assertion-mode: 'matches',
expected-log-expression: 'Hi1\n',
log-name-pattern: 'file1$'
},
{
assertion-mode: 'matches',
expected-log-expression: 'Hi2\n',
log-name-pattern: 'file1.file2$'
},
{
assertion-mode: 'matches',
expected-log-expression: 'Hi3\n',
log-name-pattern: 'file1.file2.file3$'
}
]
)
assertFindLogByNameBegin()
{
log(
message: 'Hi1\n',
log-file-name: 'assertFindLogByNameBegin.file1',
log-classifier: 'standard-out'
);
log(
message: 'Hi2\n',
log-file-name: 'assertFindLogByNameBegin.file1.file2',
log-classifier: 'standard-out'
);
log(
message: 'Hi3\n',
log-file-name: 'assertFindLogByNameBegin.file1.file2.file3',
log-classifier: 'standard-out'
);
}
Where to Find Classifier for Log Assertions
- You can find the classifiers available to you based on the test you are writing.
@LogAssertion(
expected-log: {
assertion-mode: 'contains',
classifier: 'sessionLog',
expected-log-expression: 'Field Widths less than or equal to 0 not supported',
log-name-pattern: '.log([0-9]+)?'
}
)
- When you run the test, obtain a report.
userme > report
- In the web page that opens, click on the name of the test method and you will see a list of the logs generated during the test run.
- The available classifiers appear on this page just before the log file name.
Configuration
- Include feature
log-assertion
inetlunit.json
or in the appropriate profile. - Include dependency
etlunit-log-assertion
in your POM.
{
"install-features": ["other_feature", "log-assertion"],
"features": {}
}
<dependencies>
<dependency>
<groupId>org.bitbucket.bradleysmithllc.etlunit</groupId>
<artifactId>etlunit-log-assertion</artifactId>
<version>${etlunit.project.version}</version>
</dependency>
</dependencies>