Search in sources :

Example 16 with FlatXmlDataSetBuilder

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);
    }
}
Also used : FlatXmlDataSet(org.dbunit.dataset.xml.FlatXmlDataSet) InputStream(java.io.InputStream) Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder)

Example 17 with FlatXmlDataSetBuilder

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());
}
Also used : FlatXmlDataSet(org.dbunit.dataset.xml.FlatXmlDataSet) DbUnitAssert(org.dbunit.assertion.DbUnitAssert) HibernateTransaction(com.peterphi.std.guice.hibernate.module.HibernateTransaction) StringReader(java.io.StringReader) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder) Test(org.junit.Test)

Example 18 with FlatXmlDataSetBuilder

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);
}
Also used : LowerCaseDataSet(org.dbunit.dataset.LowerCaseDataSet) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) MySqlConnection(org.dbunit.ext.mysql.MySqlConnection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder)

Example 19 with FlatXmlDataSetBuilder

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"));
}
Also used : FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder)

Example 20 with FlatXmlDataSetBuilder

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();
        }
    }
}
Also used : DatabaseEnvironment(io.shardingjdbc.core.common.env.DatabaseEnvironment) DatabaseType(io.shardingjdbc.core.constant.DatabaseType) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IDatabaseTester(org.dbunit.IDatabaseTester) IDataSet(org.dbunit.dataset.IDataSet) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder) ShardingJdbcDatabaseTester(io.shardingjdbc.core.common.env.ShardingJdbcDatabaseTester)

Aggregations

FlatXmlDataSetBuilder (org.dbunit.dataset.xml.FlatXmlDataSetBuilder)22 Connection (java.sql.Connection)9 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)8 InputStream (java.io.InputStream)7 InputStreamReader (java.io.InputStreamReader)7 IDataSet (org.dbunit.dataset.IDataSet)7 DatabaseEnvironment (io.shardingjdbc.core.common.env.DatabaseEnvironment)6 ITable (org.dbunit.dataset.ITable)6 File (java.io.File)4 PreparedStatement (java.sql.PreparedStatement)3 IDatabaseTester (org.dbunit.IDatabaseTester)3 DatabaseConnection (org.dbunit.database.DatabaseConnection)3 ReplacementDataSet (org.dbunit.dataset.ReplacementDataSet)3 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)3 MySqlConnection (org.dbunit.ext.mysql.MySqlConnection)3 ShardingJdbcDatabaseTester (io.shardingjdbc.core.common.env.ShardingJdbcDatabaseTester)2 DatabaseType (io.shardingjdbc.core.constant.DatabaseType)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 FilteredDataSet (org.dbunit.dataset.FilteredDataSet)2