@Test
  public void tableEquals() {

    final SchemaCrawlerOptions schemaCrawlerOptions = new SchemaCrawlerOptions();
    schemaCrawlerOptions.setShowStoredProcedures(true);

    final Catalog catalog = testUtility.getCatalog(schemaCrawlerOptions);
    assertNotNull("Could not obtain catalog", catalog);
    assertTrue("Could not find any schemas", catalog.getSchemas().length > 0);

    final Schema schema = catalog.getSchema("PUBLIC");
    assertNotNull("Could not obtain schema", schema);
    assertTrue("Could not find any tables", schema.getTables().length > 0);
    assertTrue("Could not find any procedures", schema.getProcedures().length > 0);

    // Try negative test
    final Table table0 = schema.getTables()[0];
    assertTrue("Could not find any columns", table0.getColumns().length > 0);

    final MutableTable table1 =
        new MutableTable(table0.getCatalogName(), table0.getSchemaName(), "Test Table 1");
    final MutableTable table2 =
        new MutableTable(table0.getCatalogName(), table0.getSchemaName(), "Test Table 2");
    final PrimaryKey primaryKey = table0.getPrimaryKey();
    table1.setPrimaryKey(primaryKey);
    table2.setPrimaryKey(primaryKey);
    for (final Column column : table0.getColumns()) {
      table1.addColumn((MutableColumn) column);
      table2.addColumn((MutableColumn) column);
    }
    for (final Index index : table0.getIndices()) {
      table1.addIndex((MutableIndex) index);
      table2.addIndex((MutableIndex) index);
    }
    for (final ForeignKey fk : table0.getForeignKeys()) {
      table1.addForeignKey((MutableForeignKey) fk);
      table2.addForeignKey((MutableForeignKey) fk);
    }
    for (final Trigger trigger : table0.getTriggers()) {
      table1.addTrigger((MutableTrigger) trigger);
      table2.addTrigger((MutableTrigger) trigger);
    }
    for (final Privilege privilege : table0.getPrivileges()) {
      table1.addPrivilege((MutablePrivilege) privilege);
      table2.addPrivilege((MutablePrivilege) privilege);
    }
    for (final CheckConstraint checkConstraint : table0.getCheckConstraints()) {
      table1.addCheckConstraint((MutableCheckConstraint) checkConstraint);
      table2.addCheckConstraint((MutableCheckConstraint) checkConstraint);
    }

    assertFalse("Tables should not be equal", table1.equals(table2));
  }
  @Test
  public void testSchema() throws Exception {
    final SchemaCrawlerOptions schemaCrawlerOptions =
        (SchemaCrawlerOptions) appContext.getBean("schemaCrawlerOptions");

    final Schema schema = testUtility.getSchema(schemaCrawlerOptions, "PUBLIC");
    assertNotNull("Could not obtain schema", schema);

    assertEquals("Unexpected number of tables in the schema", 6, schema.getTables().length);
  }
  @Test
  public void testSchema() {
    final SchemaCrawlerOptions schemaCrawlerOptions =
        (SchemaCrawlerOptions) appContext.getBean("schemaCrawlerOptions");

    final Catalog catalog = testUtility.getCatalog(schemaCrawlerOptions);
    assertNotNull("Could not obtain catalog", catalog);
    assertTrue("Could not find any schemas", catalog.getSchemas().length > 0);

    final Schema schema = catalog.getSchema("PUBLIC");
    assertNotNull("Could not obtain schema", schema);

    assertEquals(6, schema.getTables().length);
  }
  private void tables(final String dataSourceName, final Schema schema) throws Exception {
    final String[] tableNames = {
      "CUSTOMER", "CUSTOMERLIST", "INVOICE", "ITEM", "PRODUCT", "SUPPLIER"
    };
    final String[] tableTypes = {"TABLE", "VIEW", "TABLE", "TABLE", "TABLE", "TABLE"};

    final Table[] tables = schema.getTables();
    assertEquals(dataSourceName + " table count does not match", tableNames.length, tables.length);
    for (int tableIdx = 0; tableIdx < tables.length; tableIdx++) {
      final Table table = tables[tableIdx];
      assertEquals(
          dataSourceName + " table name does not match",
          tableNames[tableIdx],
          table.getName().toUpperCase());
      assertEquals(
          dataSourceName + " table type does not match",
          tableTypes[tableIdx],
          table.getType().toString().toUpperCase());
    }
  }
  private void counts(final String dataSourceName, final Schema schema) throws Exception {

    final int[] tableColumnCounts = {5, 3, 3, 5, 3, 2};
    final int[] checkConstraints = {0, 0, 0, 0, 0, 0};
    // final int[] indexCounts = {
    // 0, 0, 2, 4, 0, 2
    // };
    final int[] fkCounts = {1, 0, 2, 2, 1, 0};

    final Table[] tables = schema.getTables();
    assertEquals(
        dataSourceName + " table count does not match", tableColumnCounts.length, tables.length);
    for (int tableIdx = 0; tableIdx < tables.length; tableIdx++) {
      final Table table = tables[tableIdx];
      assertEquals(
          String.format(
              "%s table %s columns count does not match", dataSourceName, table.getFullName()),
          tableColumnCounts[tableIdx],
          table.getColumns().length);
      assertEquals(
          String.format(
              "%s table %s check constraints count does not match",
              dataSourceName, table.getFullName()),
          checkConstraints[tableIdx],
          table.getCheckConstraints().length);
      // assertEquals(String.format("%s table %s index count does not match",dataSourceName,
      // table
      // .getFullName()), indexCounts[tableIdx],
      // table.getIndices().length);
      assertEquals(
          String.format(
              "%s table %s foreign key count does not match", dataSourceName, table.getFullName()),
          fkCounts[tableIdx],
          table.getForeignKeys().length);
    }
  }