Search in sources :

Example 11 with IDataSet

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);
    }
}
Also used : CompositeDataSet(org.dbunit.dataset.CompositeDataSet) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet) InsertIdentityOperation(org.dbunit.ext.mssql.InsertIdentityOperation) SQLException(java.sql.SQLException) DatabaseUnitException(org.dbunit.DatabaseUnitException)

Example 12 with IDataSet

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();
    }
}
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 13 with IDataSet

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;
}
Also used : FlatXmlDataFileLoader(org.dbunit.util.fileloader.FlatXmlDataFileLoader) IDataSet(org.dbunit.dataset.IDataSet)

Example 14 with IDataSet

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);
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) IDataSet(org.dbunit.dataset.IDataSet) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet) Test(org.junit.Test)

Example 15 with IDataSet

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);
    }
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) Statement(java.sql.Statement) SortedTable(org.dbunit.dataset.SortedTable) ITable(org.dbunit.dataset.ITable) IDataSet(org.dbunit.dataset.IDataSet) AccessCountTable(org.smartdata.server.metastore.tables.AccessCountTable) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet) Test(org.junit.Test)

Aggregations

IDataSet (org.dbunit.dataset.IDataSet)54 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)21 DatabaseConnection (org.dbunit.database.DatabaseConnection)16 Test (org.junit.Test)15 ITable (org.dbunit.dataset.ITable)13 Connection (java.sql.Connection)12 FileOutputStream (java.io.FileOutputStream)11 File (java.io.File)10 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)8 XmlDataSet (org.dbunit.dataset.xml.XmlDataSet)8 InputStream (java.io.InputStream)7 InputStreamReader (java.io.InputStreamReader)7 FlatXmlDataSetBuilder (org.dbunit.dataset.xml.FlatXmlDataSetBuilder)7 OutputStreamWriter (java.io.OutputStreamWriter)5 Writer (java.io.Writer)5 IDatabaseTester (org.dbunit.IDatabaseTester)5 FileInputStream (java.io.FileInputStream)4 FlatDtdWriter (org.dbunit.dataset.xml.FlatDtdWriter)4 BaseCwsCmsInMemoryPersistenceTest (gov.ca.cwds.data.legacy.cms.persistence.BaseCwsCmsInMemoryPersistenceTest)3 DatabaseEnvironment (io.shardingjdbc.core.common.env.DatabaseEnvironment)3