本文整理汇总了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);
}
};
}
开发者ID:dadrus,项目名称:jpa-unit,代码行数:11,代码来源:DataSetLoaderProvider.java
示例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);
}
}
开发者ID:0xC70FF3,项目名称:java-gems,代码行数:14,代码来源:DBMock.java
示例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);
}
}
开发者ID:classmethod,项目名称:cmtest,代码行数:16,代码来源:DbUnitTester.java
示例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());
}
开发者ID:msakamoto-sf,项目名称:javasnack,代码行数:33,代码来源:DbUnitCsvUsageTest.java
示例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()]));
}
开发者ID:database-rider,项目名称:database-rider,代码行数:55,代码来源:DataSetExecutorImpl.java
注:本文中的org.dbunit.dataset.csv.CsvDataSet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论