Skip to content

Commit b2c3d65

Browse files
documentation: utilities -> data (#780)
1 parent c11e3d0 commit b2c3d65

13 files changed

Lines changed: 200 additions & 2 deletions

File tree

webtau-data/src/main/java/org/testingisdocumenting/webtau/data/DataCsv.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,46 @@
2626
import static org.testingisdocumenting.webtau.data.DataContentUtils.dataTextContent;
2727

2828
public class DataCsv {
29+
/**
30+
* Use <code>data.csv.table</code> to read data as {@link TableData} from CSV file.
31+
* Passed path is either relative based on working dir or absolute path. Or it can be a resource class path.
32+
* @param fileOrResourcePath relative path, absolute path or classpath resource path
33+
* @return table data with CSV content
34+
*/
2935
public TableData table(String fileOrResourcePath) {
3036
return tableFromListOfMaps(CsvUtils.parse(textContent(fileOrResourcePath)));
3137
}
3238

39+
/**
40+
* Use <code>data.csv.tableAutoConverted</code> to read data as {@link TableData} from CSV file. Numeric values become values of Numeric type instead of String type.
41+
* Passed path is either relative based on working dir or absolute path. Or it can be a resource class path.
42+
*
43+
* @param fileOrResourcePath relative path, absolute path or classpath resource path
44+
* @return table data with CSV content
45+
*/
3346
public TableData tableAutoConverted(String fileOrResourcePath) {
3447
return tableFromListOfMaps(CsvUtils.parseWithAutoConversion(textContent(fileOrResourcePath)));
3548
}
3649

50+
/**
51+
* Use <code>data.csv.listOfMaps</code> to read data as {@link java.util.List} of {@link java.util.Map} from CSV file.
52+
* Passed path is either relative based on working dir or absolute path. Or it can be a resource class path.
53+
*
54+
* @param fileOrResourcePath relative path, absolute path or classpath resource path
55+
* @return list of maps
56+
*/
3757
public List<Map<String, String>> listOfMaps(String fileOrResourcePath) {
3858
return CsvUtils.parse(textContent(fileOrResourcePath));
3959
}
4060

61+
/**
62+
* Use <code>data.csv.listOfMaps</code> to read data as {@link java.util.List} of {@link java.util.Map} from CSV file.
63+
* Numeric values become values of Numeric type instead of String type.
64+
* Passed path is either relative based on working dir or absolute path. Or it can be a resource class path.
65+
*
66+
* @param fileOrResourcePath relative path, absolute path or classpath resource path
67+
* @return list of maps
68+
*/
4169
public List<Map<String, Object>> listOfMapsAutoConverted(String fileOrResourcePath) {
4270
return CsvUtils.parseWithAutoConversion(textContent(fileOrResourcePath));
4371
}

webtau-data/src/main/java/org/testingisdocumenting/webtau/data/DataJson.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,22 @@
2424
import static org.testingisdocumenting.webtau.data.DataContentUtils.dataTextContent;
2525

2626
public class DataJson {
27+
/**
28+
* Use <code>data.json.map</code> to read data as {@link java.util.Map} from JSON file.
29+
* Passed path is either relative based on working dir or absolute path. Or it can be a resource class path.
30+
* @param fileOrResourcePath relative path, absolute path or classpath resource path
31+
* @return list of primitive values or maps/list
32+
*/
2733
public Map<String, ?> map(String fileOrResourcePath) {
2834
return JsonUtils.deserializeAsMap(textContent(fileOrResourcePath));
2935
}
3036

37+
/**
38+
* Use <code>data.json.list</code> to read data as {@link java.util.List} from JSON file.
39+
* Passed path is either relative based on working dir or absolute path. Or it can be a resource class path.
40+
* @param fileOrResourcePath relative path, absolute path or classpath resource path
41+
* @return list of primitive values or maps/list
42+
*/
3143
public List<?> list(String fileOrResourcePath) {
3244
return JsonUtils.deserializeAsList(textContent(fileOrResourcePath));
3345
}

webtau-docs/znai/groovy-standalone-runner/data-driven-scenarios.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Define scenarios in a loop to have dynamic scenarios based on provided data.
77

88
# CSV
99

10-
Use `data.csv` to conveniently build your scenarios from an external `CSV` data set.
10+
Use [data.csv](utilities/data#csv) to conveniently build your scenarios from an external `CSV` data set.
1111

1212
:include-file: examples/use-cases.csv {title: "examples/use-cases.csv"}
1313

webtau-docs/znai/lookup-paths

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
../../webtau-db/src/test/groovy
3737
../../webtau-db/target/test-classes
3838
../../webtau-db/src/test
39+
../../webtau-data/src/main/java
3940
../../webtau-cli-testing/src/test/groovy
4041
../../webtau-cli-testing/target/doc-artifacts
4142
../target/classes

webtau-docs/znai/references.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TableData,reference/table-data
2+
java.util.List,https://docs.oracle.com/javase/8/docs/api/java/util/List.html
3+
java.util.Map,https://docs.oracle.com/javase/8/docs/api/java/util/Map.html

webtau-docs/znai/toc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ cli
4949
introduction
5050
foreground-command
5151
background-command
52+
utilities
53+
introduction
54+
data
5255
groovy-standalone-runner
5356
introduction
5457
data-driven-scenarios

webtau-docs/znai/utilities/data.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# CSV
2+
3+
## Table Data
4+
5+
:include-java-doc: org/testingisdocumenting/webtau/data/DataCsv.java {entry: "table"}
6+
7+
:include-table: examples/data/table.csv {title: "data/table.csv"}
8+
9+
:include-file: doc-artifacts/snippets/readingData/csvTable.groovy {title: "read table data from csv"}
10+
11+
Note: by default numeric values are read as strings, to auto convert numeric values to actual numbers use `tableAutoConverted` method
12+
13+
:include-java-doc: org/testingisdocumenting/webtau/data/DataCsv.java {entry: "tableAutoConverted"}
14+
15+
:include-file: doc-artifacts/snippets/readingData/csvTableAutoConverted.groovy {title: "read table data from csv with auto conversion"}
16+
17+
## List Of Map
18+
19+
:include-table: examples/data/table.csv {title: "data/table.csv"}
20+
21+
:include-java-doc: org/testingisdocumenting/webtau/data/DataCsv.java {entry: "listOfMaps"}
22+
23+
:include-file: doc-artifacts/snippets/readingData/listOfMaps.groovy {title: "read list of maps from csv"}
24+
25+
Note: by default numeric values are read as strings, to auto convert numeric values to actual numbers use `tableAutoConverted` method
26+
27+
:include-java-doc: org/testingisdocumenting/webtau/data/DataCsv.java {entry: "listOfMapsAutoConverted"}
28+
29+
:include-file: doc-artifacts/snippets/readingData/listOfMapsAutoConverted.groovy {title: "read list of maps from csv with auto conversion"}
30+
31+
32+
# JSON
33+
34+
## List
35+
36+
:include-java-doc: org/testingisdocumenting/webtau/data/DataJson.java {entry: "list"}
37+
38+
:include-json: data/flat-list.json {paths: ["root[0].name", "root[1].payload.info"], title: "data/flat-list.json"}
39+
40+
:include-file: doc-artifacts/snippets/readingData/jsonList.groovy {title: "read json as list"}
41+
42+
## Map
43+
44+
:include-java-doc: org/testingisdocumenting/webtau/data/DataJson.java {entry: "map"}
45+
46+
:include-json: data/root-map.json {paths: ["root.payload.info"], title: "data/root-map.json"}
47+
48+
:include-file: doc-artifacts/snippets/readingData/jsonMap.groovy {title: "read json as map"}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Webtau has several modules to help you simplify automation processes. All operations in the modules provide
2+
detailed information on steps executed and details are included in web report as well as console output.
3+
4+
* [data](utilities/data) - module to read structured data like CSV and JSON into data structures like `TableData`, lists and maps
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"id": "id1",
4+
"name": "hello",
5+
"payload": {
6+
"info": "additional id1 payload"
7+
}
8+
},
9+
{
10+
"id": "id2",
11+
"name": "world",
12+
"payload": {
13+
"info": "additional id2 payload"
14+
}
15+
}
16+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"id": "id1",
3+
"name": "hello",
4+
"payload": {
5+
"info": "additional id1 payload"
6+
}
7+
}

0 commit comments

Comments
 (0)