Search in sources :

Example 1 with JndiDatabaseTester

use of org.dbunit.JndiDatabaseTester 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

InputStream (java.io.InputStream)1 JndiDatabaseTester (org.dbunit.JndiDatabaseTester)1 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)1 FlatXmlDataSetBuilder (org.dbunit.dataset.xml.FlatXmlDataSetBuilder)1