コード例 #1
0
 private void exportFK(String file) throws Exception {
   IDataSet fullDataSet = dbunitConnection.createDataSet();
   ITableFilter filter = new DatabaseSequenceFilter(dbunitConnection);
   FilteredDataSet filteredDatSet = new FilteredDataSet(filter, fullDataSet);
   FlatXmlDataSet.write(filteredDatSet, new FileOutputStream(file + ".xml"));
   FlatDtdDataSet.write(filteredDatSet, new FileOutputStream(file + ".dtd"));
 }
コード例 #2
0
ファイル: DBunitTest.java プロジェクト: qinqinwodetao/DBunit
  public static void main(String[] args) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection connection =
        DriverManager.getConnection("jdbc:mysql://localhost:3306/dbunit", "root", "1234");
    IDatabaseConnection databaseConnection = new DatabaseConnection(connection);

    // 根据SQL导出部分数据
    QueryDataSet queryDataSet = new QueryDataSet(databaseConnection);
    queryDataSet.addTable("users", "select password from users where id = 10");
    FlatXmlDataSet.write(queryDataSet, new FileOutputStream("dbunitXMLConditation.xml"));

    // 导出整个库的数据
    IDataSet dataSet = databaseConnection.createDataSet();
    // 将dbunit表中的数据写入到dbunitXML.xml文件中
    FlatXmlDataSet.write(dataSet, new FileOutputStream("dbunitXML.xml"));
    FlatDtdDataSet.write(dataSet, new FileOutputStream("dbunitXML.dtd"));
  }
コード例 #3
0
ファイル: DbUnitTestCase.java プロジェクト: aboutdata/NEFS
  protected void extractFullDataset(final String datasetFileName) throws Exception {
    // database connection
    IDatabaseConnection connection = getDbUnitConnection();

    // full database export
    IDataSet fullDataSet = connection.createDataSet();
    FlatXmlDataSet.write(fullDataSet, new FileOutputStream(datasetFileName));
  }
コード例 #4
0
 protected String getDataSetAsXML(IDataSet dataset) {
   try {
     StringWriter writer = new StringWriter();
     FlatXmlDataSet.write(dataset, writer);
     return writer.getBuffer().toString();
   } catch (Exception e) {
     throw translateException("Could not build XML from dataset", e);
   }
 }
コード例 #5
0
 /**
  * Print the contents of the given tableName to system.out<br>
  * <br>
  * Call this from any {@link BaseContextSensitiveTest} child by:
  * TestUtil.printOutTableContents(getConnection(), "encounter");
  *
  * @param sqlConnection the connection to use
  * @param tableNames the name(s) of the table(s) to print out
  * @throws Exception
  */
 public static void printOutTableContents(Connection sqlConnection, String... tableNames)
     throws Exception {
   for (String tableName : tableNames) {
     System.out.println("The contents of table: " + tableName);
     IDatabaseConnection connection = new DatabaseConnection(sqlConnection);
     DatabaseConfig config = connection.getConfig();
     config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
     QueryDataSet outputSet = new QueryDataSet(connection);
     outputSet.addTable(tableName);
     FlatXmlDataSet.write(outputSet, System.out);
   }
 }
コード例 #6
0
 public void dump(String dbUnitXmlPath) {
   try {
     IDatabaseConnection dbconn = getDbUnitConnection();
     IDataSet iDataSet = dbconn.createDataSet();
     // se for necessário ordenar devido as constraints - demora pacas
     // iDataSet = new FilteredDataSet(new
     // DatabaseSequenceFilter(dbconn), iDataSet);
     FlatXmlDataSet.write(iDataSet, new FileOutputStream(dbUnitXmlPath));
   } catch (Exception e) {
     e.printStackTrace();
     throw new RuntimeException(e);
   }
 }
コード例 #7
0
  /**
   * @param args not used.
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    /*
     * IDataSet actual = new SortedDataSet(new FlatXmlDataSet(new File(
     * "bdb_actual.xml"), false, true)); IDataSet expected = new
     * SortedDataSet(new FlatXmlDataSet(new File( "bdb_expected.xml"),
     * false, true)); Assertion.assertEquals(expected, actual);
     */

    BdbDataSetFactory factory =
        new BdbDataSetFactory(
            new File("updateStore_env"), "ppodLN", newArrayList("pPODPeer1", "pPODPeer2"));

    FlatXmlDataSet ds = factory.getDataSet();
    FlatXmlDataSet.write(ds, new FileWriter("updateStore.xml", false));
  }
コード例 #8
0
ファイル: SnapshotTest.java プロジェクト: rimasu/cloister
  /**
   * Assert that the database contains the expected content.
   *
   * @param expectedDatabaseConfig classpath location of XML file containing a complete description
   *     of the expected database state.
   * @throws SQLException if failed to access database.
   * @throws DatabaseUnitException if failed to access database.
   * @throws DataSetException if failed to access data-set backup.
   * @throws IOException if failed to generate XML dump of actual database state.
   */
  private void assertDataAsExpected(String expectedDatabaseConfig)
      throws SQLException, DatabaseUnitException, DataSetException, IOException {
    createFreshConnection();
    IDataSet actual = getCurrentDataset();
    IDataSet expected = loadDataSetFromClassPath(expectedDatabaseConfig);

    try {
      for (String tableName : expected.getTableNames()) {
        if (!EXCLUDED_TABLES.contains(tableName)) {
          Assertion.assertEquals(expected.getTable(tableName), actual.getTable(tableName));
        }
      }
    } catch (AssertionError e) {
      StringWriter writer = new StringWriter();
      writer.append("actual:");
      FlatXmlDataSet.write(actual, writer);
      writer.close();
      System.out.println(writer);
      throw e;
    }
  }
コード例 #9
0
ファイル: Main.java プロジェクト: skater01/dbunit
  private static void oldMain() throws Exception {

    //        System.setProperty("dbunit.name.escapePattern", "\"?\"");
    IDatabaseConnection connection = DatabaseEnvironment.getInstance().getConnection();
    //        IDataSet dataSet = new XmlDataSet(new FileReader("dataSetTest.xml"));
    //        DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);

    //        String[] tableNames = connection.createDataSet().getTableNames();
    //        Arrays.sort(tableNames);
    //        FlatXmlDataSet.writeDtd(new FilteredDataSet(tableNames,
    //                connection.createDataSet()),
    //                new FileOutputStream("test.dtd"));
    //
    //
    Writer out = new FileWriter("test.xml");
    //        FlatXmlDataSet.write(connection.createDataSet(), out, "ISO-8859-1");
    FlatXmlDataSet.write(connection.createDataSet(), out);
    //        out.flush();
    //        out.close();

    //        ////////////////////////////////
    //        Document document = new Document(TestUtils.getFile("xml/flatXmlDataSetTest.xml"));
    //        DocType docType = document.getDocType();
    //        System.out.println(docType);
    //
    //        // display children of DocType
    //        for (Children decls = docType.getChildren(); decls.hasMoreElements();)
    //        {
    //            Child decl = decls.next();
    //            String type = decl.getClass().getName();
    //            System.out.println("decl = " + decl + ", class: " + type);
    //        }

    //        IDataSet dataSet = new FlatXmlDataSet(
    //                new FileInputStream("flatXmlDataSetTest.xml"));
    //        FlatDtdDataSet.write(new FlatXmlDataSet(
    //                TestUtils.getFileInputStream("xml/flatXmlDataSetTest.xml")),
    //                new FileOutputStream("src/dtd/flatXmlDataSetTest.dtd"));
  }
コード例 #10
0
 private void export(String file) throws Exception {
   IDataSet fullDataSet = dbunitConnection.createDataSet();
   FlatXmlDataSet.write(fullDataSet, new FileOutputStream(file + ".xml"));
   FlatDtdDataSet.write(fullDataSet, new FileOutputStream(file + ".dtd"));
 }