本文整理匯總了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();
}
示例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);
}
示例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);
}
}
示例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));
}
示例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);
}
}
}
示例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 ();
}
}
示例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);
}
}
示例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());
}
示例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;");
}
示例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);
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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());
}
示例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();
}
}
}