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 cc0d1b50-68ff-4cb1-b3f4-93766f391a3f nice set true card 1000 e6b622f8-35a3-4d7e-b4bf-89490d965f9d nice set true card 1010 8db5ee60-5371-49a6-966b-a6e82d12c8cd another set true rts 1030 3612358e-d85b-42b0-b06c-4acd81f39794 another set false rts 1050 af094549-8d67-4004-979b-c3e8189f9b6c another set true fps 1070 f7cb27f1-43fa-4a2b-af35-433b9ad31391 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