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


Java FlatXmlDataSetBuilder类代码示例

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


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

示例1: dropTables

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的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: insertData

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:servicecatalog,项目名称:development,代码行数:29,代码来源:DatabaseTaskHandler.java

示例3: initEntityManager

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的package包/类
/**
 * Set up memory database and insert data from test-dataset.xml
 * 
 * @throws DatabaseUnitException
 * @throws HibernateException
 * @throws SQLException
 */
@BeforeClass
public static void initEntityManager() throws HibernateException, DatabaseUnitException, SQLException {
    entityManagerFactory = Persistence.createEntityManagerFactory("listing-test-db");
    entityManager = entityManagerFactory.createEntityManager();
    connection = new DatabaseConnection(((SessionImpl) (entityManager.getDelegate())).connection());
    connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());

    InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(datasetXml);
    if (inputStream != null) {
        FlatXmlDataSetBuilder flatXmlDataSetBuilder = new FlatXmlDataSetBuilder();
        flatXmlDataSetBuilder.setColumnSensing(true);
        dataset = flatXmlDataSetBuilder.build(inputStream);
        DatabaseOperation.CLEAN_INSERT.execute(connection, dataset);
    }
}
 
开发者ID:coodoo-io,项目名称:coodoo-listing,代码行数:23,代码来源:AbstractDbUnitTest.java

示例4: setUp

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    initialDataSet = new FlatXmlDataSetBuilder().build(new File("src/test/resources/test-data.xml"));
    connection = new DatabaseConnection(DriverManager.getConnection(CONNECTION_URL, USER_NAME, PASSWORD));

    final DatabaseOperation operation = DatabaseOperation.CLEAN_INSERT;
    operation.execute(connection, initialDataSet);

    connection.getConnection().createStatement().execute(
            "insert into XML_TABLE_1(id, version, value_1, value_2, value_3, value_4, value_5) values(10, 'Record 10 version', 'Record 10 Value 1', 'Record 10 Value 2', 'Record 10 Value 3', 'Record 10 Value 4', 'Record 10 Value 5');");
    connection.getConnection().commit();

    connection.getConnection().createStatement().execute(
            "merge into XML_TABLE_3(id, version, value_8, value_9) values(11, 'Record 11 version', 'Record 11 Value 8', 'Record 11 Value 9');");
    connection.getConnection().commit();

    assertThat(getRecordCountFromTable(connection, "XML_TABLE_1"), equalTo(4));
    assertThat(getRecordCountFromTable(connection, "XML_TABLE_2"), equalTo(1));
    assertThat(getRecordCountFromTable(connection, "XML_TABLE_3"), equalTo(1));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:21,代码来源:CleanupStrategyProviderTest.java

示例5: beforeTestMethod

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的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

示例6: from

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的package包/类
/**
 * @author Wasiq B
 * @since 24-Nov-2015 8:10:47 pm
 * @param file
 * @return {@link DataSetBuilder}
 * @throws FrameworkException
 */
public DataSetBuilder from (final String file) throws FrameworkException {
	log.entry ();
	try {
		final FlatXmlDataSetBuilder build = new FlatXmlDataSetBuilder ();
		build.setColumnSensing (true);
		final IDataSet dataSet = build
				.build (new File (FileUtils.getResource (file).getPath ()));
		setDataSet (dataSet);
		return this;
	}
	catch (final Exception e) {
		log.catching (e);
		throw new FrameworkException ("from", e);
	}
	finally {
		log.exit ();
	}
}
 
开发者ID:WasiqB,项目名称:xtesy-framework,代码行数:26,代码来源:DataSetBuilder.java

示例7: verifyResultContent

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的package包/类
protected void verifyResultContent(String queryFolder) throws Exception {
    logger.info("---------- verify result content in folder: " + queryFolder);

    List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
    for (File sqlFile : sqlFiles) {
        String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
        String sql = getTextFromFile(sqlFile);

        File expectResultFile = new File(sqlFile.getParent(), sqlFile.getName() + ".expected.xml");
        IDataSet expect = new FlatXmlDataSetBuilder().build(expectResultFile);
        // Get expected table named "expect". FIXME Only support default table name
        ITable expectTable = expect.getTable("expect");

        // execute Kylin
        logger.info("Query Result from Kylin - " + queryName + "  (" + queryFolder + ")");
        IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
        ITable kylinTable = executeQuery(kylinConn, queryName, sql, false);

        // compare the result
        assertTableEquals(expectTable, kylinTable);
    }
}
 
开发者ID:apache,项目名称:kylin,代码行数:23,代码来源:KylinTestBase.java

示例8: setupDB

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的package包/类
@BeforeClass
public static void setupDB() throws Exception {
  ds = UnitTestDSProvider.getDataSource();
  //clean any existing records and load some records into the database.
  FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
  builder.setColumnSensing(true);
  Connection setup = ds.getConnection();
  IDatabaseConnection con = new DatabaseConnection(setup);
  {
    InputStream xmlInput = DeviceDAOImplTest.class.getResourceAsStream("/data/app-data-1.xml");
    IDataSet dataSet = builder.build(xmlInput);
    DatabaseOperation.CLEAN_INSERT.execute(con, dataSet);
  }
  // load test encryptor class
  Class.forName(EncryptorForTest.class.getName());
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:17,代码来源:AppTest.java

示例9: loadDatasource

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的package包/类
private void loadDatasource(DBUnitDataSet annotation, TestContext testContext) throws Exception{
	DataSource dataSource = testContext.getApplicationContext().getBean(DataSource.class);
	IDatabaseTester databaseTester = new DataSourceDatabaseTester(dataSource, "PUBLIC");	
	
	//Ignore referential integrity so DBUnit can correctly delete rows related to the data set
	dataSource.getConnection().createStatement().execute("SET DATABASE REFERENTIAL INTEGRITY FALSE;");

	for(String sourceFile : annotation.value()){
		InputStream input = this.getClass().getResourceAsStream(sourceFile);
		FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
		builder.setColumnSensing(true);
		IDataSet ds = builder.build(input);
		databaseTester.setDataSet(ds);
		databaseTester.onSetup();			
	}
	
	//Add Referential constraints back in, now that the dbunit setup is complete
	dataSource.getConnection().createStatement().execute("SET DATABASE REFERENTIAL INTEGRITY TRUE;");
}
 
开发者ID:jacobhyphenated,项目名称:TaskList,代码行数:20,代码来源:DBUnitTestExecutionListener.java

示例10: FlatXmlDataSetBuilder

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的package包/类
@Test
@DatabaseSetup("EmployeeRepositoryTest_findAll_000_data.xml")
public void findAllのテスト() throws Exception {

    // 期待値
    FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
    String expedtedFile = "EmployeeRepositoryTest_findAll_000_expected.xml";
    IDataSet expectedDataSet = builder.build(
            new InputSource(resolvePhysicalDirectory(getClass()) + expedtedFile));

    // テスト対象メソッド実行
    List<Employee> actual = sut.findAll();

    // DataSetに変換
    IDataSet actualdDataSet = new BeanListConverter(actual).convert();

    // assert
    Assertion.assertEquals(expectedDataSet, actualdDataSet);
}
 
开发者ID:matsumana,项目名称:spring-doma-junit4-dbunit-sample,代码行数:20,代码来源:EmployeeRepositoryTest.java

示例11: initializeGlobalDataFile

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的package包/类
/**
 * Initialize.
 *
 * @param context
 *            the context
 * @param dataSource
 *            the data source
 * @throws DatabaseUnitException
 *             the database unit exception
 * @throws SQLException
 *             the SQL exception
 * @throws MalformedURLException
 *             the malformed url exception
 */
public void initializeGlobalDataFile(ApplicationContext context)
		throws DatabaseUnitException, SQLException, MalformedURLException {
	DataSource datas = GlobalUtils.findDataSourceBean(context);
	IDatabaseConnection con = new DatabaseConnection(datas.getConnection()); // Create
																				// DBUnit
																				// Database
																				// connection
	FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
	builder.setColumnSensing(true);

	datasets = new IDataSet[] { builder.build(singleInitXmlFile) };
	DatabaseOperation.REFRESH.execute(con, new CompositeDataSet(datasets)); // Import
																			// your
																			// data

	// TODO handle the empty data file case.
	con.close();

}
 
开发者ID:bigtester,项目名称:automation-test-engine,代码行数:34,代码来源:TestDatabaseInitializer.java

示例12: tearDownDB

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的package包/类
@AfterClass
public static void tearDownDB() {
    System.out.println("Tearing down DB");
    try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("context.xml")) {
        IDatabaseConnection connection = new DatabaseDataSourceConnection(
                (DataSource) applicationContext.getBean("dataSource"));

        try {
            DatabaseOperation.DELETE_ALL.execute(connection,
                    new FlatXmlDataSetBuilder().build(
                            applicationContext.getResource("/database_tear_down.xml").getInputStream()));
        } finally {
            connection.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:osiam,项目名称:test-suites,代码行数:19,代码来源:PerformanceTestContext.java

示例13: setupDb

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的package包/类
public static void setupDb() {
    try (ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("context.xml")) {
        IDatabaseConnection connection = new DatabaseDataSourceConnection(
                (DataSource) applicationContext.getBean("dataSource"));

        try {
            DatabaseOperation.CLEAN_INSERT.execute(connection,
                    new FlatXmlDataSetBuilder().build(
                            applicationContext.getResource("/database_seed_minimal.xml").getInputStream()));
        } finally {
            connection.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:osiam,项目名称:test-suites,代码行数:17,代码来源:TestDataCreation.java

示例14: test

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的package包/类
@Test
public void test() throws Exception
{
	// DB is initially empty
	new DbUnitAssert().assertEquals(new FlatXmlDataSetBuilder().build(new StringReader("<dataset><SimpleEntity/><GroupEntity/><simple_entity_join_table/></dataset>")),
	                                dataset.get());

	// Add some db contents
	try (HibernateTransaction tx = txutils.start().withAutoCommit())
	{
		dao.save(new SimpleEntity(1, "alice", new GroupEntity(1), new GroupEntity(2)));
		dao.save(new SimpleEntity(2, "bob"));
		dao.save(new SimpleEntity(3, "carol"));
		dao.save(new SimpleEntity(4, "dave"));
	}

	// DB should now have 4 rows
	FlatXmlDataSet expected = new FlatXmlDataSetBuilder().build(this.getClass()
	                                                                .getResourceAsStream("/com/peterphi/std/guice/hibernatetest/alice-bob-carol-dave-dataset.xml"));
	new DbUnitAssert().assertEquals(expected, dataset.get());
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:22,代码来源:DbunitModuleTest.java

示例15: execute

import org.dbunit.dataset.xml.FlatXmlDataSetBuilder; //导入依赖的package包/类
/**
 * 对XML文件中的数据在H2数据库中执行Operation.
 * 
 * @param xmlFilePaths 符合Spring Resource路径格式的文件列表.
 */
private static void execute(DatabaseOperation operation, DataSource dataSource, String... xmlFilePaths)
		throws DatabaseUnitException, SQLException {
	//注意这里HardCode了使用H2的Connetion
	IDatabaseConnection connection = new H2Connection(dataSource.getConnection(), null);

	for (String xmlPath : xmlFilePaths) {
		try {
			InputStream input = resourceLoader.getResource(xmlPath).getInputStream();
			IDataSet dataSet = new FlatXmlDataSetBuilder().setColumnSensing(true).build(input);
			operation.execute(connection, dataSet);
		} catch (IOException e) {
			logger.warn(xmlPath + " file not found", e);
		}finally{
			connection.close();
		}
	}
}
 
开发者ID:extion,项目名称:base-framework,代码行数:23,代码来源:Fixtures.java


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