|
DbAssert
dbAssert = DbAssert.init("my/package/Sources.yml");DbSource postgres = dbAssert.source("postgres");//cleans up "customers" table
postgres.clean_table("customers");
//load data from customers.yml file to datasource
final Fixture customers = postgres.fixture("customers");
final Fixture customer_one = (Fixture) customers.get("customer_one");dbAssert.table("customers").where("id", 123);
//For database it becomes SELECT … FROM customers WHERE id = 123;
//Any additional condition you may add like this:
dbAssert.table("customers").where("id = 123").and("last_name", "Coupland");
//In this case for database it becomes SELECT … WHERE id = 123 AND last_name = ‘Coupland’;dbAssert.assert_column("name", "Douglas");
//Where “name” is a field name to retrieve value from. “Douglas” is the value we expect in this database field. You can add as many assertions as you want.// HashMap can be used to assert multiple columns at once // where the map contains column-name/expected-value key-value pairs. dbAssert.assert_columns(map); //checks field _name_ contains non empty value dbAssert.assert_not_empty(”name”); // check if count of records returned more than one dbAssert.assert_count_gt(”*”, 1); // chek if number of unique departments returned by query less than 2 dbAssert.assert_count_lt(”department”, 2); //check if number of returned records “count(*)..” equals 0 dbAssert.assert_count(0); // returns value of field “user_name” as String final String userName = dbAssert.column_value(”user_name”); |
► Sign in to add a comment
Sources.yml
postgres: url: jdbc:postgresql://127.0.0.1/test username: postgres password: postgres driver: org.postgresql.Driver hsqlSource: url: jdbc:hsqldb:file:testSrc username: sa password: driver: org.hsqldb.jdbcDriverMore examples:
final Fixture event_one = (Fixture) eventsFixture.get("event_one"); dbAssert.table().where("id", event_one.get("id")); dbAssert.assert_column("events.name", event_one.get("name")); dbAssert.assert_column("events.login_name", event_one.get("login_name")); dbAssert.table("events").where("id = 1").and("name = 'my event'"); dbAssert.assert_column("login_name", "dglinenko"); dbAssert.table("events"); dbAssert.assert_count(5);