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); }
public void testJoinTableMoveJoinColumn2() 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(0, 2); assertNull(table.joinColumnAt(0).getName()); assertEquals("FOO", table.joinColumnAt(1).getName()); assertEquals("BAR", table.joinColumnAt(2).getName()); assertEquals(3, table.getJoinColumnsSize()); assertSourceContains( "@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable(joinColumns = {@JoinColumn, @JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")}))", cu); }
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 testRemoveJoinTable() throws Exception { ICompilationUnit cu = this.createTestAssociationOverrideOnType(); JavaResourceType resourceType = buildJavaResourceType(cu); AssociationOverrideAnnotation2_0 associationOverride = this.associationOverrideAt(0, resourceType); JoinTableAnnotation joinTable = associationOverride.getJoinTable(); assertNull(joinTable); }
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 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 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 testJoinColumns3() throws Exception { ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); JavaResourceType resourceType = buildJavaResourceType(cu); JavaResourceField resourceField = IterableTools.get(resourceType.getFields(), 0); AssociationOverrideAnnotation2_0 associationOverride = this.associationOverrideAt(0, resourceField); assertEquals(2, associationOverride.getJoinColumnsSize()); }
public void testGetName() throws Exception { ICompilationUnit cu = this.createTestAssociationOverrideOnField(); JavaResourceType resourceType = buildJavaResourceType(cu); JavaResourceField resourceField = IterableTools.get(resourceType.getFields(), 0); AssociationOverrideAnnotation2_0 associationOverride = this.associationOverrideAt(0, resourceField); assertNotNull(associationOverride); assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); }
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 testSetNameNull() throws Exception { ICompilationUnit cu = this.createTestAssociationOverrideOnField(); JavaResourceType resourceType = buildJavaResourceType(cu); JavaResourceField resourceField = IterableTools.get(resourceType.getFields(), 0); AssociationOverrideAnnotation2_0 associationOverride = this.associationOverrideAt(0, resourceField); assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); associationOverride.setName(null); assertNull(associationOverride.getName()); assertSourceDoesNotContain( "@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\")", cu); assertSourceContains("@AssociationOverride", cu); }
public void testAddJoinTable() throws Exception { ICompilationUnit cu = this.createTestAssociationOverrideOnType(); JavaResourceType resourceType = buildJavaResourceType(cu); AssociationOverrideAnnotation2_0 associationOverride = this.associationOverrideAt(0, resourceType); JoinTableAnnotation joinTable = associationOverride.getJoinTable(); assertNull(joinTable); associationOverride.addJoinTable(); joinTable = associationOverride.getJoinTable(); assertNotNull(joinTable); assertSourceContains( "@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinTable = @JoinTable)", 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 testRemoveJoinColumn() throws Exception { ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); JavaResourceType resourceType = buildJavaResourceType(cu); JavaResourceField resourceField = IterableTools.get(resourceType.getFields(), 0); AssociationOverrideAnnotation2_0 associationOverride = this.associationOverrideAt(0, resourceField); associationOverride.addJoinColumn(0).setName("FOO"); Iterator<JoinColumnAnnotation> joinColumns = associationOverride.getJoinColumns().iterator(); assertEquals("FOO", joinColumns.next().getName()); assertEquals("BAR", joinColumns.next().getName()); assertNull(joinColumns.next().getName()); assertEquals(false, joinColumns.hasNext()); assertSourceContains( "@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn(name = \"BAR\"), @JoinColumn})", cu); associationOverride.removeJoinColumn(1); joinColumns = associationOverride.getJoinColumns().iterator(); assertEquals("FOO", joinColumns.next().getName()); assertNull(joinColumns.next().getName()); assertEquals(false, joinColumns.hasNext()); assertSourceContains( "@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"FOO\"), @JoinColumn})", cu); associationOverride.removeJoinColumn(0); joinColumns = associationOverride.getJoinColumns().iterator(); assertNull(joinColumns.next().getName()); assertEquals(false, joinColumns.hasNext()); assertSourceContains( "@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = @JoinColumn)", cu); associationOverride.setName(null); associationOverride.removeJoinColumn(0); assertSourceDoesNotContain("@AssociationOverride(", 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 testAddJoinColumn() throws Exception { ICompilationUnit cu = this.createTestAssociationOverrideOnField(); JavaResourceType resourceType = buildJavaResourceType(cu); JavaResourceField resourceField = IterableTools.get(resourceType.getFields(), 0); AssociationOverrideAnnotation2_0 associationOverride = this.associationOverrideAt(0, resourceField); associationOverride.addJoinColumn(0).setName("FOO"); associationOverride.addJoinColumn(1); associationOverride.addJoinColumn(0).setName("BAR"); assertEquals("BAR", associationOverride.joinColumnAt(0).getName()); assertEquals("FOO", associationOverride.joinColumnAt(1).getName()); assertNull(associationOverride.joinColumnAt(2).getName()); assertSourceContains( "@AssociationOverride(name = \"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name = \"BAR\"),@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); }