Java Code Examples for org.dbunit.dataset.ReplacementDataSet#addReplacementObject()

The following examples show how to use org.dbunit.dataset.ReplacementDataSet#addReplacementObject() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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 16
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 17
Source File: DataSetLoaderProvider.java    From jpa-unit with Apache License 2.0 4 votes vote down vote up
private IDataSet defineReplaceableExpressions(final IDataSet dataSet) {
    final ReplacementDataSet replacementDataSet = new ReplacementDataSet(dataSet);
    replacementDataSet.addReplacementObject("[null]", null);
    replacementDataSet.addReplacementObject("[NULL]", null);
    return replacementDataSet;
}
 
Example 18
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 19
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 20
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);
}