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 6f133907-4e43-4840-8c64-afc782c0c9df nice set true card 1000 c0defda2-d8a5-4b9b-a1f0-3e7d3feb3454 nice set true card 1010 8a7763cf-f71c-47b7-b578-438dd36eb795 another set true rts 1030 8abaede1-b2c9-4e5a-bdbe-d7bab67e1f97 another set false rts 1050 a65bdbb8-ccf9-4398-93c7-f324f1363705 another set true fps 1070 222a82f1-2bca-4229-a91d-c1c09d4ce7a7 another set false fps 1090
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
db.update("delete from PRICES where price > :price", [price: 950]) db.update("delete from PRICES where price > :price", 950) PRICES.clear()
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