@Test
  public void testGetTables_SingleTableAliased() throws SqlResourceException {
    final SqlResource sqlResource = Factory.getSqlResource("SingleTableAliased");

    assertEquals(1, sqlResource.getTables().size());
    final TableMetaData table = sqlResource.getTables().get(getQualifiedTableName("film"));
    assertNotNull(table);
    assertEquals("sakila", table.getDatabaseName());
    assertEquals("film", table.getTableName());
    assertEquals("movie", table.getTableAlias());

    // Pks
    assertEquals(1, table.getPrimaryKeys().size());
    assertEquals("film_id", table.getPrimaryKeys().get(0).getColumnName());

    // Columns
    assertEquals(3, table.getColumns().size());
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 1, true, "sakila", "film", "film_id", "id", Types.SMALLINT);
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 2, false, "sakila", "film", "title", "title", Types.VARCHAR);
    AssertionHelper.assertColumnMetaData(
        table.getColumns(),
        3,
        false,
        "sakila",
        "film",
        "release_year",
        "year",
        (getDatabaseType() == DatabaseType.PostgreSql) ? Types.INTEGER : Types.DATE);
  }
  @Test
  public void testGetTables_SingleTable() throws SqlResourceException {
    final SqlResource sqlResource = Factory.getSqlResource("SingleTable");

    assertEquals(1, sqlResource.getTables().size());
    final TableMetaData table = sqlResource.getTables().get(getQualifiedTableName("actor"));
    assertNotNull(table);
    assertEquals("sakila", table.getDatabaseName());
    assertEquals("actor", table.getTableName());

    // Pks
    assertEquals(1, table.getPrimaryKeys().size());
    AssertionHelper.assertColumnMetaData(
        table.getPrimaryKeys().get(0),
        1,
        true,
        "sakila",
        "actor",
        "actor_id",
        "id",
        Types.SMALLINT);

    assertEquals(3, table.getColumns().size());
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 1, true, "sakila", "actor", "actor_id", "id", Types.SMALLINT);
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 2, false, "sakila", "actor", "first_name", "first_name", Types.VARCHAR);
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 3, false, "sakila", "actor", "last_name", "surname", Types.VARCHAR);
  }
  @Test
  public void testGetTables_SingleTableSub() throws SqlResourceException {
    SqlResource sqlResource = Factory.getSqlResource("sub.SingleTable");

    assertEquals(1, sqlResource.getTables().size());
    TableMetaData table = sqlResource.getTables().get(getQualifiedTableName("film"));
    assertNotNull(table);
    assertEquals("sakila", table.getDatabaseName());
    assertEquals("film", table.getTableName());
    assertEquals("pelicula", table.getTableAlias());

    sqlResource = Factory.getSqlResource("sub.sub.SingleTable");

    assertEquals(1, sqlResource.getTables().size());
    table = sqlResource.getTables().get(getQualifiedTableName("language"));
    assertNotNull(table);
    assertEquals("sakila", table.getDatabaseName());
    assertEquals("language", table.getTableName());
    assertEquals("language", table.getTableAlias());
  }
  @Test
  public void testGetTables_MultiPK() throws SqlResourceException {
    final SqlResource sqlResource = Factory.getSqlResource("SingleTable_MultiPK");

    assertEquals(1, sqlResource.getTables().size());
    final TableMetaData table = sqlResource.getTables().get(getQualifiedTableName("film_actor"));
    assertNotNull(table);
    assertEquals("sakila", table.getDatabaseName());
    assertEquals("film_actor", table.getTableName());

    // Pks
    assertEquals(2, table.getPrimaryKeys().size());
    assertEquals("actor_id", table.getPrimaryKeys().get(0).getColumnName());
    assertEquals("film_id", table.getPrimaryKeys().get(1).getColumnName());

    // Columns
    assertEquals(2, table.getColumns().size());
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 1, true, "sakila", "film_actor", "actor_id", "actorId", Types.SMALLINT);
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 2, true, "sakila", "film_actor", "film_id", "film_id", Types.SMALLINT);
  }
  @Test
  public void testGetTables_HierManyToMany() throws SqlResourceException {
    final SqlResource sqlResource = Factory.getSqlResource("HierManyToMany");

    assertEquals(3, sqlResource.getTables().size());
    TableMetaData table = sqlResource.getTables().get(getQualifiedTableName("actor"));
    assertNotNull(table);
    assertEquals("sakila", table.getDatabaseName());
    assertEquals("actor", table.getTableName());

    // Pks
    assertEquals(1, table.getPrimaryKeys().size());
    assertEquals("actor_id", table.getPrimaryKeys().get(0).getColumnName());

    // Columns
    assertEquals(3, table.getColumns().size());
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 1, true, "sakila", "actor", "actor_id", "actor_id", Types.SMALLINT);
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 2, false, "sakila", "actor", "first_name", "first_name", Types.VARCHAR);
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 3, false, "sakila", "actor", "last_name", "last_name", Types.VARCHAR);

    // Child table
    table = sqlResource.getTables().get(getQualifiedTableName("film"));
    assertNotNull(table);
    assertEquals("sakila", table.getDatabaseName());
    assertEquals("film", table.getTableName());

    // Pks
    assertEquals(1, table.getPrimaryKeys().size());
    assertEquals("film_id", table.getPrimaryKeys().get(0).getColumnName());

    // Columns
    assertEquals(3, table.getColumns().size());
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 4, true, "sakila", "film", "film_id", "film_id", Types.SMALLINT);
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 5, false, "sakila", "film", "title", "title", Types.VARCHAR);
    AssertionHelper.assertColumnMetaData(
        table.getColumns(),
        6,
        false,
        "sakila",
        "film",
        "release_year",
        "year",
        (getDatabaseType() == DatabaseType.PostgreSql) ? Types.INTEGER : Types.DATE);

    // // Join table
    // table = sqlResource.getTables().get(getQualifiedTableName("film_actor"));
    // assertNotNull(table);
    // assertEquals("sakila", table.getDatabaseName());
    // assertEquals("film_actor", table.getTableName());
    //
    // // Pks
    // assertEquals(2, table.getPrimaryKeys().size());
    // assertEquals("actor_id", table.getPrimaryKeys().get(0).getColumnName());
    // assertEquals("film_id", table.getPrimaryKeys().get(1).getColumnName());
    //
    // // Columns
    // assertEquals(2, table.getColumns().size());
    // AssertionHelper.assertColumnMetaData(table.getColumns(), 7, true, "sakila", "film_actor",
    // "film_id",
    // "film_id", Types.SMALLINT);
    // AssertionHelper.assertColumnMetaData(table.getColumns(), 0, true, "sakila", "film_actor",
    // "actor_id",
    // "actor_id", "smallint(5) unsigned");
    // assertTrue(table.getColumns().get("actor_id").isNonqueriedForeignKey());
  }
  @Test
  public void testGetTables_FlatManyToOne() throws SqlResourceException {
    final SqlResource sqlResource = Factory.getSqlResource("FlatManyToOne");

    // Parent table
    assertEquals(2, sqlResource.getTables().size());
    TableMetaData table = sqlResource.getTables().get(getQualifiedTableName("film"));
    assertNotNull(table);
    assertEquals("sakila", table.getDatabaseName());
    assertEquals("film", table.getTableName());
    assertEquals(1, table.getPrimaryKeys().size());

    // Primary keys
    AssertionHelper.assertColumnMetaData(
        table.getPrimaryKeys().get(0),
        1,
        true,
        "sakila",
        "film",
        "film_id",
        "film_id",
        Types.SMALLINT);

    // Columns
    assertEquals(3, table.getColumns().size());
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 1, true, "sakila", "film", "film_id", "film_id", Types.SMALLINT);
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 2, false, "sakila", "film", "title", "title", Types.VARCHAR);
    AssertionHelper.assertColumnMetaData(
        table.getColumns(),
        3,
        false,
        "sakila",
        "film",
        "release_year",
        "year",
        (getDatabaseType() == DatabaseType.PostgreSql) ? Types.INTEGER : Types.DATE);

    // Child table
    table = sqlResource.getTables().get(getQualifiedTableName("language"));
    assertNotNull(table);
    assertEquals("sakila", table.getDatabaseName());
    assertEquals("language", table.getTableName());

    // Pks
    assertEquals(1, table.getPrimaryKeys().size());
    AssertionHelper.assertColumnMetaData(
        table.getPrimaryKeys().get(0),
        4,
        true,
        "sakila",
        "language",
        "language_id",
        "language_id",
        Types.SMALLINT);

    // Columns
    assertEquals(2, table.getColumns().size());
    AssertionHelper.assertColumnMetaData(
        table.getColumns(),
        4,
        true,
        "sakila",
        "language",
        "language_id",
        "language_id",
        Types.SMALLINT);
    AssertionHelper.assertColumnMetaData(
        table.getColumns(), 5, false, "sakila", "language", "name", "name", Types.VARCHAR);
  }