Skip to content

Simple assertion

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

In the following cases we will suppose that we have created the following file named table_currency_expected.json:

[
    {
      "id": "90c659f0-a16e-41a6-a38e-3c67d7b3c600",
      "code": "EUR",
      "label": "euro",
      "last_modified_by": "username",
      "last_modified_date": "2019-11-01T00:00:00Z",
      "created_date": "2019-11-01T00:00:00Z",
      "created_by": "username",
      "version": 1
    },
    {
      "id": "{#uuid#}",
      "code": "USD",
      "label": "Dollar Americano",
      "last_modified_by": "username",
      "last_modified_date": "{#date_time_format:iso_instant#}",
      "created_date": "{#date_time_format:iso_instant#}",
      "created_by": "username",
      "version": 1
    }
]

Assertj-db

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

JDBC

assertThatQuery("SELECT * FROM table_test")
     .using(DriverManager.getConnection("jdbc://localhost:5432/database-name", "username", "password"))
     .isValidAgainst(loadFile("table_currency_expected.json"));

MongoDB

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

Cassandra

CQL:

assertThatCollection("select * from cassandra_table_type")
     .isValidAgainst(loadFile("table_currency_expected.json"));

Query Builder:

assertThatCollection(QueryBuilder.selectFrom("cassandratest", "cassandra_table_type").all())
     .isValidAgainst(loadFile("table_currency_expected.json"));
Clone this wiki locally