Add assertions for database structure
@regis1512 is already working on this.
Since Jul 9, 2015.
Assessment
This issue has not been assessed yet.
Description
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);
- Dominant language
- Java
- Stars
- 130
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from assertj/assertj-db
-
assertj/assertj-db#324 · 1 comment · 1 assignee ·
-
question
Difficulty 3/5 1-2 days Newbie friendliness 32/100
assertj/assertj-db#292 · 1 comment ·
-
question
Difficulty 3/5 1-2 days Newbie friendliness 35/100
assertj/assertj-db#290 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
assertj/assertj-db#259 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
assertj/assertj-db#206 ·
All issues in assertj/assertj-db
Similar issues
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
apache/flink-agents#1152 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
jenkinsci/blueocean-plugin#5417 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
objectionary/eo-graphs#75 ·