aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-07-13 09:32:02 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-07-13 09:32:02 +0200
commit4223c22d7493e8e1f958cfff44a954ec990d0248 (patch)
tree378162d42ba632eea9cf7e79095fbff65aab7d14 /sonar-core
parentab32fe3e48435896a8ae762174744ccef704c133 (diff)
downloadsonarqube-4223c22d7493e8e1f958cfff44a954ec990d0248.tar.gz
sonarqube-4223c22d7493e8e1f958cfff44a954ec990d0248.zip
Add method checkTable() with list of columns to AbstractDaoTestCase/AbstractDbUnitTestCase
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java26
-rw-r--r--sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java20
2 files changed, 41 insertions, 5 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java b/sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java
index 131af2e70c7..0e56a0f3f72 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java
@@ -28,11 +28,7 @@ import org.dbunit.DatabaseUnitException;
import org.dbunit.IDatabaseTester;
import org.dbunit.database.DatabaseConfig;
import org.dbunit.database.IDatabaseConnection;
-import org.dbunit.dataset.CompositeDataSet;
-import org.dbunit.dataset.DataSetException;
-import org.dbunit.dataset.IDataSet;
-import org.dbunit.dataset.ITable;
-import org.dbunit.dataset.ReplacementDataSet;
+import org.dbunit.dataset.*;
import org.dbunit.dataset.filter.DefaultColumnFilter;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import org.junit.Assert;
@@ -125,6 +121,7 @@ public abstract class AbstractDaoTestCase {
connection.close();
}
} catch (SQLException e) {
+ // ignore
}
}
@@ -153,6 +150,25 @@ public abstract class AbstractDaoTestCase {
}
}
+ protected void checkTable(String testName, String table, String... columns) {
+ IDatabaseConnection connection = null;
+ try {
+ connection = createConnection();
+
+ IDataSet dataSet = connection.createDataSet();
+ IDataSet expectedDataSet = getExpectedData(testName);
+ ITable filteredTable = DefaultColumnFilter.includedColumnsTable(dataSet.getTable(table), columns);
+ ITable filteredExpectedTable = DefaultColumnFilter.includedColumnsTable(expectedDataSet.getTable(table), columns);
+ Assertion.assertEquals(filteredExpectedTable, filteredTable);
+ } catch (DatabaseUnitException e) {
+ fail(e.getMessage());
+ } catch (SQLException e) {
+ throw translateException("Error while checking results", e);
+ } finally {
+ closeQuietly(connection);
+ }
+ }
+
protected void assertEmptyTables(String... emptyTables) {
IDatabaseConnection connection = null;
try {
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 01e0b25b638..9742e0174d8 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
@@ -171,6 +171,26 @@ public abstract class AbstractDbUnitTestCase {
}
}
+ protected void checkTable(String testName, String table, String... columns) {
+ IDatabaseConnection connection = null;
+ try {
+ connection = createConnection();
+
+ IDataSet dataSet = connection.createDataSet();
+ IDataSet expectedDataSet = getExpectedData(testName);
+ ITable filteredTable = DefaultColumnFilter.includedColumnsTable(dataSet.getTable(table), columns);
+ ITable filteredExpectedTable = DefaultColumnFilter.includedColumnsTable(expectedDataSet.getTable(table), columns);
+ Assertion.assertEquals(filteredExpectedTable, filteredTable);
+
+ } catch (DatabaseUnitException e) {
+ fail(e.getMessage());
+ } catch (SQLException e) {
+ throw translateException("Error while checking results", e);
+ } finally {
+ closeQuietly(connection);
+ }
+ }
+
private IDatabaseConnection createConnection() {
try {
IDatabaseConnection connection = databaseTester.getConnection();