Handcrafted Data

One way to set up a DB state is to use handcrafted reference/table-data TableData. def PRICES = db.table("PRICES") // declare PRICES table PRICES << [ "id" | "description" | "price"] { // append two rows to PRICES ___________________________________ "id1" | "nice set" | 1000 "id2" | "another set" | 2000 } Alternatively use list of maps as the parameter to perform multiple rows insertion def PRICES = db.table("PRICES") PRICES << [ [id: "id1", description: "nice set", price: 1000], [id: "id2", description: "warm set", price: 2000]] Use map as the parameter to perform a single row insertion def PRICES = db.table("PRICES") PRICES << [id: "id1", description: "nice set", price: 1000]

Semi-Auto Generated TableData

reference/table-data TableData has features like reference/table-data#permutations permute and reference/table-data#guid cell.guid among others. Using them can reduce the effort required to maintain data setup. def PRICES = db.table("PRICES") PRICES << [ "id" | "description" | "available" | "type" | "price" ] { _____________________________________________________________________________________________ cell.guid | "nice set" | true | "card" | 1000 // cell.guid generates random guid that can be used for ids cell.guid | "nice set" | true | "card" | cell.above + 10 // cell.above refers values above and can be modified with simple math operations cell.guid | "another set" | permute(true, false) | permute("rts", "fps") | cell.above + 20 } // permute generates additional rows generating new rows with all the permutations Note: code above assumes WebTauCore.* static import or WebTauGroovyDsl.* static import import static org.testingisdocumenting.webtau.WebTauCore.* ID EXTERNAL_ID DESCRIPTION AVAILABLE TYPE PRICE 9dd06201-4f31-4639-8a5e-1ce6e77e6082 nice set true card 1000 7f4544b4-6ed7-4af7-b9e7-51666bbe379e nice set true card 1010 81f14a55-fc24-459a-bb8a-82a31f3e2445 another set true rts 1030 be4e00cb-f513-420c-b828-b312716ee68c another set false rts 1050 402c28a2-d954-4c1b-85ff-3dc65cf776e2 another set true fps 1070 b9ce1a62-b73d-4452-a141-e29a3c49fff0 another set false fps 1090

External File TableData

def PRICES = db.table("PRICES") PRICES << data.csv.table('prices-db.csv') id, description, available, type, price id1, description1, true, card, 200 id2, description2, false, rts, 400 ID EXTERNAL_ID DESCRIPTION AVAILABLE TYPE PRICE id1 description1 true card 200 id2 description2 false rts 400

Cleaning Tables

db.update("delete from PRICES where price > :price", [price: 950]) db.update("delete from PRICES where price > :price", 950)

Updating Tables

ID EXTERNAL_ID DESCRIPTION AVAILABLE TYPE PRICE id1 nice set 1000 id2 another set 2000 db.update("update PRICES set price=:price where id=:id", [id: 'id2', price: 4000]) ID EXTERNAL_ID DESCRIPTION AVAILABLE TYPE PRICE id1 nice set 1000 id2 another set 4000