db-execute
Applies specified DbUnit datasets to database
Overview
e:db-execute
<e:db-execute datasets='/db/adam.xml, /db/bob.json'/>
Usage
1. Configure a connection to database via DbPlugin.
2. Use e:db-execute tag in specification:
src/test/resources/specs/Specs.html
<e:db-execute 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: - |
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: - |
operation |
DbUnit operation to apply | Optional. Default: clean_insertother options: insert, update, refresh, delete, delete_all, truncate_table, truncate_insert |
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 |
vars |
Comma-separated list of name=value pairs to set as variables | Optional. Default: - |
varsSeparator |
name=value pairs separator to use in vars attribute |
Optional. Default: , |
Examples
Basic example
Given
Empty table:
| EMPTY |
| file | 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 | 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 |
When
The following markup:
<e:db-execute dir="/specs/db/data/" datasets="adam.xml, bob.json, carl/person.csv" vars="a1=1, a2=2" varsSeparator=","/>will be rendered as:| ID | 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 |
| ID | 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 |
Then
Datasets were applied to database:
| ID | NAME | AGE | IQ | BIRTHDAY |
|---|---|---|---|---|
| 1 | Adam | 1E+1 | (null) | 2022-03-12 00:00:00.000 |
| 2 | Carl | 3E+1 | (null) | 2003-03-03 00:00:00.000 |
| 10 | Bob | 2E+1 | (null) | 2000-10-10 00:00:00.000 |