本文整理汇总了Java中org.dbunit.dataset.csv.CsvDataSet类的典型用法代码示例。如果您正苦于以下问题:Java CsvDataSet类的具体用法?Java CsvDataSet怎么用?Java CsvDataSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CsvDataSet类属于org.dbunit.dataset.csv包,在下文中一共展示了CsvDataSet类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: csvLoader
import org.dbunit.dataset.csv.CsvDataSet; //导入依赖的package包/类
@Override
public DataSetLoader<IDataSet> csvLoader() {
return (final File path) -> {
try {
return defineReplaceableExpressions(new CsvDataSet(path));
} catch (final DataSetException e) {
throw new IOException(e);
}
};
}
示例2: readFileToDataSet
import org.dbunit.dataset.csv.CsvDataSet; //导入依赖的package包/类
public IDataSet readFileToDataSet(File datasetResourceFile) throws Exception {
if (datasetResourceFile.getName().endsWith(".flat.xml")) {
return new FlatXmlDataSetBuilder().setColumnSensing(true).build(datasetResourceFile);
} else if (datasetResourceFile.getName().endsWith(".xml")) {
return new XmlDataSet(new FileInputStream(datasetResourceFile));
} else if (datasetResourceFile.getName().endsWith(".xls")) {
return new XlsDataSet(new FileInputStream(datasetResourceFile));
} else if (datasetResourceFile.getName().endsWith(".json")) {
return new JSONDataSet(new FileInputStream(datasetResourceFile));
} else {
return new CsvDataSet(datasetResourceFile);
}
}
示例3: loadDataSet
import org.dbunit.dataset.csv.CsvDataSet; //导入依赖的package包/类
private IDataSet loadDataSet(Fixture.Type type, String resource, Class<?> testClass)
throws DataSetException, URISyntaxException {
switch (type) {
case CSV:
URL url = testClass.getResource(resource);
if (url == null) throw new AssertionError("Can't find resource: " + resource);
return new CsvDataSet(new File(url.toURI()));
case YAML:
InputStream input = getResourceAsStream(testClass, resource);
if (input == null) throw new AssertionError("Can't find resource: " + resource);
return YamlDataSet.load(input);
default:
throw new IllegalArgumentException("Unsupported type: " + type);
}
}
示例4: safelyCsvExportAndImportStandardColumnTables
import org.dbunit.dataset.csv.CsvDataSet; //导入依赖的package包/类
@Test
public void safelyCsvExportAndImportStandardColumnTables()
throws IOException, DatabaseUnitException, SQLException {
IDatabaseConnection dbunit_conn = new DatabaseConnection(conn);
// cache(save) expected data snap-shot.
IDataSet expectedDataSet = new CachedDataSet(
dbunit_conn.createDataSet());
// export only t1, t2 table to CSV
QueryDataSet exportDataSet = new QueryDataSet(dbunit_conn);
exportDataSet.addTable("t1");
exportDataSet.addTable("t2");
CsvDataSetWriter.write(exportDataSet, tmpDir);
// after export, insert new record to t3 (not exported)
new T3("new label").insertMe(conn);
// clear & insert from exported CSV
IDataSet csvDataSet = new CsvDataSet(tmpDir);
DatabaseOperation.CLEAN_INSERT.execute(dbunit_conn, csvDataSet);
IDataSet actualDataSet = dbunit_conn.createDataSet();
Assertion.assertEquals(expectedDataSet.getTable("t1"),
actualDataSet.getTable("t1"));
Assertion.assertEquals(expectedDataSet.getTable("t2"),
actualDataSet.getTable("t2"));
// this produce assertion error : table record will be 3.
// Assertion.assertEquals(expectedDataSet.getTable("t3"),
// actualDataSet.getTable("t3"));
assertEquals(3, actualDataSet.getTable("t3").getRowCount());
}
示例5: loadDataSet
import org.dbunit.dataset.csv.CsvDataSet; //导入依赖的package包/类
/**
* @param name one or more (comma separated) dataset names to instance
* @return loaded dataset (in case of multiple dataSets they will be merged in one using composite dataset)
*/
@Override
public IDataSet loadDataSet(String name) throws DataSetException, IOException {
String[] dataSetNames = name.trim().split(",");
List<IDataSet> dataSets = new ArrayList<>();
for (String dataSet : dataSetNames) {
IDataSet target = null;
String dataSetName = dataSet.trim();
String extension = dataSetName.substring(dataSetName.lastIndexOf('.') + 1).toLowerCase();
switch (extension) {
case "yml": {
target = new ScriptableDataSet(new YamlDataSet(getDataSetStream(dataSetName), dbUnitConfig));
break;
}
case "xml": {
try {
target = new ScriptableDataSet(new FlatXmlDataSetBuilder().build(getDataSetUrl(dataSetName)));
}catch (Exception e) {
target = new ScriptableDataSet(new FlatXmlDataSetBuilder().build(getDataSetStream(dataSetName)));
}
break;
}
case "csv": {
target = new ScriptableDataSet(new CsvDataSet(
new File(getClass().getClassLoader().getResource(dataSetName).getFile()).getParentFile()));
break;
}
case "xls": {
target = new ScriptableDataSet(new XlsDataSet(getDataSetStream(dataSetName)));
break;
}
case "json": {
target = new ScriptableDataSet(new JSONDataSet(getDataSetStream(dataSetName)));
break;
}
default:
log.error("Unsupported dataset extension");
}
if (target != null) {
dataSets.add(target);
}
}
if (dataSets.isEmpty()) {
throw new RuntimeException("No dataset loaded for name " + name);
}
return new CompositeDataSet(dataSets.toArray(new IDataSet[dataSets.size()]));
}