org.dbunit.dataset.ReplacementDataSet Java Examples

The following examples show how to use org.dbunit.dataset.ReplacementDataSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatabaseTaskHandler.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Inserts the file of the dbUnit compliant flat xml file into the database
 * used by the system.
 * 
 * @param dbSrcFileName
 *            The name of the file to be imported.
 * @throws IOException
 * @throws DataSetException
 * @throws DatabaseUnitException
 * @throws SQLException
 */
public static void insertData(String dbSourceFileLocation)
        throws IOException, DataSetException, DatabaseUnitException,
        SQLException {
    if (dbSourceFileLocation == null) {
        return;
    }
    ReplacementDataSet dataSet = new ReplacementDataSet(
            new FlatXmlDataSetBuilder()
                    .build(new File(dbSourceFileLocation)));
    dataSet.addReplacementObject("[NULL]", null);
    Date now = new Date();
    dataSet.addReplacementObject("[SYSDATE]", Long.valueOf(now.getTime()));
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
    dataSet.addReplacementObject("[SYSTIMESTAMP]", sdf.format(now));

    DatabaseOperation.INSERT.execute(dbConn, dataSet);
}
 
Example #2
Source File: AbstractSQLAssertTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 5 votes vote down vote up
private void executeQueryWithStatement(final ShardingDataSource dataSource, final List<String> parameters, final File file) throws MalformedURLException, SQLException, DatabaseUnitException {
    try (Connection conn = dataSource.getConnection()) {
        String querySql = replaceStatement(sql, parameters.toArray());
        ReplacementDataSet expectedDataSet = new ReplacementDataSet(new FlatXmlDataSetBuilder().build(file));
        expectedDataSet.addReplacementObject("[null]", null);
        for (ITable each : expectedDataSet.getTables()) {
            String tableName = each.getTableMetaData().getTableName();
            ITable actualTable = DBUnitUtil.getConnection(new DataBaseEnvironment(DatabaseType.valueFrom(conn.getMetaData().getDatabaseProductName())), conn)
                    .createQueryTable(tableName, querySql);
            assertEquals(expectedDataSet.getTable(tableName), actualTable);
        }
    }
}
 
Example #3
Source File: FedoraImportTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private ReplacementDataSet database(IDataSet... ds) throws Exception {
    ReplacementDataSet rds = new ReplacementDataSet(new CompositeDataSet(ds));
    rds.addReplacementObject("{$user.home}", "relative/path/");
    Timestamp dbTimestamp = new Timestamp(System.currentTimeMillis());
    rds.addReplacementObject("{$now}", dbTimestamp);
    return rds;
}
 
Example #4
Source File: WorkflowManagerTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private IDataSet database(IDataSet... ds) throws Exception {
    ReplacementDataSet rds = new ReplacementDataSet(new CompositeDataSet(ds));
    rds.addReplacementObject("{$user.home}", "relative/path/");
    Timestamp dbTimestamp = new Timestamp(System.currentTimeMillis());
    rds.addReplacementObject("{$now}", dbTimestamp);
    return rds;
}
 
Example #5
Source File: EmpireBatchDaoTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private IDataSet database(IDataSet... ds) throws Exception {
    ReplacementDataSet rds = new ReplacementDataSet(new CompositeDataSet(ds));
    rds.addReplacementObject("{$user.home}", "relative/path/");
    dbTimestamp = new Timestamp(System.currentTimeMillis());
    rds.addReplacementObject("{$now}", dbTimestamp);
    return rds;
}
 
Example #6
Source File: EmpireWorkflowTaskDaoTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private IDataSet database(IDataSet... ds) throws Exception {
    ReplacementDataSet rds = new ReplacementDataSet(new CompositeDataSet(ds));
    rds.addReplacementObject("{$user.home}", "relative/path/");
    dbTimestamp = new Timestamp(System.currentTimeMillis());
    rds.addReplacementObject("{$now}", dbTimestamp);
    return rds;
}
 
Example #7
Source File: EmpireWorkflowJobDaoTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private IDataSet database(IDataSet... ds) throws Exception {
    ReplacementDataSet rds = new ReplacementDataSet(new CompositeDataSet(ds));
    rds.addReplacementObject("{$user.home}", "relative/path/");
    dbTimestamp = new Timestamp(System.currentTimeMillis());
    rds.addReplacementObject("{$now}", dbTimestamp);
    return rds;
}
 
Example #8
Source File: EmpireWorkflowParameterDaoTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private IDataSet database(IDataSet... ds) throws Exception {
    ReplacementDataSet rds = new ReplacementDataSet(new CompositeDataSet(ds));
    rds.addReplacementObject("{$user.home}", "relative/path/");
    dbTimestamp = new Timestamp(System.currentTimeMillis());
    rds.addReplacementObject("{$now}", dbTimestamp);
    return rds;
}
 
Example #9
Source File: EmpireWorkflowMaterialDaoTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private IDataSet database(IDataSet... ds) throws Exception {
    ReplacementDataSet rds = new ReplacementDataSet(new CompositeDataSet(ds));
    rds.addReplacementObject("{$user.home}", "relative/path/");
    dbTimestamp = new Timestamp(System.currentTimeMillis());
    rds.addReplacementObject("{$now}", dbTimestamp);
    return rds;
}
 
Example #10
Source File: EmpireGroupDaoTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private IDataSet database(IDataSet... ds) throws Exception {
        ReplacementDataSet rds = new ReplacementDataSet(new CompositeDataSet(ds));
//        rds.addReplacementObject("{$user.home}", "relative/path/");
        dbTimestamp = new Timestamp(System.currentTimeMillis());
        rds.addReplacementObject("{$now}", dbTimestamp);
        return rds;
    }
 
Example #11
Source File: AbstractDaoTestCase.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Charge le jeu de données à partir d'un fichier XML d'import
 * @return 
 * @throws java.lang.Exception 
 */
@Override
protected IDataSet getDataSet() throws Exception {
    FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
    builder.setColumnSensing(true);
    ReplacementDataSet dataSet = new ReplacementDataSet(builder.build(new FileInputStream(
            getInputDataFileName())));
    dataSet.addReplacementObject("[NULL]", null);
    return dataSet;
}
 
Example #12
Source File: AbstractTestDAO.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
protected IDataSet createDataSet() throws Exception {
    final FlatXmlDataSet dataSet = new FlatXmlDataSetBuilder()
            //.setColumnSensing(true) // This enables auto discovery of columns but breaks the tests, possibly our data needs clean up
            .build(getClass().getClassLoader().getResourceAsStream(createDataSetFile()));
    final ReplacementDataSet rDataSet = new ReplacementDataSet(dataSet);
    rDataSet.addReplacementObject("[NULL]", null);
    return rDataSet;
}
 
Example #13
Source File: BasePaymentModuleDBTestCase.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
protected IDataSet createDataSet() throws Exception {
    final FlatXmlDataSet dataSet = new FlatXmlDataSetBuilder()
            //.setColumnSensing(true) // This enables auto discovery of columns but breaks the tests, possibly our data needs clean up
            .build(getClass().getClassLoader().getResourceAsStream(createDataSetFile()));
    final ReplacementDataSet rDataSet = new ReplacementDataSet(dataSet);
    rDataSet.addReplacementObject("[NULL]", null);
    return rDataSet;
}
 
Example #14
Source File: SchemaUpgradeTestBase.java    From development with Apache License 2.0 5 votes vote down vote up
protected IDataSet loadDataSet(URL source) throws Exception {
    final FlatXmlDataSetBuilder xmlData = new FlatXmlDataSetBuilder();
    xmlData.setColumnSensing(true);
    final ReplacementDataSet set = new ReplacementDataSet(
            xmlData.build(source));
    set.addReplacementObject("[NULL]", null);
    return set;
}
 
Example #15
Source File: CustomReplacer.java    From database-rider with Apache License 2.0 5 votes vote down vote up
@Override
public void addReplacements(ReplacementDataSet dataSet) {
    dataSet.addReplacementSubstring("FOO", "BAR");
}
 
Example #16
Source File: AbstractSQLAssertTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 5 votes vote down vote up
private void executeQueryWithPreparedStatement(final ShardingDataSource dataSource, final List<String> parameters, final File file)
        throws MalformedURLException, SQLException, DatabaseUnitException {
    try (Connection conn = dataSource.getConnection();
         PreparedStatement preparedStatement = conn.prepareStatement(replacePreparedStatement(sql))) {
        setParameters(preparedStatement, parameters);
        ReplacementDataSet expectedDataSet = new ReplacementDataSet(new FlatXmlDataSetBuilder().build(file));
        expectedDataSet.addReplacementObject("[null]", null);
        for (ITable each : expectedDataSet.getTables()) {
            String tableName = each.getTableMetaData().getTableName();
            ITable actualTable = DBUnitUtil.getConnection(new DataBaseEnvironment(DatabaseType.valueFrom(conn.getMetaData().getDatabaseProductName())), conn)
                    .createTable(tableName, preparedStatement);
            assertEquals(expectedDataSet.getTable(tableName), actualTable);
        }
    }
}
 
Example #17
Source File: DateTimeReplacer.java    From database-rider with Apache License 2.0 5 votes vote down vote up
@Override
public void addReplacements(ReplacementDataSet dataSet) {
    Date currentDate = new Date();
    replaceDays(currentDate, dataSet);
    replaceHours(currentDate, dataSet);
    replaceMinutes(currentDate, dataSet);
    replaceSeconds(currentDate, dataSet);
}
 
Example #18
Source File: EmpireUserDaoTest.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
private IDataSet database(IDataSet... ds) throws Exception {
        ReplacementDataSet rds = new ReplacementDataSet(new CompositeDataSet(ds));
//        rds.addReplacementObject("{$user.home}", "relative/path/");
        rds.addReplacementObject("{$now}", new Timestamp(System.currentTimeMillis()));
        return rds;
    }
 
Example #19
Source File: FedoraImportTest.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testImportItemRepairLinked() throws Exception {
    File batchFolder = temp.newFolder("batch");
    // prepare foxml 1
    LocalObject lobj = localStorage.create(new File(batchFolder, "item1.foxml"));
    lobj.setOwner(fedoraSupport.getTestUser());
    lobj.setLabel("item1");
    RelationEditor locRels = new RelationEditor(lobj);
    locRels.setModel("model:page");
    locRels.write(locRels.getLastModified(), "test");
    lobj.flush();
    // ingested and linked by parent; caused by a following blackout
    remoteStorage.ingest(lobj, fedoraSupport.getTestUser(), "junit");
    // prepare remote parent
    RemoteObject parent = createParent(testName.getMethodName() + "_parent", lobj.getPid());

    ReplacementDataSet db = database(
            dbsupport.loadFlatXmlDataStream(EmpireBatchDaoTest.class, "user.xml"),
            dbsupport.loadFlatXmlDataStream(getClass(), "batch.xml")
    );
    db.addReplacementObject("{$parent_pid}", parent.getPid());
    SqlTransaction tx = daos.createTransaction();
    dbsupport.cleanInsert(dbsupport.getConnection(tx), db);
    tx.commit();

    // add item 1
    Batch batch = ibm.get(1);
    assertNotNull(batch);
    BatchItemObject item1 = ibm.addLocalObject(batch, lobj);
    item1.setState(ObjectState.INGESTED);
    ibm.update(item1);

    // import
    BatchItemObject result = fedoraImport.importItem(
            item1, fedoraSupport.getTestUser(), true);
    // test skipped by repair process
    assertNull(result);
    result = ibm.findBatchObject(batch.getId(), item1.getPid());
    assertEquals(ObjectState.INGESTED, result.getState());

    List<Item> fItems = search.find(lobj.getPid());
    assertEquals(1, fItems.size());
    FedoraTestSupport.assertItem(fItems, lobj.getPid());
}
 
Example #20
Source File: FedoraImportTest.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testImportItemRepairNotLinked() throws Exception {
    File batchFolder = temp.newFolder("batch");
    // prepare foxml 1
    LocalObject lobj = localStorage.create(new File(batchFolder, "item1.foxml"));
    lobj.setOwner(fedoraSupport.getTestUser());
    lobj.setLabel("item1");
    RelationEditor locRels = new RelationEditor(lobj);
    locRels.setModel("model:page");
    locRels.write(locRels.getLastModified(), "test");
    lobj.flush();
    // ingested but not linked by parent; caused by a blackout
    remoteStorage.ingest(lobj, fedoraSupport.getTestUser(), "junit");
    // prepare remote parent
    RemoteObject parent = createParent(testName.getMethodName() + "_parent");

    ReplacementDataSet db = database(
            dbsupport.loadFlatXmlDataStream(EmpireBatchDaoTest.class, "user.xml"),
            dbsupport.loadFlatXmlDataStream(getClass(), "batch.xml")
    );
    db.addReplacementObject("{$parent_pid}", parent.getPid());
    SqlTransaction tx = daos.createTransaction();
    dbsupport.cleanInsert(dbsupport.getConnection(tx), db);
    tx.commit();

    // add item 1
    Batch batch = ibm.get(1);
    assertNotNull(batch);
    BatchItemObject item1 = ibm.addLocalObject(batch, lobj);
    item1.setState(ObjectState.INGESTED);
    ibm.update(item1);

    // import
    BatchItemObject result = fedoraImport.importItem(
            item1, fedoraSupport.getTestUser(), true);
    assertNotNull(result);
    assertEquals(ObjectState.INGESTED, result.getState());
    result = ibm.findBatchObject(batch.getId(), item1.getPid());
    assertEquals(ObjectState.INGESTED, result.getState());

    List<Item> fItems = search.find(lobj.getPid());
    assertEquals(1, fItems.size());
    FedoraTestSupport.assertItem(fItems, lobj.getPid());
}
 
Example #21
Source File: FedoraImportTest.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testImportItemRepairFailure() throws Exception {
    File batchFolder = temp.newFolder("batch");
    // prepare foxml 1
    LocalObject lobj = localStorage.create(new File(batchFolder, "item1.foxml"));
    lobj.setOwner(fedoraSupport.getTestUser());
    lobj.setLabel("item1");
    RelationEditor locRels = new RelationEditor(lobj);
    locRels.setModel("model:page");
    locRels.write(locRels.getLastModified(), "test");
    lobj.flush();
    // prepare remote parent
    RemoteObject parent = createParent(testName.getMethodName() + "_parent");

    ReplacementDataSet db = database(
            dbsupport.loadFlatXmlDataStream(EmpireBatchDaoTest.class, "user.xml"),
            dbsupport.loadFlatXmlDataStream(getClass(), "batch.xml")
    );
    db.addReplacementObject("{$parent_pid}", parent.getPid());
    SqlTransaction tx = daos.createTransaction();
    dbsupport.cleanInsert(dbsupport.getConnection(tx), db);
    tx.commit();

    // add item 1
    Batch batch = ibm.get(1);
    assertNotNull(batch);
    BatchItemObject item1 = ibm.addLocalObject(batch, lobj);
    item1.setState(ObjectState.INGESTING_FAILED);
    item1.setLog("failure");
    ibm.update(item1);

    // import
    BatchItemObject result = fedoraImport.importItem(
            item1, fedoraSupport.getTestUser(), true);
    assertNotNull(result);
    assertEquals(ObjectState.INGESTED, result.getState());
    assertNull(result.getLog());
    result = ibm.findBatchObject(batch.getId(), item1.getPid());
    assertEquals(ObjectState.INGESTED, result.getState());
    assertNull(result.getLog());

    List<Item> fItems = search.find(lobj.getPid());
    assertEquals(1, fItems.size());
    FedoraTestSupport.assertItem(fItems, lobj.getPid());
}
 
Example #22
Source File: FedoraImportTest.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testImportItemFailure() throws Exception {
    File batchFolder = temp.newFolder("batch");
    // prepare foxml 1
    LocalObject lobj = localStorage.create(new File(batchFolder, "item1.foxml"));
    lobj.setOwner(fedoraSupport.getTestUser());
    lobj.setLabel("item1");
    RelationEditor locRels = new RelationEditor(lobj);
    locRels.setModel("model:page");
    locRels.write(locRels.getLastModified(), "test");
    lobj.flush();
    // prepare remote parent
    RemoteObject parent = createParent(testName.getMethodName() + "_parent");

    ReplacementDataSet db = database(
            dbsupport.loadFlatXmlDataStream(EmpireBatchDaoTest.class, "user.xml"),
            dbsupport.loadFlatXmlDataStream(getClass(), "batch.xml")
    );
    db.addReplacementObject("{$parent_pid}", parent.getPid());
    SqlTransaction tx = daos.createTransaction();
    dbsupport.cleanInsert(dbsupport.getConnection(tx), db);
    tx.commit();

    // add item 1
    Batch batch = ibm.get(1);
    assertNotNull(batch);
    BatchItemObject item1 = ibm.addLocalObject(batch, lobj);
    item1.setState(ObjectState.LOADED);
    ibm.update(item1);

    // import deleted foxml
    assertTrue(lobj.getFoxml().delete());
    BatchItemObject result = fedoraImport.importItem(
            item1, fedoraSupport.getTestUser(), false);
    assertNotNull(result);
    assertEquals(ObjectState.INGESTING_FAILED, result.getState());
    assertNotNull(result.getLog());
    result = ibm.findBatchObject(batch.getId(), item1.getPid());
    assertEquals(ObjectState.INGESTING_FAILED, result.getState());
    assertNotNull(result.getLog());

    List<Item> fItems = search.find(lobj.getPid());
    assertEquals(0, fItems.size());
}
 
Example #23
Source File: FedoraImportTest.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testImportItem() throws Exception {
    File batchFolder = temp.newFolder("batch");
    // prepare foxml 1
    LocalObject lobj = localStorage.create(new File(batchFolder, "item1.foxml"));
    lobj.setOwner(fedoraSupport.getTestUser());
    lobj.setLabel("item1");
    RelationEditor locRels = new RelationEditor(lobj);
    locRels.setModel("model:page");
    locRels.write(locRels.getLastModified(), "test");
    lobj.flush();
    // prepare remote parent
    RemoteObject parent = createParent(testName.getMethodName() + "_parent");

    ReplacementDataSet db = database(
            dbsupport.loadFlatXmlDataStream(EmpireBatchDaoTest.class, "user.xml"),
            dbsupport.loadFlatXmlDataStream(getClass(), "batch.xml")
    );
    db.addReplacementObject("{$parent_pid}", parent.getPid());
    SqlTransaction tx = daos.createTransaction();
    dbsupport.cleanInsert(dbsupport.getConnection(tx), db);
    tx.commit();

    // add item 1
    Batch batch = ibm.get(1);
    assertNotNull(batch);
    BatchItemObject item1 = ibm.addLocalObject(batch, lobj);
    item1.setState(ObjectState.LOADED);
    ibm.update(item1);

    // import
    BatchItemObject result = fedoraImport.importItem(
            item1, fedoraSupport.getTestUser(), false);
    assertNotNull(result);
    assertEquals(ObjectState.INGESTED, result.getState());
    result = ibm.findBatchObject(batch.getId(), item1.getPid());
    assertEquals(ObjectState.INGESTED, result.getState());

    List<Item> fItems = search.find(lobj.getPid());
    assertEquals(1, fItems.size());
    FedoraTestSupport.assertItem(fItems, lobj.getPid());
}
 
Example #24
Source File: NullReplacer.java    From database-rider with Apache License 2.0 4 votes vote down vote up
@Override
public void addReplacements(ReplacementDataSet dataSet) {
    dataSet.addReplacementObject("[null]", null);
}
 
Example #25
Source File: UserManagerSqlTest.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
private IDataSet database(IDataSet... ds) throws Exception {
    ReplacementDataSet rds = new ReplacementDataSet(new CompositeDataSet(ds));
    rds.addReplacementObject("{$user.home}", "relative/path/");
    rds.addReplacementObject("{$now}", new Timestamp(System.currentTimeMillis()));
    return rds;
}
 
Example #26
Source File: UnixTimestampReplacer.java    From database-rider with Apache License 2.0 4 votes vote down vote up
@Override
public void addReplacements(ReplacementDataSet dataSet) {
    long timestamp = System.currentTimeMillis() / 1000L;
    dataSet.addReplacementObject("[UNIX_TIMESTAMP]", timestamp);
}
 
Example #27
Source File: EmpireBatchItemDaoTest.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
private IDataSet database(IDataSet... ds) throws Exception {
    ReplacementDataSet rds = new ReplacementDataSet(new CompositeDataSet(ds));
    rds.addReplacementObject("{$user.home}", "relative/path/");
    rds.addReplacementObject("{$now}", new Timestamp(System.currentTimeMillis()));
    return rds;
}
 
Example #28
Source File: TestDatabase.java    From development with Apache License 2.0 4 votes vote down vote up
private IDataSet loadDataSet(URL source) throws Exception {
    final ReplacementDataSet set = new ReplacementDataSet(
            new FlatXmlDataSetBuilder().build(source));
    set.addReplacementObject("[NULL]", null);
    return set;
}
 
Example #29
Source File: DateTimeReplacer.java    From database-rider with Apache License 2.0 4 votes vote down vote up
private void replaceDays(Date currentDate, ReplacementDataSet replacementDataSet) {
    for (DayReplacerType type : DayReplacerType.values()) {
        Date calculatedDate = addDays(currentDate, type.getDays());
        replacementDataSet.addReplacementSubstring(getPlaceholderPattern(type), DateUtils.formatDateTime(calculatedDate));
    }
}
 
Example #30
Source File: DateTimeReplacer.java    From database-rider with Apache License 2.0 4 votes vote down vote up
private void replaceHours(Date currentDate, ReplacementDataSet replacementDataSet) {
    for (HourReplacerType type : HourReplacerType.values()) {
        Date calculatedDate = addHours(currentDate, type.getHours());
        replacementDataSet.addReplacementSubstring(getPlaceholderPattern(type), DateUtils.formatDateTime(calculatedDate));
    }
}