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 e24f2132-6eff-4636-ba10-cceae1003d4c nice set true card 1000 d12b2bc0-8d3d-40ad-a8c0-83791cf31d4c nice set true card 1010 f211a4d6-82b2-4528-b994-f8961008ec9a another set true rts 1030 36204292-d438-4023-ad18-9bd145673940 another set false rts 1050 75654ea7-c586-4b06-8b53-81bb8ac2f4a5 another set true fps 1070 f38de156-8d39-4cb1-8f02-13bed0a7d2a4 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) PRICES.clear()

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