aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-07-09 17:48:18 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-07-09 18:21:46 +0200
commit61ef36129b56cf7154446fbeb0b4231be189d275 (patch)
tree897226bf505c6b016ee6f1a6f5fb10a5567b2268 /sonar-core/src
parent1e207b3b6de3382938c710a7c6135be4ce849219 (diff)
downloadsonarqube-61ef36129b56cf7154446fbeb0b4231be189d275.tar.gz
sonarqube-61ef36129b56cf7154446fbeb0b4231be189d275.zip
Add methods checkColumns() to dbunit helpers
Diffstat (limited to 'sonar-core/src')
-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.java28
2 files changed, 41 insertions, 13 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 9222fcd2392..39926b21b6f 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
@@ -33,11 +33,7 @@ import org.dbunit.dataset.ITable;
import org.dbunit.dataset.ReplacementDataSet;
import org.dbunit.dataset.filter.DefaultColumnFilter;
import org.dbunit.dataset.xml.FlatXmlDataSet;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
+import org.junit.*;
import org.sonar.api.config.Settings;
import java.io.InputStream;
@@ -133,7 +129,7 @@ public abstract class AbstractDaoTestCase {
}
protected void checkTables(String testName, String... tables) {
- checkTables(testName, new String[] {}, tables);
+ checkTables(testName, new String[]{}, tables);
}
protected void checkTables(String testName, String[] excludedColumnNames, String... tables) {
@@ -151,6 +147,24 @@ public abstract class AbstractDaoTestCase {
}
}
+ /**
+ * Opposite of {@link #checkTables(String, String[], String...)}.
+ */
+ protected void checkColumns(String testName, String table, String... columns) {
+ try {
+ IDataSet dataSet = getCurrentDataSet();
+ 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 (DataSetException e) {
+ throw translateException("Error while checking columns", e);
+ } catch (DatabaseUnitException e) {
+ fail(e.getMessage());
+ }
+ }
+
protected void assertEmptyTables(String... emptyTables) {
for (String table : emptyTables) {
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 78d9fe4164e..3efe742f307 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
@@ -19,8 +19,6 @@
*/
package org.sonar.jpa.test;
-import org.junit.AfterClass;
-
import org.apache.commons.io.IOUtils;
import org.dbunit.Assertion;
import org.dbunit.DataSourceDatabaseTester;
@@ -28,16 +26,13 @@ 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.dbunit.ext.h2.H2DataTypeFactory;
import org.dbunit.operation.DatabaseOperation;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.sonar.api.database.DatabaseSession;
@@ -185,6 +180,25 @@ public abstract class AbstractDbUnitTestCase {
}
}
+ /**
+ * Opposite of {@link #checkTables(String, String[], String...)}.
+ */
+ protected void checkColumns(String testName, String table, String... columns) {
+ getSession().commit();
+ try {
+ IDataSet dataSet = getCurrentDataSet();
+ 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 (DataSetException e) {
+ throw translateException("Error while checking columns", e);
+ } catch (DatabaseUnitException e) {
+ fail(e.getMessage());
+ }
+ }
+
private IDataSet getExpectedData(String testName) {
String className = getClass().getName();
className = String.format("/%s/%s-result.xml", className.replace(".", "/"), testName);