Exam >
On this page

db-verify

Applies specified DbUnit datasets to database

Overview

Usage

1. Configure a connection to database via DbPlugin.

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

src/test/resources/specs/Specs.html
<e:db-verify datasets='/db/adam.xml, /db/bob.json'/>  

Attributes

attributedescexample
datasets Comma-separated paths in src/test/resources to datasets to apply. Supported formats: xml, json, csv Required. Default: -
datasets="/db/adam.xml, /db/bob.json, /db/carl/person.csv"
dir Set directory in src/test/resources as working directory so that all datasets from datasets attribute will be relative to it: src/test/resources[dir][item in datasets] Optional. Default: -
dir="/db/"
ds Datasource to which dataset will be applied. By default only 1 datasource with name default exists, other may be added by DbPlugin configuration. Optional. Default: default
ds="myOtherDatasource"
orderBy List of columns to sort records before verifying. Useful when default sorting results in different order for actual and expected datasets due to using of placeholders. Optional. Default: -
orderBy="person_fields.val, person.birthday"
vars Comma-separated list of name=value pairs to set as variables Optional. Default: -
vars="var1=1, var2={{now}}, var3=' preserved spaces string '"
varsSeparator name=value pairs separator to use in vars attribute Optional. Default: ,
varsSeparator="|"
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

Examples

Basic example

Log File
Basic example

Given


PERSON
IDNAMEAGEBIRTHDAY
1Adam102022-03-12 00:00:00.000
10Bob202000-10-10 00:00:00
2Carl302003-03-03 00:00:00.000
PERSON_FIELDS
IDNAMEVALPERSON_ID
11a111
12a221
21b1110
22b2210
31c1value with comma >> , << and quotes "_'2
And following dataset files:
/home/runner/work/Exam/Exam/example/build/resources/test/specs/db/data
filecontent
adam.xml
<?xml version='1.0' encoding='UTF-8'?>
<dataset>
  <PERSON ID="1" NAME="Adam" AGE="10" BIRTHDAY="{{today}}"/>
  <PERSON_FIELDS ID="11..19" NAME="a1" VAL="{{a1}}" PERSON_ID="1"/>
  <PERSON_FIELDS ID="11..19" NAME="a2" VAL="{{a2}}" PERSON_ID="1"/>
</dataset>
bob.json
{
  "PERSON": [
    {"id": 10, "name": "Bob", "age": 20, "BIRTHDAY": "2000-10-10 00:00:00"}
  ],
  "PERSON_FIELDS": [
    {"id": "21..30", "name": "b1", "val": "1", "person_id": 10},
    {"id": "21..30", "name": "b2", "val": "2", "person_id": 10}
  ]
}
carl/table-ordering.txt
person_fields
person
carl/person.csv
ID, NAME, AGE, BIRTHDAY
2, "Carl", 30, {{date "2003-03-03"}}
carl/person_fields.csv
ID, NAME, VAL, PERSON_ID
31..40, c1, "value with comma >> , << and quotes \"_'", 2

Then


The following markup:
<e:db-verify dir="/specs/db/data/" datasets="adam.xml, bob.json, carl/person.csv" orderBy="person_fields.val, person.birthday" vars="a1=1, a2=2" varsSeparator=","/>
will be rendered as:
PERSON
IDNAMEAGEBIRTHDAY
 10 Bob 20 2000-10-10 00:00:00
 2 Carl 30 2003-03-03 00:00:00.000
 1 Adam 10 2022-03-12 00:00:00.000
PERSON_FIELDS
IDNAMEVALPERSON_ID
 11 a1 1 1
 21 b1 1 10
 12 a2 2 1
 22 b2 2 10
 31 c1 value with comma >> , << and quotes "_' 2