assertj / assertj/assertj-db

Add assertions for database structure

オープン
#12 コメント 6 件 リアクション 0 件 担当者 1 名 @regis1512 が担当を希望しています GitHub で見る
enhancement
主要言語
Java
スター
130
フォーク
21
PR マージ指標
30日以内にマージされた PR はありません

説明

I need assertions for checking database structure.
E.g. I want to check if specific table exists in database.

Proposed assertions:
`assertThat(table).exists();`
or
`assertThat(source).tableExists("name");`

Additionally it would be nice to have convinience method isEmpty() for
`assertThat(table).hasNumberOfRows(0);`

JDBC code to check if table exists ()

```
public static boolean hasTable(DataSource ds, String name) {
boolean exists = false;

try(Connection c = ds.getConnection();
//table names usually stored in database uppercased
ResultSet rs = c.getMetaData().getTables(null, null, name.toUpperCase(), null)) {

if (rs.next()) {
exists = true; // table exists
}
} catch (Exception e) {
e.printStackTrace();
}

return exists;
}
```

Or just do some operation and catch jdbc exception: table not exists. Below assertion partially does the trick, but is not elegant.
`assertThat(table).hasNumberOfRows(0);`

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。