Skip to content

Assertion with column restriction

Lukas Cardot edited this page Feb 16, 2020 · 1 revision

JCV-DB supports the restriction of the results returned by the different requests and libraries. In the following cases we suppose that we have created the following table_currency_expected.json file:

[
    {
      "id": "90c659f0-a16e-41a6-a38e-3c67d7b3c600",
      "code": "EUR",
      "label": "euro"
    },
    {
      "id": "{#uuid#}",
      "code": "USD",
      "label": "Dollar Americano"
    }
]

Assertj-db

Source source = new Source("jdbc://localhost:5432/database-name", "username", "password")
Table table = new Table(source, "table_test")
assertThatTable(table.setColumnsToCheck({ "id", "code", "label" }))
    .isValidAgainst(loadFile("table_currency_expected.json"));

JDBC

assertThatQuery("SELECT id, code, label FROM table_test")
     .isValidAgainst(loadFile("table_currency_expected.json"));

MongoDB

BasicDBObject filter = new BasicDBObject("_id", true)
    .append("code", true)
    .append("label", true);

assertThatCollection(mongoClient.getDatabase("database-name").getCollection("currency-collection").find().projection(filter))
     .isValidAgainst(loadFile("table_currency_expected.json"));

Cassandra

CQL:

assertThatCollection("select id, code, label from cassandra_table_type")
     .using(new CassandraDataSource("cassandra_dc_test", "localhost", 5425))
     .isValidAgainst(loadFile("table_currency_expected.json"));

Query Builder:

assertThatCollection(QueryBuilder.selectFrom("cassandratest", "cassandra_table_type").all().columns("id", "code", label))
     .using(new CassandraDataSource("cassandra_dc_test", "localhost", 5425))
     .isValidAgainst(loadFile("table_currency_expected.json"));
Clone this wiki locally