Exam >
On this page

db-check

Creates DbUnit dataset for specified table and verifies it against a database

Overview

Usage

1. Configure a connection to database via DbPlugin.

2. Use e:db-check tag in specification:

src/test/resources/specs/Specs.html
<e:db-check caption="optional caption" table="ANDROIDS_TABLE" cols="id, name" separator=",">
    <e:row>1, Adam</e:row>
    <e:row>2, Bob</e:row>
</e:db-check>  

Attributes

attributedescexample
table Table name Required. Default: -
table="androids_table"
cols List of comma-separated column names with optionally provided values to include in dataset Optional. Default: -
cols="id=1..10, name, height=170, manufactured={{now}}"
separator Value separator in e:row Optional. Default: ,
separator="|"
where WHERE clause in database-specific SQL format to filter actual dataset Optional. Default: -
where="name='andrew'"
where WHERE clause in database-specific SQL format to filter actual dataset Optional. Default: -
where="name='andrew'"
caption Caption to display instead of table name in report Optional. Default: -
caption="Androids"
orderBy List of columns to sort records before verifying Optional. Default: columns from cols attribute in order of declaration
orderBy="name, height"
ignoreRowsBefore Row number from expected dataset before which rows will be excluded from the verification Optional. Default: 1
ignoreRowsBefore="2"
ignoreRowsAfter Row number from expected dataset after which rows will be excluded from the verification Optional. Default: 0 (disabled)
ignoreRowsAfter="2"
awaitAtMostSec How long to wait in seconds before failing the verification * Optional. Default: 4
awaitAtMostSec="4"
awaitPollDelayMillis How long to wait in millis before starting to verify * Optional. Default: 0
awaitPollDelayMillis="1000"
awaitPollIntervalMillis How long to wait in millis between verification attempts * Optional. Default: 1000
awaitPollIntervalMillis="500"
* Waiting is disabled by default and check will fail immediately in case of mismatch unless at least one of the awaitAtMostSec, awaitPollDelayMillis or awaitPollIntervalMillis attributes are set

Each dataset record will be zipped from cols and rows declarations (hence order of cols and order of values inside rows should match).

Dummy example

Given


Table has the following records:
ANDROIDS_TABLE
idnameheightmanufactured
1Adam1702022-03-12 00:00:00.000
2Bob2002022-03-12 00:00:00.000

Then


The following markup:
<e:db-check table="ANDROIDS_TABLE" cols="id, name, height, manufactured">
  <e:row>1, Adam, 170, {{today}}</e:row>
  <e:row>2, Bob, 200, {{today}}</e:row>
</e:db-check>
will be rendered as:
ANDROIDS_TABLE
idnameheightmanufactured
1Adam1702022-03-12 00:00:00.000
2Bob2002022-03-12 00:00:00.000

If all rows should have the same value declaration for specific column, then value assignment may be inlined with column declaration. Values declaration for such columns should be omitted in e:row tag.

The next example produces the same result as the previous one:

Declaration inlining

Given


Table has the following records:
ANDROIDS_TABLE
idnameheightmanufactured
1Adam1702022-03-12 00:00:00.000
2Bob2002022-03-12 00:00:00.000

Then


The following markup:
<e:db-check table="ANDROIDS_TABLE" cols="id=1..2, name, height, manufactured={{today}}">
  <e:row>Adam, 170</e:row>
  <e:row> Bob, 200</e:row>
</e:db-check>
will be rendered as:
ANDROIDS_TABLE
idnameheightmanufactured
1Adam1702022-03-12 00:00:00.000
2Bob2002022-03-12 00:00:00.000

Examples

Value declaration

Value can be declared as simple text, Handlebar helpers invocation or ranges.

Value declaration

Given


Table has the following records:
ANDROIDS_TABLE
idnameweightmanufactured
1Adam702022-03-11 00:00:00.000
2Bob902022-03-11 00:00:00.000

Then


  • id value is declared as range and will be assigned from 1 to 10 in circle
  • name and weight values are declared as simple text values (value will be casted to column type be DbUnit)
  • manufactured value is declared as Handlebar helpers invocation and will be assigned to result of invocation (which will be casted to column type by DbUnit)
The following markup:
<e:db-check table="ANDROIDS_TABLE" cols="id=1..10, name, weight, manufactured={{today minus='1 d'}}">
  <e:row>Adam, 70</e:row>
  <e:row>Bob , 90</e:row>
</e:db-check>
will be rendered as:
ANDROIDS_TABLE
idnameweightmanufactured
1Adam702022-03-11 00:00:00.000
2Bob902022-03-11 00:00:00.000

Trimmed spaces

Values declarations a trimmed by default, if there is a need to preserve spaces, then declaration should be surrounded by '

Trimmed spaces

Given


Table has the following records:
  • First name equals to [ A ] (surrounded by spaces)
  • Second name equals to just [A]
ANDROIDS_TABLE
idnameweight
1 A 70
2A90

Then


The following markup:
<e:db-check table="ANDROIDS_TABLE" cols="name, weight">
  <e:row> ' A ' , 70</e:row>
  <e:row> A , 90</e:row>
</e:db-check>
will be rendered as:
ANDROIDS_TABLE
nameweight
A 70
A90

Values with commas

Comma is used as default values separator, so using it as part as the value declaration will break parsing. To workaround this custom value separator may be set by separator attribute.

Values with commas

Given


Table has record where name = a, b
ANDROIDS_TABLE
idnameweight
1a , b70

Then


The following markup:
<e:db-check table="ANDROIDS_TABLE" cols="id=1..10, name, weight" separator="|">
  <e:row> a , b | 70</e:row>
</e:db-check>
will be rendered as:
ANDROIDS_TABLE
idnameweight
1a , b70

Verifying a subset of data

To verify only a subset of actual data satisfying specific condition the where attribute can be used to provide filter in database-specific SQL format. The provided attribute value will be used as-is in WHERE clause of SQL SELECT expression.

Verifying subset

Given


Table has the following records:
ANDROIDS_TABLE
idnameheight
1Adam170
2Adam130
3Bob200

Then


The following markup:
<e:db-check table="ANDROIDS_TABLE" cols="name, height" where="name='Adam' and height=170">
  <e:row>Adam, 170</e:row>
</e:db-check>
will be rendered as:
ANDROIDS_TABLE
nameheight
Adam170

Verifying table is empty

To verify that table is empty an empty e:db-check tag can be used with single table attribute.

Verifying empty

Given


Empty table:
ANDROIDS_TABLE
EMPTY

Then


The following markup:
<e:db-check table="ANDROIDS_TABLE"/>
will be rendered as:
ANDROIDS_TABLE
EMPTY

More