Description

Attributes

List of assert-log() operation attributes

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

log-name-pattern attribute example

 

/* 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:

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:

 

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

 

 

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:

 

@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

 

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

expected-log-file attribute example

 

 

Hi there buckeroo,

how are you?

 

 

@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