public void testJoinTableMoveInverseJoinColumn2() throws Exception {
    ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithInverseJoinColumns();
    JavaResourceType resourceType = buildJavaResourceType(cu);
    AssociationOverrideAnnotation2_0 associationOverride =
        this.associationOverrideAt(0, resourceType);
    JoinTableAnnotation table = associationOverride.getJoinTable();
    table.addInverseJoinColumn(1).setName("FOO");

    Iterator<JoinColumnAnnotation> inverseJoinColumns = table.getInverseJoinColumns().iterator();
    assertEquals("BAR", inverseJoinColumns.next().getName());
    assertEquals("FOO", inverseJoinColumns.next().getName());
    assertNull(inverseJoinColumns.next().getName());

    table.moveInverseJoinColumn(0, 2);
    inverseJoinColumns = table.getInverseJoinColumns().iterator();
    assertNull(inverseJoinColumns.next().getName());
    assertEquals("BAR", inverseJoinColumns.next().getName());
    assertEquals("FOO", inverseJoinColumns.next().getName());

    assertSourceContains(
        "@AssociationOverride(name = \""
            + ASSOCIATION_OVERRIDE_NAME
            + "\", joinTable = @JoinTable(inverseJoinColumns = {@JoinColumn, @JoinColumn(name = \"BAR\"), @JoinColumn(name = \"FOO\")}))",
        cu);
  }
 public void testJoinTableGetName() throws Exception {
   ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable();
   JavaResourceType resourceType = buildJavaResourceType(cu);
   AssociationOverrideAnnotation2_0 associationOverride =
       this.associationOverrideAt(0, resourceType);
   JoinTableAnnotation joinTable = associationOverride.getJoinTable();
   assertEquals(JOIN_TABLE_NAME, joinTable.getName());
 }
  public void testJoinTableInverseJoinColumns3() throws Exception {
    ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithInverseJoinColumns();
    JavaResourceType resourceType = buildJavaResourceType(cu);
    AssociationOverrideAnnotation2_0 associationOverride =
        this.associationOverrideAt(0, resourceType);
    JoinTableAnnotation table = associationOverride.getJoinTable();

    assertEquals(2, table.getInverseJoinColumnsSize());
  }
  public void testJoinTableUniqueConstraints3() throws Exception {
    ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithUniqueConstraints();
    JavaResourceType resourceType = buildJavaResourceType(cu);
    AssociationOverrideAnnotation2_0 associationOverride =
        this.associationOverrideAt(0, resourceType);
    JoinTableAnnotation table = associationOverride.getJoinTable();

    assertEquals(3, table.getUniqueConstraintsSize());
  }
 public void testJoinTableGetSchema() throws Exception {
   ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithSchema();
   JavaResourceType resourceType = buildJavaResourceType(cu);
   AssociationOverrideAnnotation2_0 associationOverride =
       this.associationOverrideAt(0, resourceType);
   JoinTableAnnotation table = associationOverride.getJoinTable();
   assertNotNull(table);
   assertEquals(SCHEMA_NAME, table.getSchema());
 }
  public void testJoinTableSetCatalogNull() throws Exception {
    ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithCatalog();
    JavaResourceType resourceType = buildJavaResourceType(cu);
    AssociationOverrideAnnotation2_0 associationOverride =
        this.associationOverrideAt(0, resourceType);
    JoinTableAnnotation table = associationOverride.getJoinTable();
    assertEquals(CATALOG_NAME, table.getCatalog());

    table.setCatalog(null);
    assertNull(table.getCatalog());

    assertSourceDoesNotContain("@JoinTable(", cu);
  }
  public void testJoinTableMoveJoinColumn() throws Exception {
    ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithJoinColumns();
    JavaResourceType resourceType = buildJavaResourceType(cu);
    AssociationOverrideAnnotation2_0 associationOverride =
        this.associationOverrideAt(0, resourceType);
    JoinTableAnnotation table = associationOverride.getJoinTable();
    JoinColumnAnnotation joinColumn = table.joinColumnAt(0);
    joinColumn.setReferencedColumnName("REF_NAME");
    joinColumn.setUnique(Boolean.FALSE);
    joinColumn.setNullable(Boolean.FALSE);
    joinColumn.setInsertable(Boolean.FALSE);
    joinColumn.setUpdatable(Boolean.FALSE);
    joinColumn.setColumnDefinition("COLUMN_DEF");
    joinColumn.setTable("TABLE");
    table.addJoinColumn(0).setName("FOO");

    assertSourceContains(
        "@AssociationOverride(name = \""
            + ASSOCIATION_OVERRIDE_NAME
            + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn}))",
        cu);

    table.moveJoinColumn(2, 0);
    assertEquals("BAR", table.joinColumnAt(0).getName());
    assertNull(table.joinColumnAt(1).getName());
    assertEquals("FOO", table.joinColumnAt(2).getName());
    assertEquals(3, table.getJoinColumnsSize());
    assertSourceContains(
        "@AssociationOverride(name = \""
            + ASSOCIATION_OVERRIDE_NAME
            + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn, @JoinColumn(name = \"FOO\")}))",
        cu);
  }
  public void testJoinTableSetSchema() throws Exception {
    ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable();
    JavaResourceType resourceType = buildJavaResourceType(cu);
    AssociationOverrideAnnotation2_0 associationOverride =
        this.associationOverrideAt(0, resourceType);
    JoinTableAnnotation table = associationOverride.getJoinTable();
    assertNotNull(table);
    assertNull(table.getSchema());

    table.setSchema("Foo");
    assertEquals("Foo", table.getSchema());

    assertSourceContains(
        "@AssociationOverride(name = \""
            + ASSOCIATION_OVERRIDE_NAME
            + "\", joinTable = @JoinTable(name = \"MY_JOIN_TABLE\", schema = \"Foo\"))",
        cu);
  }
  public void testJoinTableMoveUniqueConstraint2() throws Exception {
    ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithUniqueConstraints();
    JavaResourceType resourceType = buildJavaResourceType(cu);
    AssociationOverrideAnnotation2_0 associationOverride =
        this.associationOverrideAt(0, resourceType);
    JoinTableAnnotation table = associationOverride.getJoinTable();
    assertSourceContains(
        "@AssociationOverride(name = \""
            + ASSOCIATION_OVERRIDE_NAME
            + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"}), @UniqueConstraint(columnNames = {\"BAZ\"})}))",
        cu);

    table.moveUniqueConstraint(0, 2);
    assertSourceContains(
        "@AssociationOverride(name = \""
            + ASSOCIATION_OVERRIDE_NAME
            + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAZ\"}), @UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"FOO\"})}))",
        cu);
  }
  public void testAddInverseJoinColumn() throws Exception {
    ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable();
    JavaResourceType resourceType = buildJavaResourceType(cu);
    AssociationOverrideAnnotation2_0 associationOverride =
        this.associationOverrideAt(0, resourceType);
    JoinTableAnnotation table = associationOverride.getJoinTable();

    table.addInverseJoinColumn(0).setName("FOO");
    table.addInverseJoinColumn(1);
    table.addInverseJoinColumn(0).setName("BAR");

    assertEquals("BAR", table.inverseJoinColumnAt(0).getName());
    assertEquals("FOO", table.inverseJoinColumnAt(1).getName());
    assertNull(table.inverseJoinColumnAt(2).getName());
    assertSourceContains(
        "@AssociationOverride(name = \""
            + ASSOCIATION_OVERRIDE_NAME
            + "\", joinTable = @JoinTable(name = \"MY_JOIN_TABLE\", inverseJoinColumns = {@JoinColumn(name = \"BAR\"),@JoinColumn(name = \"FOO\"), @JoinColumn}))",
        cu);
  }
  public void testJoinTableAddUniqueConstraint() throws Exception {
    ICompilationUnit cu = this.createTestAssociationOverrideWithJoinTable();
    JavaResourceType resourceType = buildJavaResourceType(cu);
    AssociationOverrideAnnotation2_0 associationOverride =
        this.associationOverrideAt(0, resourceType);
    JoinTableAnnotation table = associationOverride.getJoinTable();

    table.addUniqueConstraint(0).addColumnName("FOO");
    table.addUniqueConstraint(1);
    table.addUniqueConstraint(0).addColumnName("BAR");

    assertEquals("BAR", table.uniqueConstraintAt(0).columnNameAt(0));
    assertEquals("FOO", table.uniqueConstraintAt(1).columnNameAt(0));
    assertEquals(0, table.uniqueConstraintAt(2).getColumnNamesSize());

    assertSourceContains(
        "@AssociationOverride(name = \""
            + ASSOCIATION_OVERRIDE_NAME
            + "\", joinTable = @JoinTable(name = \"MY_JOIN_TABLE\", uniqueConstraints = {@UniqueConstraint(columnNames = \"BAR\"),@UniqueConstraint(columnNames = \"FOO\"), @UniqueConstraint}))",
        cu);
  }
  public void testJoinTableSetJoinColumnName() throws Exception {
    ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithJoinColumns();
    JavaResourceType resourceType = buildJavaResourceType(cu);
    AssociationOverrideAnnotation2_0 associationOverride =
        this.associationOverrideAt(0, resourceType);
    JoinTableAnnotation table = associationOverride.getJoinTable();

    assertEquals(2, table.getJoinColumnsSize());

    JoinColumnAnnotation joinColumn = table.joinColumnAt(0);

    assertEquals("BAR", joinColumn.getName());

    joinColumn.setName("foo");
    assertEquals("foo", joinColumn.getName());

    assertSourceContains(
        "@AssociationOverride(name = \""
            + ASSOCIATION_OVERRIDE_NAME
            + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"foo\"), @JoinColumn}))",
        cu);
  }
  public void testJoinTableRemoveJoinColumn() throws Exception {
    ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithJoinColumns();
    JavaResourceType resourceType = buildJavaResourceType(cu);
    AssociationOverrideAnnotation2_0 associationOverride =
        this.associationOverrideAt(0, resourceType);
    JoinTableAnnotation table = associationOverride.getJoinTable();
    table.addJoinColumn(0).setName("FOO");

    assertEquals("FOO", table.joinColumnAt(0).getName());
    assertEquals("BAR", table.joinColumnAt(1).getName());
    assertNull(table.joinColumnAt(2).getName());
    assertEquals(3, table.getJoinColumnsSize());

    table.removeJoinColumn(1);
    assertEquals("FOO", table.joinColumnAt(0).getName());
    assertNull(table.joinColumnAt(1).getName());
    assertEquals(2, table.getJoinColumnsSize());
    assertSourceContains(
        "@AssociationOverride(name = \""
            + ASSOCIATION_OVERRIDE_NAME
            + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn}))",
        cu);

    table.removeJoinColumn(0);
    assertNull(table.joinColumnAt(0).getName());
    assertEquals(1, table.getJoinColumnsSize());
    assertSourceContains(
        "@AssociationOverride(name = \""
            + ASSOCIATION_OVERRIDE_NAME
            + "\", joinTable = @JoinTable(joinColumns = @JoinColumn))",
        cu);

    table.removeJoinColumn(0);
    assertEquals(0, table.getJoinColumnsSize());
    assertSourceDoesNotContain("@JoinTable(", cu);
  }
  public void testJoinTableRemoveUniqueConstraint() throws Exception {
    ICompilationUnit cu = this.createTestAssociationOverrideJoinTableWithUniqueConstraints();
    JavaResourceType resourceType = buildJavaResourceType(cu);
    AssociationOverrideAnnotation2_0 associationOverride =
        this.associationOverrideAt(0, resourceType);
    JoinTableAnnotation table = associationOverride.getJoinTable();
    assertEquals("BAR", table.uniqueConstraintAt(0).columnNameAt(0));
    assertEquals("FOO", table.uniqueConstraintAt(1).columnNameAt(0));
    assertEquals("BAZ", table.uniqueConstraintAt(2).columnNameAt(0));
    assertEquals(3, table.getUniqueConstraintsSize());

    table.removeUniqueConstraint(1);
    assertEquals("BAR", table.uniqueConstraintAt(0).columnNameAt(0));
    assertEquals("BAZ", table.uniqueConstraintAt(1).columnNameAt(0));
    assertEquals(2, table.getUniqueConstraintsSize());
    assertSourceContains(
        "@AssociationOverride(name = \""
            + ASSOCIATION_OVERRIDE_NAME
            + "\", joinTable = @JoinTable(uniqueConstraints = {@UniqueConstraint(columnNames = {\"BAR\"}), @UniqueConstraint(columnNames = {\"BAZ\"})}))",
        cu);

    table.removeUniqueConstraint(0);
    assertEquals("BAZ", table.uniqueConstraintAt(0).columnNameAt(0));
    assertEquals(1, table.getUniqueConstraintsSize());
    assertSourceContains(
        "@AssociationOverride(name = \""
            + ASSOCIATION_OVERRIDE_NAME
            + "\", joinTable = @JoinTable(uniqueConstraints = @UniqueConstraint(columnNames = {\"BAZ\"})))",
        cu);

    table.removeUniqueConstraint(0);
    assertEquals(0, table.getUniqueConstraintsSize());
    assertSourceDoesNotContain("@JoinTable(", cu);
  }