コード例 #1
0
  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);
  }
コード例 #2
0
  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);
  }