Use language specific DSL to create TableData instance: Groovy ["Col A" | "Col B" | "Col C"] { ________________________________ "v1a" | "v1b" | "v1c" "v2a" | "v2b" | "v2c" } Java table("Col A", "Col B", "Col C", ________________________________, "v1a", "v1b", "v1c", "v2a", "v2b", "v2c") Note: The example above assumes import static org.testingisdocumenting.webtau.WebTauCore.* or import static org.testingisdocumenting.webtau.WebTauDsl.* . Additionally WebTauCore has header-separating lines defined using underscores ___ of various lengths, which you can optionally use for aesthetics. Using ____ underscore is optional and is there for aesthetics only Groovy ["Col A" | "Col B" | "Col C"] { "v1a" | "v1b" | "v1c" "v2a" | "v2b" | "v2c" } Java table("Col A", "Col B", "Col C").values( "v1a", "v1b", "v1c", "v2a", "v2b", "v2c")
Use * in front of a column to specify it as a key column Groovy ["*id" | "Name" | "Type"] { ___________________________ "id1" | "N" | "T" "id2" | "N2" | "T2" "id3" | "N" | "T" } Java table("*id" , "Name" , "Type", _______________________, "id1" , "N" , "T", "id2" , "N2" , "T2", "id3" , "N" , "T") To access a value by key column Groovy def found = tableData.findByKey("id2") found.Name.should == "N2" Java Record found = tableData.findByKey("id2"); String name = found.get("Name"); actual(name).should(equal("N2")); To change key columns of an existing table Groovy tableData.withNewKeyColumns("Name", "Type") Java tableData.withNewKeyColumns("Name", "Type") Note: withNewKeyColumns creates new table and validates new key column uniqueness
Use to create TableData from a list of maps. Groovy def list = [ [k1: "v1", k2: "v2"], [k1: "v3", k3: "v4"]] TableData tableData = TableData.fromListOfMaps(list) TableData expected = ["k1" | "k2" | "k3"] { ____________________ "v1" | "v2" | null "v3" | null | "v4" } tableData.should == expected Java List<Map<String, ?>> list = new ArrayList<>(); list.add(CollectionUtils.map("k1", "v1", "k2", "v2")); list.add(CollectionUtils.map("k1", "v3", "k3", "v4")); TableData tableData = TableData.fromListOfMaps(list); TableData expected = table("k1", "k2", "k3", _________________, "v1", "v2", null, "v3", null, "v4"); actual(tableData).should(equal(expected)); Note: WebTau merges keys from all list elements to create the table header
Create From Existing Rows
Use to create TableData from existing rows. Groovy def table = ["*id" | "description"] { __________________________ "id1" | "description one" "id2" | "description two" "id3" | "description three" } def newTable = table.fromRowsByKeys("id1", "id3") newTable.should == ["*id" | "description"] { __________________________ "id1" | "description one" "id3" | "description three" } def table = ["*id1" | "*id2" | "description"] { _____________________________________ "id11" | "id21" | "description one" "id21" | "id22" | "description two" "id31" | "id32" | "description three" } def newTable = table.fromRowsByKeys(key("id11", "id21"), key("id31", "id32")) newTable.should == ["*id1" | "*id2" | "description"] { _____________________________________ "id11" | "id21" | "description one" "id31" | "id32" | "description three" } Java TableData table = table("*id", "description", __________________________, "id1", "description one", "id2", "description two", "id3", "description three"); TableData newTable = table.fromRowsByKeys("id1", "id3"); actual(newTable).should(equal(table("*id", "description", __________________________, "id1", "description one", "id3", "description three"))); TableData table = table("*id1", "*id2", "description", ____________________________________, "id11", "id12", "description one", "id21", "id22", "description two", "id31", "id32", "description three"); TableData newTable = table.fromRowsByKeys(key("id11", "id12"), key("id31", "id32")); actual(newTable).should(equal(table("*id1", "*id2", "description", ____________________________________, "id11", "id12", "description one", "id31", "id32", "description three")));
Use to serialize as JSON System.out.println(tableData.toJson()); [ { "A" : 1.3, "B" : 2 }, { "A" : "Hello", "B" : "World" } ] Use to serialize as CSV System.out.println(tableData.toCsv()); A,B 1.3,2 Hello,World
Use data/json#write-table-data data.json.write to serialize Table Data to a file
Use permute(v1, v2) to automatically generate multiple rows. Groovy ["Col A" | "Col B" | "Col C"] { ___________________________________________________________ permute(true, false) | "v1b" | permute('a', 'b') "v2a" | permute(10, 20) | "v2c" } Java table("Col A" , "Col B" , "Col C", ________________________________________________________________, permute(true, false), "v1b" , permute('a', 'b'), "v2a" , permute(10, 20) , "v2c") Col A Col B Col C true v1b a false v1b a true v1b b false v1b b v2a 10 v2c v2a 20 v2c
Use cell.guid to automatically generate unique ids. Groovy ["ID" | "Col A" | "Col B" | "Col C"] { ________________________________________________________________________ cell.guid | permute(true, false) | "v1b" | permute('a', 'b') cell.guid | "v2a" | permute(10, 20) | "v2c" } Java table("ID" , "Col A" , "Col B" , "Col C", ______________________________________________________________________, cell.guid, permute(true, false), "v1b" , permute('a', 'b'), cell.guid, "v2a" , permute(10, 20) , "v2c") ID Col A Col B Col C 90741f3b-a8f0-48e1-9ede-e9b2eb25d4bf true v1b a 8961f38b-3b5b-440a-b994-ddec6cc3938b false v1b a 6d4f7af8-65a7-46cd-b2a5-21a029611a61 true v1b b d5346f2c-48f3-4e7f-a283-677d270260e8 false v1b b 8f1a1bf2-8aba-48b1-9744-6dc969865bad v2a 10 v2c 6e649545-2465-43b4-992a-8f39aceda38b v2a 20 v2c
Use table.replace(before, after) to replace values in a table. Groovy ["Col A" | "Col B" | "Col C"] { ________________________________ "v1a" | "v1b" | "v1c" "v2a" | "v2b" | "v2c" } tableData.replace("v1b", "v1b_") Java table("Col A", "Col B", "Col C", ________________________________, "v1a", "v1b", "v1c", "v2a", "v2b", "v2c") tableData.replace("v1b", "v1b_") Col A Col B Col C v1a v1b_ v1c v2a v2b v2c
Cell Above Value Reference
Use cell.above to refer to the previous row value Groovy ["Name" | "Start Date" | "Games To Play" ] { ______________________________________________________ "John" | LocalDate.of(2016, 6, 20) | 10 "Bob" | cell.above | 8 "Mike" | cell.above | 14 "Drew" | LocalDate.of(2016, 6, 22) | 10 "Pete" | cell.above | 11 "Max" | cell.above | 3 } Java table("Name", "Start Date" , "Games To Play", __________________________________________________, "John", LocalDate.of(2016, 6, 20), 10, "Bob" , cell.above , 8, "Mike", cell.above , 14, "Drew", LocalDate.of(2016, 6, 22), 10, "Pete", cell.above , 11, "Max" , cell.above , 3) Name Start Date Games To Play John 2016-06-20 10 Bob 2016-06-20 8 Mike 2016-06-20 14 Drew 2016-06-22 10 Pete 2016-06-22 11 Max 2016-06-22 3
Use cell.above.plus|minus to generate a derived value based on the previous row value Groovy ["Name" | "Start Date" | "Games To Play" ] { ______________________________________________________ "John" | LocalDate.of(2016, 6, 20) | 10 "Bob" | cell.above | cell.above + 1 "Mike" | cell.above | cell.above + 1 } Java table("Name", "Start Date" , "Games To Play", ________________________________________________________________, "John", LocalDate.of(2016, 6, 20), 10, "Bob" , cell.above , cell.above.plus(1), "Mike", cell.above , cell.above.plus(1)) Name Start Date Games To Play John 2016-06-20 10 Bob 2016-06-20 11 Mike 2016-06-20 12 Extract cell.above.operation to make your intentions clearer Groovy def increment = cell.above + 1 ["Name" | "Start Date" | "Games To Play" ] { ______________________________________________________ "John" | LocalDate.of(2016, 6, 20) | 10 "Bob" | cell.above | increment "Mike" | cell.above | increment } Java TableDataCellValueGenerator<?> increment = cell.above.plus(1) table("Name", "Start Date" , "Games To Play", ________________________________________________________________, "John", LocalDate.of(2016, 6, 20), 10, "Bob" , cell.above , increment, "Mike", cell.above , increment)