Skip to content

Commit

Permalink
Revert "Fix execution of tests on non-H2 databases"
Browse files Browse the repository at this point in the history
This reverts commit 34ac5d8.
  • Loading branch information
Simon Brandhof committed Jul 6, 2015
1 parent 34ac5d8 commit cc40fc4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
17 changes: 10 additions & 7 deletions sonar-db/src/test/java/org/sonar/db/DbTester.java
Expand Up @@ -96,15 +96,15 @@ public static DbTester createForSchema(System2 system2, Class testClass, String


@Override @Override
protected void before() throws Throwable { protected void before() throws Throwable {
db.start(); truncateTables();
} }


@Override @Override
protected void after() { protected void after() {
if (session != null) { if (session != null) {
MyBatis.closeQuietly(session); MyBatis.closeQuietly(session);
} }
db.stop(); db.close();
} }


public DbSession getSession() { public DbSession getSession() {
Expand Down Expand Up @@ -323,8 +323,8 @@ public void assertDbUnit(Class testClass, String filename, String[] excludedColu


public void assertColumnDefinition(String table, String column, int expectedType, @Nullable Integer expectedSize) { public void assertColumnDefinition(String table, String column, int expectedType, @Nullable Integer expectedSize) {
try (Connection connection = db.getDatabase().getDataSource().getConnection(); try (Connection connection = db.getDatabase().getDataSource().getConnection();
PreparedStatement stmt = connection.prepareStatement("select * from " + table); PreparedStatement stmt = connection.prepareStatement("select * from " + table);
ResultSet res = stmt.executeQuery()) { ResultSet res = stmt.executeQuery()) {
Integer columnIndex = getColumnIndex(res, column); Integer columnIndex = getColumnIndex(res, column);
if (columnIndex == null) { if (columnIndex == null) {
fail("The column '" + column + "' does not exist"); fail("The column '" + column + "' does not exist");
Expand All @@ -336,7 +336,7 @@ public void assertColumnDefinition(String table, String column, int expectedType
} }


} catch (Exception e) { } catch (Exception e) {
throw new IllegalStateException("Fail to check column", e); throw new IllegalStateException("Fail to check column");
} }
} }


Expand All @@ -353,7 +353,7 @@ private Integer getColumnIndex(ResultSet res, String column) {
return null; return null;


} catch (Exception e) { } catch (Exception e) {
throw new IllegalStateException("Fail to get column index", e); throw new IllegalStateException("Fail to get column idnex");
} }
} }


Expand Down Expand Up @@ -387,7 +387,6 @@ private void closeQuietly(IDatabaseConnection connection) {
} }
} catch (SQLException e) { } catch (SQLException e) {
// ignore // ignore
e.printStackTrace();
} }
} }


Expand Down Expand Up @@ -420,4 +419,8 @@ public Database database() {
return db.getDatabase(); return db.getDatabase();
} }


public DatabaseCommands getCommands() {
return db.getCommands();
}

} }
13 changes: 3 additions & 10 deletions sonar-db/src/test/java/org/sonar/db/TestDb.java
Expand Up @@ -41,7 +41,6 @@
import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers; import org.sonar.api.utils.log.Loggers;
import org.sonar.db.deprecated.NullQueue; import org.sonar.db.deprecated.NullQueue;
import org.sonar.db.dialect.H2;


/** /**
* This class should be call using @ClassRule in order to create the schema once (ft @Rule is used * This class should be call using @ClassRule in order to create the schema once (ft @Rule is used
Expand Down Expand Up @@ -92,11 +91,11 @@ private TestDb(@Nullable String schemaPath) {
db.start(); db.start();
if (schemaPath != null) { if (schemaPath != null) {
// will fail if not H2 // will fail if not H2
if (H2.ID.equals(db.getDialect().getId())) { if (db.getDialect().getId().equals("h2")) {
((H2Database) db).executeScript(schemaPath); ((H2Database) db).executeScript(schemaPath);
} else { } else {
db.stop(); db.stop();

throw new AssumptionViolatedException("Test disabled because it supports only H2");
} }
} }
isDefault = (schemaPath == null); isDefault = (schemaPath == null);
Expand All @@ -110,12 +109,6 @@ private TestDb(@Nullable String schemaPath) {
} }
} }


void start() {
if (!isDefault && !H2.ID.equals(db.getDialect().getId())) {
throw new AssumptionViolatedException("Test disabled because it supports only H2");
}
}

void truncateTables() { void truncateTables() {
try { try {
commands.truncateDatabase(db.getDataSource()); commands.truncateDatabase(db.getDataSource());
Expand All @@ -124,7 +117,7 @@ void truncateTables() {
} }
} }


void stop() { void close() {
if (!isDefault) { if (!isDefault) {
db.stop(); db.stop();
} }
Expand Down

0 comments on commit cc40fc4

Please sign in to comment.