@Override
protected void before() throws Throwable {
- truncateTables();
+ db.start();
}
@Override
if (session != null) {
MyBatis.closeQuietly(session);
}
- db.close();
+ db.stop();
}
public DbSession getSession() {
public void assertColumnDefinition(String table, String column, int expectedType, @Nullable Integer expectedSize) {
try (Connection connection = db.getDatabase().getDataSource().getConnection();
- PreparedStatement stmt = connection.prepareStatement("select * from " + table);
- ResultSet res = stmt.executeQuery()) {
+ PreparedStatement stmt = connection.prepareStatement("select * from " + table);
+ ResultSet res = stmt.executeQuery()) {
Integer columnIndex = getColumnIndex(res, column);
if (columnIndex == null) {
fail("The column '" + column + "' does not exist");
}
} catch (Exception e) {
- throw new IllegalStateException("Fail to check column");
+ throw new IllegalStateException("Fail to check column", e);
}
}
return null;
} catch (Exception e) {
- throw new IllegalStateException("Fail to get column idnex");
+ throw new IllegalStateException("Fail to get column index", e);
}
}
}
} catch (SQLException e) {
// ignore
+ e.printStackTrace();
}
}
return db.getDatabase();
}
- public DatabaseCommands getCommands() {
- return db.getCommands();
- }
-
}
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
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
db.start();
if (schemaPath != null) {
// will fail if not H2
- if (db.getDialect().getId().equals("h2")) {
+ if (H2.ID.equals(db.getDialect().getId())) {
((H2Database) db).executeScript(schemaPath);
} else {
db.stop();
- throw new AssumptionViolatedException("Test disabled because it supports only H2");
+
}
}
isDefault = (schemaPath == null);
}
}
+ void start() {
+ if (!isDefault && !H2.ID.equals(db.getDialect().getId())) {
+ throw new AssumptionViolatedException("Test disabled because it supports only H2");
+ }
+ }
+
void truncateTables() {
try {
commands.truncateDatabase(db.getDataSource());
}
}
- void close() {
+ void stop() {
if (!isDefault) {
db.stop();
}