_@LogAssertion

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):

Attribute

Name

Possible ValuesInfo
assertion-mode

equals

matches

contains

contains-pattern

  • Applies to expected-log-expression.
  • Default is 'contains.'
log-name-pattern 

A regular expression. 

Represents part of the

log file name.

classifier 

To find its relevance:

  1. Run the report
  2. Click on the method name
  3. Logs are listed on a page
  4. Preceding log name is the classifier
failure-id 

May appear in CLI above the word "failed," if test fails.

expected-log-expression 

Mutually exclusive to expected-log-file.

A string expected to be found in the log.

expected-log-file 

Mutually exclusive to expected-log-expression.

Use of this attribute is not recommended.

Same possibilities

as the assert-log() operation.

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 assert-log() function.

Here is another view of the @LogAssertion attributes

 

- >> REF:

 @LogAssertion Common

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

expected-log:  - >>  TYPE:  Object (key-value pairs, comma separated)  

Either this, or 'expected-logs.' must be present
   

{

 

- >> REF:

 Assert-Log Common

 

 

 

 

 

 

 

 

 

 

assertion-mode:  - >>

POSSIBLE VALUES:

equals 

matches

contains-pattern

contains  << default 

log-name-pattern:  - >>  TYPE:  string

classifier:  - >>  TYPE:  string

failure-id:  - >>  TYPE:  string

expected-log-expression:  - >>  TYPE:  string

expected-log-file:  - >>  TYPE:  string 

 

}

expected-logs:  - >> TYPE:  Unique list of assert-log instances. 

Either this, or 'expected-log.' must be present
 

[

{

 

- >> REF:

 Assert-Log Common

 

 

 

 

 

 

 

 

 

 

assertion-mode:  - >>

POSSIBLE VALUES:

equals 

matches

contains-pattern

contains  << default 

log-name-pattern:  - >>  TYPE:  string

classifier:  - >>  TYPE:  string

failure-id:  - >>  TYPE:  string

expected-log-expression:  - >>  TYPE:  string

expected-log-file:  - >>  TYPE:  string 

 

},

{

...

}

]

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

 

expected-log with 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

 

expected-log with no assertion-mode specified. Defaults to 'contains.'

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

 

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)

 

assertion-mode 'equals' applies to entire contents of log file

@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).

 

fwq_qpt_data_format_tgt_1
#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.

 

expected-logs (multiple log assertions) example

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

 

The 'classifier' attribute

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

 

Display report after test run
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.