org.dbunit.dataset.xml.FlatXmlDataSetBuilder Java Examples
The following examples show how to use
org.dbunit.dataset.xml.FlatXmlDataSetBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataSetBuilderExporterIt.java From database-rider with Apache License 2.0 | 6 votes |
@Test public void shouldExportXMLDataSetUsingColumnValuesSyntax() throws DataSetException { IDataSet iDataSet = new FlatXmlDataSetBuilder().build(getDataSetStream("datasets/xml/users.xml")); File outputDir = Paths.get("target/FromXMlBuilder.java").toAbsolutePath().toFile(); new DataSetBuilderExporter().export(iDataSet, new BuilderExportConfig(BuilderType.COLUMNS_VALUES, outputDir)); assertThat(contentOf(outputDir)).isEqualTo("DataSetBuilder builder = new DataSetBuilder();" + NEW_LINE + "IDataSet dataSet = builder" + NEW_LINE + " .table(\"USER\")" + NEW_LINE + " .columns(\"id\", \"name\")" + NEW_LINE + " .values(\"1\", \"@realpestano\")" + NEW_LINE + " .values(\"2\", \"@dbunit\")" + NEW_LINE + " .table(\"TWEET\")" + NEW_LINE + " .columns(\"id\", \"content\", \"user_id\")" + NEW_LINE + " .values(\"abcdef12345\", \"dbunit rules flat xml example\", \"1\")" + NEW_LINE + " .table(\"FOLLOWER\")" + NEW_LINE + " .columns(\"id\", \"user_id\", \"follower_id\")" + NEW_LINE + " .values(\"1\", \"1\", \"2\").build();"); }
Example #2
Source File: AbstractRuleImplementationTestCase.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
/** * Charge le jeu de données à partir d'un fichier XML d'import * @return * @throws java.lang.Exception */ @Override protected IDataSet getDataSet() throws Exception { if (dataset != null) { return dataset; } if (!getInputDataFileName().isEmpty()) { FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder(); builder.setColumnSensing(true); dataset = builder.build(new File( getInputDataFileName())); return dataset; } else { return null; } }
Example #3
Source File: DatabaseTaskHandler.java From development with Apache License 2.0 | 6 votes |
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(); }
Example #4
Source File: DatabaseTaskHandler.java From development with Apache License 2.0 | 6 votes |
/** * 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); }
Example #5
Source File: KylinTestBase.java From kylin with Apache License 2.0 | 6 votes |
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); } }
Example #6
Source File: DataSourceDBUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenDataSet_whenInsert_thenTableHasNewClient() throws Exception { try (InputStream is = getClass().getClassLoader().getResourceAsStream("dbunit/expected-user.xml")) { // given IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is); ITable expectedTable = expectedDataSet.getTable("CLIENTS"); Connection conn = getDataSource().getConnection(); // when conn.createStatement() .executeUpdate("INSERT INTO CLIENTS (first_name, last_name) VALUES ('John', 'Jansen')"); ITable actualData = getConnection() .createQueryTable("result_name", "SELECT * FROM CLIENTS WHERE last_name='Jansen'"); // then assertEqualsIgnoreCols(expectedTable, actualData, new String[] { "id" }); } }
Example #7
Source File: CleanupStrategyProviderTest.java From jpa-unit with Apache License 2.0 | 6 votes |
@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)); }
Example #8
Source File: DataSourceDBUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenDataSet_whenDelete_thenItemIsDeleted() throws Exception { try (InputStream is = DataSourceDBUnitTest.class.getClassLoader() .getResourceAsStream("dbunit/items_exp_delete.xml")) { // given ITable expectedTable = (new FlatXmlDataSetBuilder().build(is)).getTable("ITEMS"); // when connection.createStatement().executeUpdate("delete from ITEMS where id = 2"); // then IDataSet databaseDataSet = getConnection().createDataSet(); ITable actualTable = databaseDataSet.getTable("ITEMS"); Assertion.assertEquals(expectedTable, actualTable); } }
Example #9
Source File: DataSetBuilderExporterIt.java From database-rider with Apache License 2.0 | 6 votes |
@Test public void shouldExportXMLDataSetUsingDefaultSyntax() throws DataSetException { IDataSet iDataSet = new FlatXmlDataSetBuilder().build(getDataSetStream("datasets/xml/users.xml")); File outputDir = Paths.get("target/FromXMlDefaultBuilder.java").toAbsolutePath().toFile(); new DataSetBuilderExporter().export(iDataSet, new BuilderExportConfig(BuilderType.DEFAULT, outputDir)); assertThat(contentOf(outputDir)).isEqualTo("DataSetBuilder builder = new DataSetBuilder();" + NEW_LINE + "IDataSet dataSet = builder" + NEW_LINE + " .table(\"USER\")" + NEW_LINE + " .row()" + NEW_LINE + " .column(\"id\", \"1\")" + NEW_LINE + " .column(\"name\", \"@realpestano\")" + NEW_LINE + " .row()" + NEW_LINE + " .column(\"id\", \"2\")" + NEW_LINE + " .column(\"name\", \"@dbunit\")" + NEW_LINE + " .table(\"TWEET\")" + NEW_LINE + " .row()" + NEW_LINE + " .column(\"id\", \"abcdef12345\")" + NEW_LINE + " .column(\"content\", \"dbunit rules flat xml example\")" + NEW_LINE + " .column(\"user_id\", \"1\")" + NEW_LINE + " .table(\"FOLLOWER\")" + NEW_LINE + " .row()" + NEW_LINE + " .column(\"id\", \"1\")" + NEW_LINE + " .column(\"user_id\", \"1\")" + NEW_LINE + " .column(\"follower_id\", \"2\").build();"); }
Example #10
Source File: DataSourceDBUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenDataSet_whenInsertUnexpectedData_thenFail() throws Exception { try (InputStream is = getClass().getClassLoader() .getResourceAsStream("dbunit/expected-multiple-failures.xml")) { // given IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is); ITable expectedTable = expectedDataSet.getTable("ITEMS"); Connection conn = getDataSource().getConnection(); DiffCollectingFailureHandler collectingHandler = new DiffCollectingFailureHandler(); // when conn.createStatement().executeUpdate("INSERT INTO ITEMS (title, price) VALUES ('Battery', '1000000')"); ITable actualData = getConnection().createDataSet().getTable("ITEMS"); // then Assertion.assertEquals(expectedTable, actualData, collectingHandler); if (!collectingHandler.getDiffList().isEmpty()) { String message = (String) collectingHandler.getDiffList().stream() .map(d -> formatDifference((Difference) d)).collect(joining("\n")); logger.error(() -> message); } } }
Example #11
Source File: OldSchoolDbUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenDataSet_whenInsert_thenGetResultsAreStillEqualIfIgnoringColumnsWithDifferentProduced() throws Exception { String[] excludedColumns = { "id", "produced" }; try (InputStream is = getClass().getClassLoader() .getResourceAsStream("dbunit/expected-ignoring-registered_at.xml")) { // given IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is); ITable expectedTable = DefaultColumnFilter .excludedColumnsTable(expectedDataSet.getTable("ITEMS"), excludedColumns); // when connection.createStatement() .executeUpdate("INSERT INTO ITEMS (title, price, produced) VALUES('Necklace', 199.99, now())"); // then IDataSet databaseDataSet = tester.getConnection().createDataSet(); ITable actualTable = DefaultColumnFilter .excludedColumnsTable(databaseDataSet.getTable("ITEMS"), excludedColumns); Assertion.assertEquals(expectedTable, actualTable); } }
Example #12
Source File: KylinTestBase.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
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); } }
Example #13
Source File: DatabaseWriterTest.java From LicenseScout with Apache License 2.0 | 6 votes |
/** * Tests {@link DatabaseWriter#writeToDatabase(BuildInfo, List, ExecutionDatabaseConfiguration, ILSLog)}. * * @throws Exception */ @Test public void testWriteDatabase() throws Exception { final ILSLog log = TestUtil.createJavaUtilGlobalLog(); final LicenseStoreData licenseStoreData = TestUtil.readLicenseStoreData(log); final BuildInfo buildInfo = createBuildInformation(); final List<Archive> archives = new ArrayList<>(); final Archive archive1 = createArchive1(licenseStoreData); archives.add(archive1); final Archive archive2 = createArchive2(); archives.add(archive2); final ExecutionDatabaseConfiguration databaseConfiguration = createDatabaseConfiguration(); DatabaseWriter.writeToDatabase(buildInfo, archives, databaseConfiguration, log); final List<String> tablesNamesToCheck = Arrays.asList("Builds", "LibraryData", "DetectedLicenses"); final IDataSet expectedDataSet = new FlatXmlDataSetBuilder() .build(new File("src/test/resources/database/expectedForDatabaseWriterTest.xml")); assertDatabase(expectedDataSet, tablesNamesToCheck); }
Example #14
Source File: OldSchoolDbUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenDataSet_whenDelete_thenItemIsRemoved() throws Exception { try (InputStream is = OldSchoolDbUnitTest.class.getClassLoader() .getResourceAsStream("dbunit/items_exp_delete.xml")) { // given ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("ITEMS"); // when connection.createStatement().executeUpdate("delete from ITEMS where id = 2"); // then IDataSet databaseDataSet = tester.getConnection().createDataSet(); ITable actualTable = databaseDataSet.getTable("ITEMS"); assertEquals(expectedTable, actualTable); } }
Example #15
Source File: OldSchoolDbUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenDataSet_whenProductIgnoredAndDelete_thenItemIsRemoved() throws Exception { try (InputStream is = OldSchoolDbUnitTest.class.getClassLoader() .getResourceAsStream("dbunit/items_exp_delete_no_produced.xml")) { // given ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("ITEMS"); // when connection.createStatement().executeUpdate("delete from ITEMS where id = 2"); // then IDataSet databaseDataSet = tester.getConnection().createDataSet(); ITable actualTable = databaseDataSet.getTable("ITEMS"); actualTable = DefaultColumnFilter.excludedColumnsTable(actualTable, new String[] { "produced" }); assertEquals(expectedTable, actualTable); } }
Example #16
Source File: OldSchoolDbUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenDataSet_whenUpdate_thenItemHasNewName() throws Exception { try (InputStream is = OldSchoolDbUnitTest.class.getClassLoader() .getResourceAsStream("dbunit/items_exp_rename.xml")) { // given ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("ITEMS"); // when connection.createStatement().executeUpdate("update ITEMS set title='new name' where id = 1"); // then IDataSet databaseDataSet = tester.getConnection().createDataSet(); ITable actualTable = databaseDataSet.getTable("ITEMS"); assertEquals(expectedTable, actualTable); } }
Example #17
Source File: OldSchoolDbUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void givenDataSet_whenUpdateWithNoProduced_thenItemHasNewName() throws Exception { try (InputStream is = OldSchoolDbUnitTest.class.getClassLoader() .getResourceAsStream("dbunit/items_exp_rename_no_produced.xml")) { // given ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("ITEMS"); expectedTable = DefaultColumnFilter.excludedColumnsTable(expectedTable, new String[] { "produced" }); // when connection.createStatement().executeUpdate("update ITEMS set title='new name' where id = 1"); // then IDataSet databaseDataSet = tester.getConnection().createDataSet(); ITable actualTable = databaseDataSet.getTable("ITEMS"); actualTable = DefaultColumnFilter.excludedColumnsTable(actualTable, new String[] { "produced" }); assertEquals(expectedTable, actualTable); } }
Example #18
Source File: Fixtures.java From base-framework with Apache License 2.0 | 6 votes |
/** * 对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(); } } }
Example #19
Source File: DataSourceDBUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenDataSet_whenUpdate_thenItemHasNewName() throws Exception { try (InputStream is = DataSourceDBUnitTest.class.getClassLoader() .getResourceAsStream("dbunit/items_exp_rename.xml")) { // given ITable expectedTable = (new FlatXmlDataSetBuilder().build(is)).getTable("ITEMS"); connection.createStatement().executeUpdate("update ITEMS set title='new name' where id = 1"); IDataSet databaseDataSet = getConnection().createDataSet(); ITable actualTable = databaseDataSet.getTable("ITEMS"); Assertion.assertEquals(expectedTable, actualTable); } }
Example #20
Source File: AbstractSQLAssertTest.java From sharding-jdbc-1.5.1 with Apache License 2.0 | 5 votes |
private void executeQueryWithStatement(final ShardingDataSource dataSource, final List<String> parameters, final File file) throws MalformedURLException, SQLException, DatabaseUnitException { try (Connection conn = dataSource.getConnection()) { String querySql = replaceStatement(sql, parameters.toArray()); ReplacementDataSet expectedDataSet = new ReplacementDataSet(new FlatXmlDataSetBuilder().build(file)); expectedDataSet.addReplacementObject("[null]", null); for (ITable each : expectedDataSet.getTables()) { String tableName = each.getTableMetaData().getTableName(); ITable actualTable = DBUnitUtil.getConnection(new DataBaseEnvironment(DatabaseType.valueFrom(conn.getMetaData().getDatabaseProductName())), conn) .createQueryTable(tableName, querySql); assertEquals(expectedDataSet.getTable(tableName), actualTable); } } }
Example #21
Source File: ColumnDetectorXmlDataSetLoader.java From gazpachoquest with GNU General Public License v3.0 | 5 votes |
@Override protected IDataSet createDataSet(Resource resource) throws Exception { FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder(); builder.setColumnSensing(true); InputStream inputStream = resource.getInputStream(); try { return builder.build(inputStream); } finally { inputStream.close(); } }
Example #22
Source File: AbstractModelTest.java From pnc with Apache License 2.0 | 5 votes |
/** * Inserts data into database from the dbunit XML file * * @param em Entity manager * @param datasetPath Path to DBunit dataset file * @throws Exception Thrown in case of any error during the operation */ protected void initDatabaseUsingDataset(EntityManager em, String datasetPath) throws Exception { IDatabaseConnection connection = new DatabaseConnection(em.unwrap(SessionImpl.class).connection()); connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory()); FlatXmlDataSetBuilder flatXmlDataSetBuilder = new FlatXmlDataSetBuilder(); flatXmlDataSetBuilder.setColumnSensing(true); InputStream dataSetStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(datasetPath); IDataSet dataSet = flatXmlDataSetBuilder.build(dataSetStream); DatabaseOperation.INSERT.execute(connection, dataSet); }
Example #23
Source File: DbUnitSupport.java From proarc with GNU General Public License v3.0 | 5 votes |
public IDataSet loadFlatXmlDataStream(Class<?> c, String resource, boolean resetDtdSchema) throws Exception { FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder(); builder.setMetaDataSetFromDtd(getDtdSchema(resetDtdSchema)); // builder.setMetaDataSet(getConnection().createDataSet()); FlatXmlDataSet fds = builder.build(getResourceStream(c, resource)); return fds; }
Example #24
Source File: AbstractDaoTestCase.java From Asqatasun with GNU Affero General Public License v3.0 | 5 votes |
/** * Charge le jeu de données à partir d'un fichier XML d'import */ @Override protected IDataSet getDataSet() throws Exception { FlatXmlDataSetBuilder flatXmlDataSetBuilder = new FlatXmlDataSetBuilder(); FlatXmlDataSet loadedDataSet = flatXmlDataSetBuilder.build(new FileInputStream( getInputDataFileName())); return loadedDataSet; }
Example #25
Source File: AbstractDaoTestCase.java From Asqatasun with GNU Affero General Public License v3.0 | 5 votes |
/** * Charge le jeu de données à partir d'un fichier XML d'import * @return * @throws java.lang.Exception */ @Override protected IDataSet getDataSet() throws Exception { FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder(); builder.setColumnSensing(true); ReplacementDataSet dataSet = new ReplacementDataSet(builder.build(new FileInputStream( getInputDataFileName()))); dataSet.addReplacementObject("[NULL]", null); return dataSet; }
Example #26
Source File: AbstractSQLAssertTest.java From sharding-jdbc-1.5.1 with Apache License 2.0 | 5 votes |
private void executeQueryWithPreparedStatement(final ShardingDataSource dataSource, final List<String> parameters, final File file) throws MalformedURLException, SQLException, DatabaseUnitException { try (Connection conn = dataSource.getConnection(); PreparedStatement preparedStatement = conn.prepareStatement(replacePreparedStatement(sql))) { setParameters(preparedStatement, parameters); ReplacementDataSet expectedDataSet = new ReplacementDataSet(new FlatXmlDataSetBuilder().build(file)); expectedDataSet.addReplacementObject("[null]", null); for (ITable each : expectedDataSet.getTables()) { String tableName = each.getTableMetaData().getTableName(); ITable actualTable = DBUnitUtil.getConnection(new DataBaseEnvironment(DatabaseType.valueFrom(conn.getMetaData().getDatabaseProductName())), conn) .createTable(tableName, preparedStatement); assertEquals(expectedDataSet.getTable(tableName), actualTable); } } }
Example #27
Source File: AbstractSQLAssertTest.java From sharding-jdbc-1.5.1 with Apache License 2.0 | 5 votes |
private void assertResult(final Connection connection, final File file) throws MalformedURLException, SQLException, DatabaseUnitException { ITableIterator expectedTableIterator = new FlatXmlDataSetBuilder().build(file).iterator(); try (Connection conn = connection) { while (expectedTableIterator.next()) { ITable expectedTable = expectedTableIterator.getTable(); String actualTableName = expectedTable.getTableMetaData().getTableName(); String verifySql = "SELECT * FROM " + actualTableName + " WHERE status = '" + getStatus(file) + "'"; ITable actualTable = DBUnitUtil.getConnection(new DataBaseEnvironment(DatabaseType.valueFrom(conn.getMetaData().getDatabaseProductName())), conn) .createQueryTable(actualTableName, verifySql); assertEquals(expectedTable, actualTable); } } }
Example #28
Source File: AbstractSQLTest.java From sharding-jdbc-1.5.1 with Apache License 2.0 | 5 votes |
@Before public final void importDataSet() throws Exception { for (DatabaseType databaseType : CURRENT_TEST_MODE.databaseTypes()) { DataBaseEnvironment dbEnv = new DataBaseEnvironment(databaseType); for (String each : getDataSetFiles()) { InputStream is = AbstractSQLTest.class.getClassLoader().getResourceAsStream(each); IDataSet dataSet = new FlatXmlDataSetBuilder().build(new InputStreamReader(is)); IDatabaseTester databaseTester = new ShardingJdbcDatabaseTester(dbEnv.getDriverClassName(), dbEnv.getURL(getDatabaseName(each)), dbEnv.getUsername(), dbEnv.getPassword(), dbEnv.getSchema(getDatabaseName(each))); databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT); databaseTester.setDataSet(dataSet); databaseTester.onSetup(); } } }
Example #29
Source File: BasePaymentModuleDBTestCase.java From yes-cart with Apache License 2.0 | 5 votes |
protected IDataSet createDataSet() throws Exception { final FlatXmlDataSet dataSet = new FlatXmlDataSetBuilder() //.setColumnSensing(true) // This enables auto discovery of columns but breaks the tests, possibly our data needs clean up .build(getClass().getClassLoader().getResourceAsStream(createDataSetFile())); final ReplacementDataSet rDataSet = new ReplacementDataSet(dataSet); rDataSet.addReplacementObject("[NULL]", null); return rDataSet; }
Example #30
Source File: DatabaseTaskHandler.java From development with Apache License 2.0 | 5 votes |
public static void cleanDatabase() throws IOException, DataSetException, DatabaseUnitException, SQLException { String filePath = ROOT_PATH + "javares/devscripts/deleteDbContent.xml"; String tableList = DatabaseTaskHandler.class.getResource(".").getFile() + filePath; IDataSet dataToDelete = new FlatXmlDataSetBuilder().build(new File( tableList)); DatabaseOperation.DELETE_ALL.execute(dbConn, dataToDelete); }