assertj / assertj/assertj-db

Add assertions for database structure

Đang mở
#12 6 bình luận 0 reaction 1 người được giao Được @regis1512 nhận Xem trên GitHub
enhancement
Ngôn ngữ chính
Java
Star
130
Fork
21
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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);`

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.