use of org.dbunit.dataset.IDataSet in project sonarqube by SonarSource.
the class AbstractDbTester method prepareDbUnit.
private void prepareDbUnit(InputStream... dataSetStream) {
IDatabaseConnection connection = null;
try {
IDataSet[] dataSets = new IDataSet[dataSetStream.length];
for (int i = 0; i < dataSetStream.length; i++) {
dataSets[i] = dbUnitDataSet(dataSetStream[i]);
}
db.getDbUnitTester().setDataSet(new CompositeDataSet(dataSets));
connection = dbUnitConnection();
new InsertIdentityOperation(DatabaseOperation.INSERT).execute(connection, db.getDbUnitTester().getDataSet());
} catch (Exception e) {
throw translateException("Could not setup DBUnit data", e);
} finally {
closeQuietly(connection);
}
}
use of org.dbunit.dataset.IDataSet in project sharding-jdbc by dangdangdotcom.
the class AbstractDBUnitTest method importDataSet.
@Before
public final void importDataSet() throws Exception {
for (String each : getDataSetFiles()) {
InputStream is = AbstractDBUnitTest.class.getClassLoader().getResourceAsStream(each);
IDataSet dataSet = new FlatXmlDataSetBuilder().build(new InputStreamReader(is));
IDatabaseTester databaseTester = new ShardingJdbcDatabaseTester(dbEnv.getDriverClassName(), dbEnv.getURL(getFileName(each)), dbEnv.getUsername(), dbEnv.getPassword());
databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT);
databaseTester.setDataSet(dataSet);
databaseTester.onSetup();
}
}
use of org.dbunit.dataset.IDataSet in project ORCID-Source by ORCID.
the class DBUnitTest method getDataSet.
public static IDataSet getDataSet(String flatXMLDataFile) {
FlatXmlDataFileLoader loader = new FlatXmlDataFileLoader();
loader.getBuilder().setColumnSensing(true);
IDataSet ds = loader.load(flatXMLDataFile);
return ds;
}
use of org.dbunit.dataset.IDataSet in project SSM by Intel-bigdata.
the class TestDBAdapter method testGetFileIds.
@Test
public void testGetFileIds() throws Exception {
createTables(databaseTester.getConnection());
IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("files.xml"));
databaseTester.setDataSet(dataSet);
databaseTester.onSetup();
DBAdapter dbAdapter = new DBAdapter(databaseTester.getConnection().getConnection());
List<String> paths = Arrays.asList("file1", "file2", "file3");
Map<String, Long> pathToID = dbAdapter.getFileIDs(paths);
Assert.assertTrue(pathToID.get("file1") == 101);
Assert.assertTrue(pathToID.get("file2") == 102);
Assert.assertTrue(pathToID.get("file3") == 103);
}
use of org.dbunit.dataset.IDataSet in project SSM by Intel-bigdata.
the class TestDBAdapter method testCreateProportionView.
@Test
public void testCreateProportionView() throws Exception {
Statement statement = databaseTester.getConnection().getConnection().createStatement();
statement.execute(AccessCountTable.createTableSQL("table1"));
statement.execute(AccessCountTable.createTableSQL("table2"));
statement.execute(AccessCountTable.createTableSQL("table3"));
statement.execute(AccessCountTable.createTableSQL("expect"));
IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("accessCountTable.xml"));
databaseTester.setDataSet(dataSet);
databaseTester.onSetup();
AccessCountTable table3 = new AccessCountTable("table3", 0L, 10L, TimeGranularity.SECOND);
DBAdapter dbAdapter = new DBAdapter(databaseTester.getConnection().getConnection());
// 50%
AccessCountTable viewTable = new AccessCountTable(0L, 5L);
dbAdapter.createProportionView(viewTable, table3);
ITable actual = databaseTester.getConnection().createTable(viewTable.getTableName());
ITable expect = databaseTester.getConnection().createTable(table3.getTableName());
SortedTable sortedActual = new SortedTable(actual, new String[] { "fid" });
sortedActual.setUseComparable(true);
Assert.assertTrue(sortedActual.getRowCount() == expect.getRowCount());
for (int i = 0; i < expect.getRowCount(); i++) {
Integer actualAC = (Integer) sortedActual.getValue(i, AccessCountTable.ACCESSCOUNT_FIELD);
Integer expectAC = (Integer) expect.getValue(i, AccessCountTable.ACCESSCOUNT_FIELD);
Assert.assertTrue(actualAC == expectAC / 2);
}
}
Aggregations