assertj / assertj/assertj-db

Add assertions for database structure

Abierto
#12 6 comentarios 0 reacciones 1 asignado Reclamado por @regis1512 Ver en GitHub
enhancement
Lenguaje dominante
Java
Estrellas
130
Forks
21
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.