db-verify
Applies specified DbUnit datasets to database
Overview
e:db-verify
<e:db-verify datasets='/db/adam.xml, /db/bob.json'/>
Usage
1. Configure a connection to database via DbPlugin.
2. Use e:db-verify
tag in specification:
<e:db-verify datasets='/db/adam.xml, /db/bob.json'/>
Attributes
attribute | desc | example |
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: defaultds="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: 4awaitAtMostSec="4"
|
awaitPollDelayMillis |
How long to wait in millis before starting to verify * |
Optional. Default: 0awaitPollDelayMillis="1000"
|
awaitPollIntervalMillis |
How long to wait in millis between verification attempts * |
Optional. Default: 1000awaitPollIntervalMillis="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
Given
PERSONID | NAME | AGE | BIRTHDAY |
---|
1 | Adam | 10 | 2022-03-12 00:00:00.000 |
10 | Bob | 20 | 2000-10-10 00:00:00 |
2 | Carl | 30 | 2003-03-03 00:00:00.000 |
PERSON_FIELDSID | NAME | VAL | PERSON_ID |
---|
11 | a1 | 1 | 1 |
12 | a2 | 2 | 1 |
21 | b1 | 1 | 10 |
22 | b2 | 2 | 10 |
31 | c1 | value with comma >> , << and quotes "_' | 2 |
And following dataset files:
/home/runner/work/Exam/Exam/example/build/resources/test/specs/db/datafile | content | 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 | |
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: PERSONID | NAME | AGE | BIRTHDAY |
---|
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_FIELDSID | NAME | VAL | PERSON_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 |