use of org.dbunit.dataset.xml.FlatXmlDataSetBuilder in project RecordManager2 by moravianlibrary.
the class DBUnitHelper method init.
public void init(String resourceFile) throws Exception {
try (Connection connection = dataSource.getConnection()) {
IDatabaseConnection conn = new DatabaseConnection(connection);
InputStream is = DBUnitHelper.class.getClassLoader().getResourceAsStream(resourceFile);
FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
builder.setColumnSensing(true);
FlatXmlDataSet dataset = builder.build(is);
truncateTables();
DatabaseOperation.CLEAN_INSERT.execute(conn, dataset);
}
}
use of org.dbunit.dataset.xml.FlatXmlDataSetBuilder in project stdlib by petergeneric.
the class DbunitModuleTest method test.
@Test
public void test() throws Exception {
// DB is initially empty
new DbUnitAssert().assertEquals(new FlatXmlDataSetBuilder().build(new StringReader("<dataset><SimpleEntity/><GroupEntity/><simple_entity_join_table/></dataset>")), dataset.get());
// Add some db contents
try (HibernateTransaction tx = txutils.start().withAutoCommit()) {
dao.save(new SimpleEntity(1, "alice", new GroupEntity(1), new GroupEntity(2)));
dao.save(new SimpleEntity(2, "bob"));
dao.save(new SimpleEntity(3, "carol"));
dao.save(new SimpleEntity(4, "dave"));
}
// DB should now have 4 rows
FlatXmlDataSet expected = new FlatXmlDataSetBuilder().build(this.getClass().getResourceAsStream("/com/peterphi/std/guice/hibernatetest/alice-bob-carol-dave-dataset.xml"));
new DbUnitAssert().assertEquals(expected, dataset.get());
}
use of org.dbunit.dataset.xml.FlatXmlDataSetBuilder in project activityinfo by bedatadriven.
the class DbUnit method loadDatset.
public void loadDatset(URL resource) throws Throwable {
InputStream in = Resources.asByteSource(resource).openStream();
Preconditions.checkNotNull("Cannot find xml file " + resource);
LowerCaseDataSet dataSet = new LowerCaseDataSet(new FlatXmlDataSetBuilder().setDtdMetadata(true).setColumnSensing(true).build(new InputStreamReader(in)));
IDatabaseConnection dbUnitConnection = new MySqlConnection(connection, null);
InsertIdentityOperation.INSERT.execute(dbUnitConnection, dataSet);
}
use of org.dbunit.dataset.xml.FlatXmlDataSetBuilder in project ovirt-engine by oVirt.
the class BaseDaoTestCase method initDataSet.
protected static IDataSet initDataSet() throws Exception {
FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
builder.setColumnSensing(true);
return builder.build(BaseDaoTestCase.class.getResourceAsStream("/fixtures.xml"));
}
use of org.dbunit.dataset.xml.FlatXmlDataSetBuilder in project sharding-jdbc by shardingjdbc.
the class AbstractSQLAssertTest method importAllDataSet.
protected static void importAllDataSet(final List<String> dataSetFiles) throws Exception {
for (DatabaseType databaseType : getDatabaseTypes()) {
DatabaseEnvironment dbEnv = new DatabaseEnvironment(databaseType);
for (String each : dataSetFiles) {
InputStream is = AbstractSQLTest.class.getClassLoader().getResourceAsStream(each);
IDataSet dataSet = new FlatXmlDataSetBuilder().build(new InputStreamReader(is));
IDatabaseTester databaseTester = new ShardingJdbcDatabaseTester(dbEnv.getDriverClassName(), dbEnv.getURL(getDatabaseName(each)), dbEnv.getUsername(), dbEnv.getPassword(), dbEnv.getSchema(getDatabaseName(each)));
databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT);
databaseTester.setDataSet(dataSet);
databaseTester.onSetup();
}
}
}
Aggregations