当前位置: 首页>>代码示例>>Java>>正文


Java IDataSet类代码示例

本文整理汇总了Java中org.dbunit.dataset.IDataSet的典型用法代码示例。如果您正苦于以下问题:Java IDataSet类的具体用法?Java IDataSet怎么用?Java IDataSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IDataSet类属于org.dbunit.dataset包,在下文中一共展示了IDataSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dropTables

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
public static void dropTables(String filePath) throws DataSetException,
        IOException, SQLException {
    IDataSet tablesToDelete = new FlatXmlDataSetBuilder().build(new File(
            filePath));
    String[] tableNames = tablesToDelete.getTableNames();
    Statement stmt = conn.createStatement();
    String queryString = "DROP TABLE %s CASCADE";
    for (int i = tableNames.length - 1; i >= 0; i--) {
        // first drop constraints to the table
        deleteConstraints(tableNames[i]);

        // now drop the table itself
        String tableName = tableNames[i];
        try {
            String query = String.format(queryString, tableName);
            stmt.executeUpdate(query);
            System.out.println(query);
        } catch (SQLException e) {
            System.out.println(e.getMessage());
        }
    }
    stmt.close();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:24,代码来源:DatabaseTaskHandler.java

示例2: testLoadDataSet_lessColumnsFirst

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
/**
 * Test the loading of a data set with 2 rows for a table, but the first
 * row has less columns than the second one.
 */
@Test
public void testLoadDataSet_lessColumnsFirst() throws Exception {
    MultiSchemaDataSet result = multiSchemaXmlDataSetReader.readDataSetXml(toFile(getClass().getResource("LessColumnsFirstDataSet.xml")));

    // there should be 1 dataset for the default schema A
    assertLenientEquals(new String[]{"SCHEMA_A"}, result.getSchemaNames());

    // the dataset should contain 2 tables with the same name
    IDataSet dataSet = result.getDataSetForSchema("SCHEMA_A");
    assertLenientEquals(new String[]{"TABLE_A"}, dataSet.getTableNames());
    assertEquals(2, dataSet.getTable("TABLE_A").getRowCount());
    ITableIterator tableIterator = dataSet.iterator();

    // first table TABLE_A row should contain 1 column
    assertTrue(tableIterator.next());
    ITable table = tableIterator.getTable();
    assertPropertyLenientEquals("columnName", asList("COLUMN_1", "COLUMN_2", "COLUMN_3"), asList(table.getTableMetaData().getColumns()));
    assertEquals(2, table.getRowCount());
    assertEquals("4", table.getValue(0, "COLUMN_2"));
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:25,代码来源:MultiSchemaXmlDataSetReaderTest.java

示例3: testLoadDataSet_multiSchemaNoDefault

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
/**
 * Test the loading of a data set with 3 schemas:
 * schema A (default) contains 3 records for TABLE_A, schema B and C contain 2 records for TABLE_A.
 */
@Test
public void testLoadDataSet_multiSchemaNoDefault() throws Exception {
    MultiSchemaDataSet result = multiSchemaXmlDataSetReader.readDataSetXml(toFile(getClass().getResource("MultiSchemaNoDefaultDataSet.xml")));

    // there should be 3 schemas
    assertLenientEquals(new String[]{"SCHEMA_A", "SCHEMA_B", "SCHEMA_C"}, result.getSchemaNames());

    // default schema A should contain 3 tables
    IDataSet dataSetA = result.getDataSetForSchema("SCHEMA_A");
    assertLenientEquals(new String[]{"TABLE_A"}, dataSetA.getTableNames());
    assertEquals(3, dataSetA.getTable("TABLE_A").getRowCount());

    // schema B should contain 2 tables
    IDataSet dataSetB = result.getDataSetForSchema("SCHEMA_B");
    assertLenientEquals(new String[]{"TABLE_A"}, dataSetB.getTableNames());
    assertEquals(2, dataSetB.getTable("TABLE_A").getRowCount());

    // schema C should contain 2 tables
    IDataSet dataSetC = result.getDataSetForSchema("SCHEMA_C");
    assertLenientEquals(new String[]{"TABLE_A"}, dataSetC.getTableNames());
    assertEquals(2, dataSetC.getTable("TABLE_A").getRowCount());
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:27,代码来源:MultiSchemaXmlDataSetReaderTest.java

示例4: testLoadDataSet_multiInputStreams

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
/**
 * Test the loading of a data set out of 2 files:
 * this will load the LessColumnsLastDataSet.xml and  LessColumnsFirstDataSet.xml dataset
 */
@Test
public void testLoadDataSet_multiInputStreams() throws Exception {
    File file1 = toFile(getClass().getResource("LessColumnsLastDataSet.xml"));
    File file2 = toFile(getClass().getResource("LessColumnsFirstDataSet.xml"));
    MultiSchemaDataSet result = multiSchemaXmlDataSetReader.readDataSetXml(file1, file2);

    // there should be 1 dataset for the default schema A
    assertLenientEquals(new String[]{"SCHEMA_A"}, result.getSchemaNames());

    // the dataset should contain 4 tables with the same name
    IDataSet dataSet = result.getDataSetForSchema("SCHEMA_A");
    String[] actual = dataSet.getTableNames();
    assertLenientEquals(new String[]{"TABLE_A"}, actual);
    assertEquals(4, dataSet.getTable("TABLE_A").getRowCount());
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:20,代码来源:MultiSchemaXmlDataSetReaderTest.java

示例5: testDeletion

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
/**
 * Tests export.
 */
public void testDeletion() throws Exception {
	File resultDir = new File(testDir, "result");
	if (!resultDir.exists()) {
		resultDir.mkdir();
	}
	File result = null;
	result = new File(resultDir, "delete.sql");
	File insertResult = new File(resultDir, "insert.sql");
	
	if (doDeletion(datamodelDir, new File(testDir, "extractionmodel.csv"), result, insertResult, scope)) {
		Session statementExecutor = new Session(connectionArguments.get(0), connectionArguments.get(1), connectionArguments.get(2), connectionArguments.get(3));
		SqlScriptExecutor.executeScript(result.getCanonicalPath(), statementExecutor);
		statementExecutor.shutDown();
		
		File actualState = new File(resultDir, "remaining-state.xml");
		IDataSet depDataset = getConnection().createDataSet(getDataSet().getTableNames());
		Writer out = new FileWriter(actualState);
	    FlatXmlDataSet.write(depDataset, out, Charset.defaultCharset().name());
	    out.close();

		assertEqualDatasets(expectedResult, actualState);
	}
}
 
开发者ID:P15,项目名称:jailer,代码行数:27,代码来源:DeletionTestCase.java

示例6: assertExpectedDataSets

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
public void assertExpectedDataSets(MultiSchemaDataSet multiSchemaExpectedDataSet, Object testObject) {
    try {
        if (multiSchemaExpectedDataSet == null) {
            // no data set should be compared
            return;
        }
        // first make sure every database update is flushed to the database
        getDatabaseModule().flushDatabaseUpdates(testObject);

        DataSetAssert dataSetAssert = new DataSetAssert();
        for (String schemaName : multiSchemaExpectedDataSet.getSchemaNames()) {
            IDataSet expectedDataSet = multiSchemaExpectedDataSet.getDataSetForSchema(schemaName);
            IDataSet actualDataSet = getActualDataSet(schemaName);

            dataSetAssert.assertEqualDbUnitDataSets(schemaName, expectedDataSet, actualDataSet);
        }
    } finally {
        closeJdbcConnection();
    }

}
 
开发者ID:linux-china,项目名称:unitils,代码行数:22,代码来源:DbUnitModule.java

示例7: customSetup

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
@Before
public void customSetup() throws Exception {
    super.getDatabaseTester().setSchema("linkbinder_test");

    // マスタデータ
    File resource = new File(getPjUserResourceName());
    if (resource.exists()) {
        IDataSet ds = new XlsDataSet(new FileInputStream(resource));
        IDatabaseConnection connection = getConnection();
        try {
            DatabaseOperation.REFRESH.execute(connection, ds);
        } finally {
            closeConnection(connection);
        }
    }

    super.setUp();

}
 
开发者ID:otsecbsol,项目名称:linkbinder,代码行数:20,代码来源:AbstractDaoTestCase.java

示例8: testJsonLoaderLoadUsingProperResource

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
@Test
public void testJsonLoaderLoadUsingProperResource() throws Exception {
    // WHEN
    final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.jsonLoader();

    // THEN
    assertThat(loader, notNullValue());

    // WHEN
    final IDataSet dataSet = loader.load(getFile("test-data.json"));

    // THEN
    assertThat(dataSet, notNullValue());

    final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
    assertThat(tableNames.size(), equalTo(2));
    assertThat(tableNames, hasItems("JSON_TABLE_1", "JSON_TABLE_2"));

    final ITable table1 = dataSet.getTable("JSON_TABLE_1");
    assertThat(table1.getRowCount(), equalTo(3));

    final ITable table2 = dataSet.getTable("JSON_TABLE_2");
    assertThat(table2.getRowCount(), equalTo(1));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:25,代码来源:DataSetLoaderProviderTest.java

示例9: testYamlLoaderLoadUsingProperResource

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
@Test
public void testYamlLoaderLoadUsingProperResource() throws Exception {
    // WHEN
    final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.yamlLoader();

    // THEN
    assertThat(loader, notNullValue());

    // WHEN
    final IDataSet dataSet = loader.load(getFile("test-data.yaml"));

    // THEN
    assertThat(dataSet, notNullValue());

    final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
    assertThat(tableNames.size(), equalTo(2));
    assertThat(tableNames, hasItems("YAML_TABLE_1", "YAML_TABLE_2"));

    final ITable table1 = dataSet.getTable("YAML_TABLE_1");
    assertThat(table1.getRowCount(), equalTo(3));

    final ITable table2 = dataSet.getTable("YAML_TABLE_2");
    assertThat(table2.getRowCount(), equalTo(1));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:25,代码来源:DataSetLoaderProviderTest.java

示例10: testXmlLoaderLoadUsingProperResource

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
@Test
public void testXmlLoaderLoadUsingProperResource() throws Exception {
    // WHEN
    final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.xmlLoader();

    // THEN
    assertThat(loader, notNullValue());

    // WHEN
    final IDataSet dataSet = loader.load(getFile("test-data.xml"));

    // THEN
    assertThat(dataSet, notNullValue());

    final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
    assertThat(tableNames.size(), equalTo(2));
    assertThat(tableNames, hasItems("XML_TABLE_1", "XML_TABLE_2"));

    final ITable table1 = dataSet.getTable("XML_TABLE_1");
    assertThat(table1.getRowCount(), equalTo(3));

    final ITable table2 = dataSet.getTable("XML_TABLE_2");
    assertThat(table2.getRowCount(), equalTo(1));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:25,代码来源:DataSetLoaderProviderTest.java

示例11: beforeTestMethod

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
    DataSetLocation dsLocation = testContext.getTestInstance().getClass().getAnnotation(DataSetLocation.class);
    if (dsLocation != null) {
        String dataSetResourcePath = dsLocation.value();
        Resource dataSetResource = testContext.getApplicationContext().getResource(dataSetResourcePath);

        if (dataSetResource.exists()) {
            IDataSet dataSet = new FlatXmlDataSetBuilder().build(dataSetResource.getInputStream());
            IDatabaseConnection dbConn = new DatabaseDataSourceConnection(
                    testContext.getApplicationContext().getBean(DataSource.class)
            );
            DatabaseOperation.CLEAN_INSERT.execute(dbConn, dataSet);

            LOG.info("Annotated test, using data set: {}", dataSetResourcePath);
        }
    }
}
 
开发者ID:DmitriyLy,项目名称:travel_portal,代码行数:19,代码来源:CleanInsertTestExecutionListener.java

示例12: file

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
@Test
@Ignore("Somehow the given zip file (xlsx) is invalid, even Excel opens it without issues")
public void testXlsxLoaderLoadUsingProperResource() throws Exception {
    // WHEN
    final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.xlsLoader();

    // THEN
    assertThat(loader, notNullValue());

    // WHEN
    final IDataSet dataSet = loader.load(getFile("test-data.xlsx"));

    // THEN
    assertThat(dataSet, notNullValue());

    final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
    assertThat(tableNames.size(), equalTo(2));
    assertThat(tableNames, hasItems("XLS_TABLE_1", "XLS_TABLE_2"));

    final ITable table1 = dataSet.getTable("XLS_TABLE_1");
    assertThat(table1.getRowCount(), equalTo(3));

    final ITable table2 = dataSet.getTable("XLS_TABLE_2");
    assertThat(table2.getRowCount(), equalTo(1));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:26,代码来源:DataSetLoaderProviderTest.java

示例13: testCsvLoaderLoadUsingProperResource

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
@Test
public void testCsvLoaderLoadUsingProperResource() throws Exception {
    // WHEN
    final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.csvLoader();

    // THEN
    assertThat(loader, notNullValue());

    // WHEN
    final IDataSet dataSet = loader.load(getFile("test-data"));

    // THEN
    assertThat(dataSet, notNullValue());

    final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
    assertThat(tableNames.size(), equalTo(2));
    assertThat(tableNames, hasItems("CSV_TABLE_1", "CSV_TABLE_2"));

    final ITable table1 = dataSet.getTable("CSV_TABLE_1");
    assertThat(table1.getRowCount(), equalTo(3));

    final ITable table2 = dataSet.getTable("CSV_TABLE_2");
    assertThat(table2.getRowCount(), equalTo(1));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:25,代码来源:DataSetLoaderProviderTest.java

示例14: testLoadDataSetsUsingAvailableFilePaths

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
@Test
public void testLoadDataSetsUsingAvailableFilePaths() throws DataSetException {
    // GIVEN

    // WHEN
    final List<IDataSet> dataSetList = featureExecutor.loadDataSets(Arrays.asList("test-data.json", "test-data.json"));

    // THEN
    assertNotNull(dataSetList);
    assertThat(dataSetList.size(), equalTo(2));

    final IDataSet ds1 = dataSetList.get(0);
    assertNotNull(ds1);
    assertThat(ds1.getTableNames().length, equalTo(2));

    final IDataSet ds2 = dataSetList.get(0);
    assertNotNull(ds2);
    assertThat(ds2.getTableNames().length, equalTo(2));

    assertThat(ds1, equalTo(ds2));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:22,代码来源:SqlDbFeatureExecutorTest.java

示例15: testVerifyDataAfterFeatureExecution

import org.dbunit.dataset.IDataSet; //导入依赖的package包/类
@Test
public void testVerifyDataAfterFeatureExecution() throws DbFeatureException, SQLException, DataSetException {
    // GIVEN
    final IDataSet currentDs = mock(IDataSet.class);
    when(currentDs.getTableNames()).thenReturn(new String[] {});
    when(connection.createDataSet()).thenReturn(currentDs);
    when(expectedDataSets.strict()).thenReturn(Boolean.FALSE);
    when(expectedDataSets.value()).thenReturn(new String[] {});
    when(expectedDataSets.orderBy()).thenReturn(new String[] {});
    when(expectedDataSets.excludeColumns()).thenReturn(new String[] {});

    // WHEN
    final DbFeature<IDatabaseConnection> feature = featureExecutor.createVerifyDataAfterFeature(expectedDataSets);
    assertThat(feature, notNullValue());
    feature.execute(connection);

    // THEN
    verify(connection).createDataSet();
    verifyNoMoreInteractions(connection);
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:21,代码来源:SqlDbFeatureExecutorTest.java


注:本文中的org.dbunit.dataset.IDataSet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。