db-check
Creates DbUnit dataset for specified table and verifies it against a database
Overview
e:db-check
<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>
Usage
1. Configure a connection to database via DbPlugin.
2. Use e:db-check
tag in specification:
<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
attribute | desc | example |
---|---|---|
table |
Table name | Required. Default: -
|
cols |
List of comma-separated column names with optionally provided values to include in dataset | Optional. Default: -
|
separator |
Value separator in e:row |
Optional. Default: ,
|
where |
WHERE clause in database-specific SQL format to filter actual dataset | Optional. Default: -
|
where |
WHERE clause in database-specific SQL format to filter actual dataset | Optional. Default: -
|
caption |
Caption to display instead of table name in report | Optional. Default: -
|
orderBy |
List of columns to sort records before verifying | Optional. Default: columns from cols attribute in order of declaration
|
ignoreRowsBefore |
Row number from expected dataset before which rows will be excluded from the verification | Optional. Default: 1
|
ignoreRowsAfter |
Row number from expected dataset after which rows will be excluded from the verification | Optional. Default: 0 (disabled)
|
awaitAtMostSec |
How long to wait in seconds before failing the verification * | Optional. Default: 4
|
awaitPollDelayMillis |
How long to wait in millis before starting to verify * | Optional. Default: 0
|
awaitPollIntervalMillis |
How long to wait in millis between verification attempts * | Optional. Default: 1000
|
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).
Given
Table has the following records:
id | name | height | manufactured |
---|---|---|---|
1 | Adam | 170 | 2022-03-12 00:00:00.000 |
2 | Bob | 200 | 2022-03-12 00:00:00.000 |
Then
<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:id | name | height | manufactured |
---|---|---|---|
1 | Adam | 170 | 2022-03-12 00:00:00.000 |
2 | Bob | 200 | 2022-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:
Given
Table has the following records:
id | name | height | manufactured |
---|---|---|---|
1 | Adam | 170 | 2022-03-12 00:00:00.000 |
2 | Bob | 200 | 2022-03-12 00:00:00.000 |
Then
<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:id | name | height | manufactured |
---|---|---|---|
1 | Adam | 170 | 2022-03-12 00:00:00.000 |
2 | Bob | 200 | 2022-03-12 00:00:00.000 |
Examples
Value declaration
Value can be declared as simple text, Handlebar helpers invocation or ranges.
Given
Table has the following records:
id | name | weight | manufactured |
---|---|---|---|
1 | Adam | 70 | 2022-03-11 00:00:00.000 |
2 | Bob | 90 | 2022-03-11 00:00:00.000 |
Then
id
value is declared as range and will be assigned from 1 to 10 in circlename
andweight
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)
<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:id | name | weight | manufactured |
---|---|---|---|
1 | Adam | 70 | 2022-03-11 00:00:00.000 |
2 | Bob | 90 | 2022-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 '
Given
Table has the following records:
- First
name
equals to [ A ] (surrounded by spaces) - Second
name
equals to just [A]
id | name | weight |
---|---|---|
1 | A | 70 |
2 | A | 90 |
Then
<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:name | weight |
---|---|
A | 70 |
A | 90 |
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.
Given
Table has record where name = a, b
id | name | weight |
---|---|---|
1 | a , b | 70 |
Then
<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:id | name | weight |
---|---|---|
1 | a , b | 70 |
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.
Given
Table has the following records:
id | name | height |
---|---|---|
1 | Adam | 170 |
2 | Adam | 130 |
3 | Bob | 200 |
Then
<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:name | height |
---|---|
Adam | 170 |
Verifying table is empty
To verify that table is empty an empty e:db-check
tag can be used with single table
attribute.
Given
Empty table:
EMPTY |
Then
<e:db-check table="ANDROIDS_TABLE"/>
will be rendered as:EMPTY |