diff options
author | David Gageot <david@gageot.net> | 2012-07-04 13:06:57 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-07-04 13:06:57 +0200 |
commit | 21d23cba20b5daa0c53f620541f0b8511061ab28 (patch) | |
tree | 89d71b46fb8529d765b808b5a62ad1bd9cfa4196 | |
parent | f7df95a76e8ed82dc63761255779291f91551a08 (diff) | |
download | sonarqube-21d23cba20b5daa0c53f620541f0b8511061ab28.tar.gz sonarqube-21d23cba20b5daa0c53f620541f0b8511061ab28.zip |
More stable dao tests
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/persistence/DaoTestCase.java | 20 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java | 21 |
2 files changed, 20 insertions, 21 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/DaoTestCase.java b/sonar-core/src/test/java/org/sonar/core/persistence/DaoTestCase.java index bd26337937a..0a6c5dc8712 100644 --- a/sonar-core/src/test/java/org/sonar/core/persistence/DaoTestCase.java +++ b/sonar-core/src/test/java/org/sonar/core/persistence/DaoTestCase.java @@ -62,19 +62,17 @@ public abstract class DaoTestCase { settings.setProperties(Maps.fromProperties(System.getProperties())); boolean hasDialect = settings.hasKey("sonar.jdbc.dialect"); - if ((null == database) || (hasDialect)) { // Create database only once per vm (Only for in mempry database) - if (hasDialect) { - database = new DefaultDatabase(settings); - } else { - database = new H2Database(); - } - database.start(); + if (hasDialect) { + database = new DefaultDatabase(settings); + } else { + database = new H2Database(); + } + database.start(); - myBatis = new MyBatis(database); - myBatis.start(); + myBatis = new MyBatis(database); + myBatis.start(); - databaseCommands = DatabaseCommands.forDialect(database.getDialect()); - } + databaseCommands = DatabaseCommands.forDialect(database.getDialect()); } @Before diff --git a/sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java b/sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java index 732da687b79..58afe6240ce 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java +++ b/sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java @@ -66,15 +66,13 @@ public abstract class AbstractDbUnitTestCase { @BeforeClass public static void startDatabase() throws Exception { - if (null == database) { // Create only once per vm - database = new H2Database(); - database.start(); + database = new H2Database(); + database.start(); - dbConnector = new MemoryDatabaseConnector(database); - dbConnector.start(); + dbConnector = new MemoryDatabaseConnector(database); + dbConnector.start(); - databaseCommands = DatabaseCommands.forDialect(database.getDialect()); - } + databaseCommands = DatabaseCommands.forDialect(database.getDialect()); } @Before @@ -88,12 +86,15 @@ public abstract class AbstractDbUnitTestCase { @After public void stopConnection() throws Exception { - databaseTester.onTearDown(); - // Important: close the connection and session, otherwise tests can stuck + if (databaseTester != null) { + databaseTester.onTearDown(); + } if (connection != null) { connection.close(); } - session.stop(); + if (session != null) { + session.stop(); + } } public DatabaseSession getSession() { |