aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src/test
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-07-06 15:05:53 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-07-06 15:05:53 +0200
commit34ac5d84f639df6643a7976593c6f00b4283f04b (patch)
tree323c9f9093eec1ee62c6fbcf76b2a2c16f4dbc38 /sonar-db/src/test
parent769e017b27513adf3e0991ac8affb090a1f35053 (diff)
downloadsonarqube-34ac5d84f639df6643a7976593c6f00b4283f04b.tar.gz
sonarqube-34ac5d84f639df6643a7976593c6f00b4283f04b.zip
Fix execution of tests on non-H2 databases
Diffstat (limited to 'sonar-db/src/test')
-rw-r--r--sonar-db/src/test/java/org/sonar/db/DbTester.java17
-rw-r--r--sonar-db/src/test/java/org/sonar/db/TestDb.java13
2 files changed, 17 insertions, 13 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/DbTester.java b/sonar-db/src/test/java/org/sonar/db/DbTester.java
index 30bc65fa1e3..498f5f46eec 100644
--- a/sonar-db/src/test/java/org/sonar/db/DbTester.java
+++ b/sonar-db/src/test/java/org/sonar/db/DbTester.java
@@ -96,7 +96,7 @@ public class DbTester extends ExternalResource {
@Override
protected void before() throws Throwable {
- truncateTables();
+ db.start();
}
@Override
@@ -104,7 +104,7 @@ public class DbTester extends ExternalResource {
if (session != null) {
MyBatis.closeQuietly(session);
}
- db.close();
+ db.stop();
}
public DbSession getSession() {
@@ -323,8 +323,8 @@ public class DbTester extends ExternalResource {
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");
@@ -336,7 +336,7 @@ public class DbTester extends ExternalResource {
}
} catch (Exception e) {
- throw new IllegalStateException("Fail to check column");
+ throw new IllegalStateException("Fail to check column", e);
}
}
@@ -353,7 +353,7 @@ public class DbTester extends ExternalResource {
return null;
} catch (Exception e) {
- throw new IllegalStateException("Fail to get column idnex");
+ throw new IllegalStateException("Fail to get column index", e);
}
}
@@ -387,6 +387,7 @@ public class DbTester extends ExternalResource {
}
} catch (SQLException e) {
// ignore
+ e.printStackTrace();
}
}
@@ -419,8 +420,4 @@ public class DbTester extends ExternalResource {
return db.getDatabase();
}
- public DatabaseCommands getCommands() {
- return db.getCommands();
- }
-
}
diff --git a/sonar-db/src/test/java/org/sonar/db/TestDb.java b/sonar-db/src/test/java/org/sonar/db/TestDb.java
index 3ab4fc41346..93509a42fab 100644
--- a/sonar-db/src/test/java/org/sonar/db/TestDb.java
+++ b/sonar-db/src/test/java/org/sonar/db/TestDb.java
@@ -41,6 +41,7 @@ import org.sonar.api.config.Settings;
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
@@ -91,11 +92,11 @@ class TestDb {
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);
@@ -109,6 +110,12 @@ class TestDb {
}
}
+ 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());
@@ -117,7 +124,7 @@ class TestDb {
}
}
- void close() {
+ void stop() {
if (!isDefault) {
db.stop();
}