public void testgetUniqueConstraintsSize() throws Exception {
    createTestEntityWithElementCollection();
    addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);

    JavaElementCollectionMapping2_0 elementCollectionMapping =
        (JavaElementCollectionMapping2_0)
            getJavaPersistentType().getAttributes().iterator().next().getMapping();
    CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable();

    assertEquals(0, collectionTable.getUniqueConstraintsSize());

    JavaResourceType resourceType =
        (JavaResourceType)
            getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE);
    JavaResourceField resourceField = resourceType.getFields().iterator().next();
    CollectionTableAnnotation2_0 joinTableAnnotation =
        (CollectionTableAnnotation2_0)
            resourceField.addAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME);
    joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo");
    joinTableAnnotation.addUniqueConstraint(1).addColumnName(0, "bar");

    getJpaProject().synchronizeContextModel();

    assertEquals(2, collectionTable.getUniqueConstraintsSize());
  }
  public void testUpdateUniqueConstraints() throws Exception {
    createTestEntityWithElementCollection();
    addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);

    JavaElementCollectionMapping2_0 elementCollectionMapping =
        (JavaElementCollectionMapping2_0)
            getJavaPersistentType().getAttributes().iterator().next().getMapping();
    JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable();
    JavaResourceType resourceType =
        (JavaResourceType)
            getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE);
    JavaResourceField resourceField = resourceType.getFields().iterator().next();
    CollectionTableAnnotation2_0 joinTableAnnotation =
        (CollectionTableAnnotation2_0)
            resourceField.addAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME);

    joinTableAnnotation.addUniqueConstraint(0).addColumnName("FOO");
    joinTableAnnotation.addUniqueConstraint(1).addColumnName("BAR");
    joinTableAnnotation.addUniqueConstraint(2).addColumnName("BAZ");
    getJpaProject().synchronizeContextModel();

    ListIterator<JavaSpecifiedUniqueConstraint> uniqueConstraints =
        collectionTable.getUniqueConstraints().iterator();
    assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next());
    assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next());
    assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next());
    assertFalse(uniqueConstraints.hasNext());

    joinTableAnnotation.moveUniqueConstraint(2, 0);
    getJpaProject().synchronizeContextModel();
    uniqueConstraints = collectionTable.getUniqueConstraints().iterator();
    assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next());
    assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next());
    assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next());
    assertFalse(uniqueConstraints.hasNext());

    joinTableAnnotation.moveUniqueConstraint(0, 1);
    getJpaProject().synchronizeContextModel();
    uniqueConstraints = collectionTable.getUniqueConstraints().iterator();
    assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next());
    assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next());
    assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next());
    assertFalse(uniqueConstraints.hasNext());

    joinTableAnnotation.removeUniqueConstraint(1);
    getJpaProject().synchronizeContextModel();
    uniqueConstraints = collectionTable.getUniqueConstraints().iterator();
    assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next());
    assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next());
    assertFalse(uniqueConstraints.hasNext());

    joinTableAnnotation.removeUniqueConstraint(1);
    getJpaProject().synchronizeContextModel();
    uniqueConstraints = collectionTable.getUniqueConstraints().iterator();
    assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next());
    assertFalse(uniqueConstraints.hasNext());

    joinTableAnnotation.removeUniqueConstraint(0);
    getJpaProject().synchronizeContextModel();
    uniqueConstraints = collectionTable.getUniqueConstraints().iterator();
    assertFalse(uniqueConstraints.hasNext());
  }