Ejemplo n.º 1
0
  private void testExecute(IDataSet dataSet) throws Exception {
    ITable[] tablesBefore = DataSetUtils.getTables(_connection.createDataSet());
    //        InsertIdentityOperation.CLEAN_INSERT.execute(_connection, dataSet);
    InsertIdentityOperation.INSERT.execute(_connection, dataSet);
    ITable[] tablesAfter = DataSetUtils.getTables(_connection.createDataSet());

    assertEquals("table count", tablesBefore.length, tablesAfter.length);

    // Verify tables after
    for (int i = 0; i < tablesAfter.length; i++) {
      ITable tableBefore = tablesBefore[i];
      ITable tableAfter = tablesAfter[i];

      String name = tableAfter.getTableMetaData().getTableName();
      if (name.startsWith("IDENTITY")) {
        assertEquals("row count before: " + name, 0, tableBefore.getRowCount());
        if (dataSet instanceof ForwardOnlyDataSet) {
          assertTrue(name, tableAfter.getRowCount() > 0);
        } else {
          Assertion.assertEquals(dataSet.getTable(name), tableAfter);
        }
      } else {
        // Other tables should have not been affected
        Assertion.assertEquals(tableBefore, tableAfter);
      }
    }
  }
Ejemplo n.º 2
0
  /* test case was added to validate the bug that tables with Identity columns that are not
  one of the primary keys are able to figure out if an IDENTITY_INSERT is needed.
  Thanks to Gaetano Di Gregorio for finding the bug.
  */
  public void testIdentityInsertNoPK() throws Exception {
    Reader in = TestUtils.getFileReader("xml/insertIdentityOperationTestNoPK.xml");
    IDataSet xmlDataSet = new FlatXmlDataSetBuilder().build(in);

    ITable[] tablesBefore = DataSetUtils.getTables(_connection.createDataSet());
    InsertIdentityOperation.CLEAN_INSERT.execute(_connection, xmlDataSet);
    ITable[] tablesAfter = DataSetUtils.getTables(_connection.createDataSet());

    // Verify tables after
    for (int i = 0; i < tablesAfter.length; i++) {
      ITable tableBefore = tablesBefore[i];
      ITable tableAfter = tablesAfter[i];

      String name = tableAfter.getTableMetaData().getTableName();
      if (name.equals("TEST_IDENTITY_NOT_PK")) {
        assertEquals("row count before: " + name, 0, tableBefore.getRowCount());
        Assertion.assertEquals(xmlDataSet.getTable(name), tableAfter);
      } else {
        // Other tables should have not been affected
        Assertion.assertEquals(tableBefore, tableAfter);
      }
    }
  }