Search in sources :

Example 1 with FlatXmlDataSetBuilder

use of org.dbunit.dataset.xml.FlatXmlDataSetBuilder in project head by mifos.

the class MifosIntegrationTestCase method dbVerificationTearDown.

private void dbVerificationTearDown() throws Exception, FileNotFoundException, MalformedURLException {
    if (verifyDatabaseState) {
        Connection connection = StaticHibernateUtil.getSessionTL().connection();
        connection.setAutoCommit(false);
        DatabaseConnection dbUnitConnection = new DatabaseConnection(connection);
        IDataSet upgradeDataDump = new FilteredDataSet(excludeTables, dbUnitConnection.createDataSet());
        String tmpDir = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator");
        FlatXmlDataSet.write(upgradeDataDump, new FileOutputStream(tmpDir + "upgradeDataDump.xml"));
        FlatXmlDataSetBuilder fxmlBuilder = new FlatXmlDataSetBuilder();
        upgradeDataDump = fxmlBuilder.build(new File(tmpDir + "upgradeDataDump.xml"));
        Assertion.assertEquals(latestDataDump, upgradeDataDump);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) Connection(java.sql.Connection) DatabaseConnection(org.dbunit.database.DatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder) File(java.io.File) FilteredDataSet(org.dbunit.dataset.FilteredDataSet)

Example 2 with FlatXmlDataSetBuilder

use of org.dbunit.dataset.xml.FlatXmlDataSetBuilder in project head by mifos.

the class MifosIntegrationTestCase method dbVerificationSetUp.

private void dbVerificationSetUp() throws Exception {
    if (verifyDatabaseState) {
        excludeTables.excludeTable("BATCH_JOB_EXECUTION");
        Connection connection = StaticHibernateUtil.getSessionTL().connection();
        connection.setAutoCommit(false);
        DatabaseConnection dbUnitConnection = new DatabaseConnection(connection);
        latestDataDump = new FilteredDataSet(excludeTables, dbUnitConnection.createDataSet());
        String tmpDir = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator");
        FlatXmlDataSet.write(latestDataDump, new FileOutputStream(tmpDir + "latestDataDump.xml"));
        FlatXmlDataSetBuilder fxmlBuilder = new FlatXmlDataSetBuilder();
        latestDataDump = fxmlBuilder.build(new File(tmpDir + "latestDataDump.xml"));
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) Connection(java.sql.Connection) DatabaseConnection(org.dbunit.database.DatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder) File(java.io.File) FilteredDataSet(org.dbunit.dataset.FilteredDataSet)

Example 3 with FlatXmlDataSetBuilder

use of org.dbunit.dataset.xml.FlatXmlDataSetBuilder in project head by mifos.

the class DbUnitUtilities method getDataSetFromClasspathFile.

public IDataSet getDataSetFromClasspathFile(String filename, String directory) throws IOException, DataSetException {
    ClassPathResource resource = new ClassPathResource(directory + filename);
    File file = resource.getFile();
    if (file == null) {
        throw new FileNotFoundException("Couldn't find file:" + filename);
    }
    FlatXmlDataSetBuilder fb = new FlatXmlDataSetBuilder();
    fb.setColumnSensing(true);
    fb.setDtdMetadata(false);
    return fb.build(file);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 4 with FlatXmlDataSetBuilder

use of org.dbunit.dataset.xml.FlatXmlDataSetBuilder 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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IDatabaseTester(org.dbunit.IDatabaseTester) IDataSet(org.dbunit.dataset.IDataSet) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder) Before(org.junit.Before)

Example 5 with FlatXmlDataSetBuilder

use of org.dbunit.dataset.xml.FlatXmlDataSetBuilder in project microservices by pwillhan.

the class SampleDataImporter method onStartup.

public void onStartup(@Observes @Initialized(ApplicationScoped.class) Object event) throws Exception {
    InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("testdata.xml");
    IDatabaseConnection connection = new JndiDatabaseTester("java:jboss/datasources/ExampleDS").getConnection();
    DatabaseOperation.CLEAN_INSERT.execute(connection, new FlatXmlDataSetBuilder().build(input));
    if (connection != null) {
        try {
            connection.close();
        } catch (Exception ex) {
            ex.printStackTrace(System.err);
        }
    } else {
        System.err.println("Can't import test data, check connection settings!");
    }
}
Also used : InputStream(java.io.InputStream) JndiDatabaseTester(org.dbunit.JndiDatabaseTester) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder)

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