]> source.dussan.org Git - sonarqube.git/commitdiff
Revert "Fix execution of tests on non-H2 databases"
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 6 Jul 2015 13:17:49 +0000 (15:17 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 6 Jul 2015 13:17:49 +0000 (15:17 +0200)
This reverts commit 34ac5d84f639df6643a7976593c6f00b4283f04b.

sonar-db/src/test/java/org/sonar/db/DbTester.java
sonar-db/src/test/java/org/sonar/db/TestDb.java

index 498f5f46eec98ba1f9186f90372fd65f6173a164..30bc65fa1e364e0d30b292b2f37c09170d52cae8 100644 (file)
@@ -96,7 +96,7 @@ public class DbTester extends ExternalResource {
 
   @Override
   protected void before() throws Throwable {
-    db.start();
+    truncateTables();
   }
 
   @Override
@@ -104,7 +104,7 @@ public class DbTester extends ExternalResource {
     if (session != null) {
       MyBatis.closeQuietly(session);
     }
-    db.stop();
+    db.close();
   }
 
   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", e);
+      throw new IllegalStateException("Fail to check column");
     }
   }
 
@@ -353,7 +353,7 @@ public class DbTester extends ExternalResource {
       return null;
 
     } catch (Exception e) {
-      throw new IllegalStateException("Fail to get column index", e);
+      throw new IllegalStateException("Fail to get column idnex");
     }
   }
 
@@ -387,7 +387,6 @@ public class DbTester extends ExternalResource {
       }
     } catch (SQLException e) {
       // ignore
-      e.printStackTrace();
     }
   }
 
@@ -420,4 +419,8 @@ public class DbTester extends ExternalResource {
     return db.getDatabase();
   }
 
+  public DatabaseCommands getCommands() {
+    return db.getCommands();
+  }
+
 }
index 93509a42fab4c09dd21c80140c4498e65528137d..3ab4fc413463c195756ba8d79a66dd01be31bd5f 100644 (file)
@@ -41,7 +41,6 @@ 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
@@ -92,11 +91,11 @@ class TestDb {
       db.start();
       if (schemaPath != null) {
         // will fail if not H2
-        if (H2.ID.equals(db.getDialect().getId())) {
+        if (db.getDialect().getId().equals("h2")) {
           ((H2Database) db).executeScript(schemaPath);
         } else {
           db.stop();
-
+          throw new AssumptionViolatedException("Test disabled because it supports only H2");
         }
       }
       isDefault = (schemaPath == null);
@@ -110,12 +109,6 @@ 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());
@@ -124,7 +117,7 @@ class TestDb {
     }
   }
 
-  void stop() {
+  void close() {
     if (!isDefault) {
       db.stop();
     }