Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Completely clear and rebuild the h2 database on reset
Browse files Browse the repository at this point in the history
The sql backup procedure for the first run scenario writes the
sequence lines without the "if not exists" clause, so subsequent
runs can fail - especially after the user has executed some
tests manually.
Drop all items from the database and either restore a base from
the backup or a complete database with test data.
  • Loading branch information
djansen-redhat committed Sep 10, 2013
1 parent cef83a5 commit e97f4e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Expand Up @@ -37,6 +37,7 @@ public class DatabaseHelper
private static Statement statement;
private static DatabaseHelper DB;
private String backupPath;
private static int CURRENT_TABLE_COUNT = 76;
private FluentWait<Statement> wait;

private DatabaseHelper()
Expand Down Expand Up @@ -181,13 +182,21 @@ public void resetDatabaseWithData()
{
String path = getFileFromClasspath("org/zanata/feature/zanata_with_data.sql").getAbsolutePath();
executeQuery("RUNSCRIPT FROM '" + path + "' CHARSET 'UTF-8'");
waitUntil("select count(*) from INFORMATION_SCHEMA.tables", CURRENT_TABLE_COUNT);
waitUntil("select count(*) from HProjectIteration", 1);
}

public void resetData()
{
executeQuery("RUNSCRIPT FROM '" + backupPath + "' CHARSET 'UTF-8'");
waitUntil("select count(*) from HProjectIteration", 0);
waitUntil("select count(*) from INFORMATION_SCHEMA.tables", CURRENT_TABLE_COUNT);
}

public void obliterateDatabase()
{
executeQuery("DROP ALL OBJECTS");
waitUntil("select count(*) from INFORMATION_SCHEMA.SEQUENCES", 0);
}

public void resetFileData()
Expand Down
Expand Up @@ -29,19 +29,18 @@ protected void before() throws Throwable
}

DatabaseHelper.database().resetFileData();
DatabaseHelper.database().obliterateDatabase();

if (configSet.contains(Config.WithData))
{
DatabaseHelper.database().resetDatabaseWithData();
}
else
{
log.info("reset database before");
DatabaseHelper.database().resetData();
DatabaseHelper.database().addAdminUser();
DatabaseHelper.database().addTranslatorUser();
}

}

private boolean isResetEnabled()
Expand All @@ -55,6 +54,7 @@ protected void after()
// by default it will reset database after
if (isResetEnabled() && !configSet.contains(Config.NoResetAfter))
{
DatabaseHelper.database().obliterateDatabase();
DatabaseHelper.database().resetData();
log.info("reset database after");
}
Expand Down

0 comments on commit e97f4e5

Please sign in to comment.