Skip to content

Assertion with ordering

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

Assertion with data ordering

JCV-DB supports ordering defined by requests and libraries. In the following cases we suppose that we have created the following table_currency_expected.json file:

[
    {
      "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
    },
    {
      "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
    }
]

Assertj-db

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

JDBC

assertThatQuery("SELECT * FROM table_test ORDER BY label DESC")
     .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().sort(BasicDBObject("label", -1)))
     .isValidAgainst(loadFile("table_currency_expected.json"));

Cassandra

CQL:

assertThatCollection("select *from cassandra_table_type order by label desc")
     .using(new CassandraDataSource("cassandra_dc_test", "localhost", 5425))
     .isValidAgainst(loadFile("table_currency_expected.json"));

Query Builder:

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