assert-log

ETLUnit 3.9.6

 

Draft in Progress

This document is a draft and is under development.

 

Description

  • Asserts that a log file contains or matches some text.

Attributes

List of assert-log() operation attributes

 

 

 

 

 

 

 

 

 

 

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 

 

Go to top

Individual assert-log() Attributes

assertion-mode:

How do you want to compare your specified log text with actual log contents?

equals

The entire contents of the log file must be the same, byte-for-byte, as your assertion data (either the excerpt found in the .expr log file, named in the expected-log-file property and found in the log/ folder, or the value assigned to the expected-log-expression attribute).

matches

The value assigned to the expected-log-expression attribute is a regular expression that must match the entire contents of the log file.

contains-pattern

The value assigned to the expected-log-expression attribute is a regular expression matching a subset of the file contents.  Similar to a Ctl-F "find" operation using your keyboard.

contains

Default assertion-mode.  If you do not specify an assertion-mode, contains will be used.

Use a literal value for a search of the log file. 

Refers to the value assigned to expected-log-expression, or the text found in the file referred to by expected-log-file.

Go to top

log-name-pattern:

Specify a log name without spelling it out

  • The pattern should be in the form of a regular expression.
  • Enclose the pattern in single quotes.
  • The pattern should be similar to what would be expected by Java's regex interpreter.  For rules, SEE the API doc for Pattern (Java Platform SE7).
  • Leading characters in the log file's name do not have to be accounted for in the pattern.  A log file that contains the log-name-pattern expression will be searched for.

log-name-pattern attribute example

 

Examples of log-name-pattern

/* The log file name ends either in '.log,' or in '.log'

   followed by one or more digits: */

log-name-pattern: '.log([0-9]+)?'

 

/* The log file name ends in 'file1.' 

   The dollar sign ('$') at the end enforces that the specified

   string represents the end of the log file name: */

log-name-pattern: 'file1$'

 

/* Notice the double backslashes. A backslash is the escape symbol.

  The character immediately following it is used literally, whereas it would normally

  be used by the regular expression interpreter as a control symbol: */

log-name-pattern: 'log\\.1234567890\\.\\d{0,10}\\.\\d{14}$'

 

Go to top

classifier:

  • Limit the log file type (found on the Method Summary report page) to one that you specify.

For example, when executing an Informatica workflow in your ETLUnit test, in the Method Summary report, you might see a classifier of 'sessionLog.'

To see how the classifier attribute is used:

  1. Run the etlunit test that uses this attribute.
  2. Run the report for the test.
  3. Click on the test method name.
  4. Logs will be listed on a page.
  5. Preceding the log name is the classifier.

classifier attribute example

ETLUnit test code:

 

Example of assert-log classifier

class logTest

{

@Test

logMatches()

{

log(

message: 'Hi',

log-file-name: 'logMatches.file',

log-classifier: 'little_Log_Test'

);

 

assert-log(

classifier: 'little_Log_Test',

expected-log-expression: 'Hi'

);

}

}

 

 

Run the test and invoke the report:

 

userme > te #logMatches
Processing [1] tests
class experiment.logTest   -------------------------------------------------------
1/1        .logMatches
  Passed                                                                      P[1]
Tests run: 1, Successes: 1, Time elapsed: 0.196 sec
...
userme > r

 

 

  • Click on the word "All" on the last line.
  • Click on the test method name.
  • The classifier will precede the log file's name.

Go to top

failure-id:

Identifier to use as a Failure ID if the log assertion fails.

failure-id attribute example

A test that will trigger failure:

 

Example of failure-id

@Test

logClassifierMisMatch()

{

log(

message: 'Meaningful message',

log-file-name: 'logMatches.file',

log-classifier: 'LogTiminy'

);

 

assert-log(

classifier: 'LogTiminy',

failure-id: 'LOG_CONTENTS_NOT_AS_EXPECTED',

expected-log-expression: 'Meaning ful'

);

}

 

Visible in command shell when you run the test:

 

userme > te #logClassifierMisMatch
Processing [1] tests
class experiment.logTest   -------------------------------------------------------
1/1        .logClassifierMisMatch
      LOG_CONTENTS_NOT_AS_EXPECTED
  Failed                                                                      F[1]
Tests run: 1, Failures: 1, Time elapsed: 0.188 sec

 

Go to top

expected-log-expression:

Text you expect to find in the log file

expected-log-expression attribute example

 

Example of expected-log-expression attribute

assert-log(

log-name-pattern: '^s_m_SESSION\\.log$',

expected-log-expression: 'sq_rdcf_fact_load_temp: rmflt.1.0',

failure-id: 'TEMP: sq_rdcf_fact_load_temp version number not found'

);

 

In the above example, assertion-mode is not specified.  The assertion-mode value will be "contains," the default.

Go to top

expected-log-file:

Name of log assertion data file - for testing multiple rows of text

  • Use the expected-log-file attribute along with a text file that contains the expected log text, when you need to assert against multiple lines of text.
  • The file containing assertion data should be located in a folder called "log," a sibling of your test class.
  • The file name should have the extension ".expr"
  • The lines of text contained in the .expr file do not represent every byte of the log file.  They represent an excerpt.
  • Provide the name of that file in your etlunit test file structure, minus the ".expr" file name extension.

expected-log-file attribute example

 

 

File log_test_expectedLogFile_Matches.expr (contents)

Hi there buckeroo,

how are you?

 

 

Example of expected-log-file attribute

@Test

expectedLogFile_Matches()

{

log(

message: 'Hi there buckeroo,\nhow are you?',

log-file-name: 'logMatches.file',

log-classifier: 'standard-out'

);

assert-log(

expected-log-file: 'log_test_expectedLogFile_Matches',

failure-id: 'FAIL_BAD_LOG_CONTENTS'

);

}

 

 

userme > te @log_test#expectedLogFile_Matches
Processing [1] tests
class experiment.log_test   ------------------------------------------------------
1/1        .expectedLogFile_Matches
  Passed                                                                      P[1]
Tests run: 1, Successes: 1, Time elapsed: 0.188 sec

 

When the test was run,  the log() operation caused a log file to be generated that contained the expected text.

The text had a line break in it.

Go to top