public void testMorphToElementCollectionMapping() throws Exception { createTestEntityWithIdMapping(); addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); SpecifiedPersistentAttribute persistentAttribute = getJavaPersistentType().getAttributes().iterator().next(); IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE); JavaResourceField resourceField = resourceType.getFields().iterator().next(); assertFalse(idMapping.isDefault()); idMapping.getColumn().setSpecifiedName("FOO"); idMapping.setConverter(BaseTemporalConverter.class); ((BaseTemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); idMapping.addGeneratedValue(); idMapping.getGeneratorContainer().addTableGenerator(); idMapping.getGeneratorContainer().addSequenceGenerator(); resourceField.addAnnotation(AccessAnnotation2_0.ANNOTATION_NAME); assertFalse(idMapping.isDefault()); persistentAttribute.setMappingKey(MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY); assertTrue(persistentAttribute.getMapping() instanceof ElementCollectionMapping2_0); assertNull(resourceField.getAnnotation(IdAnnotation.ANNOTATION_NAME)); assertNotNull(resourceField.getAnnotation(ElementCollectionAnnotation2_0.ANNOTATION_NAME)); assertNotNull(resourceField.getAnnotation(AccessAnnotation2_0.ANNOTATION_NAME)); assertNotNull(resourceField.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); assertNotNull(resourceField.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); assertNull(resourceField.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); assertNull(resourceField.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); assertNull(resourceField.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); }
public void testAddUniqueConstraint2() throws Exception { createTestEntityWithElementCollection(); addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO"); collectionTable.addUniqueConstraint(1).addColumnName(0, "BAR"); collectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE); JavaResourceField resourceField = resourceType.getFields().iterator().next(); CollectionTableAnnotation2_0 joinTableAnnotation = (CollectionTableAnnotation2_0) resourceField.getAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME); ListIterator<UniqueConstraintAnnotation> uniqueConstraints = joinTableAnnotation.getUniqueConstraints().iterator(); assertEquals("BAZ", uniqueConstraints.next().columnNameAt(0)); assertEquals("FOO", uniqueConstraints.next().columnNameAt(0)); assertEquals("BAR", uniqueConstraints.next().columnNameAt(0)); assertFalse(uniqueConstraints.hasNext()); }
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 testRemoveSpecifiedJoinColumn() throws Exception { createTestEntityWithElementCollection(); addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE); JavaResourceField resourceField = resourceType.getFields().iterator().next(); collectionTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); collectionTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); collectionTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); CollectionTableAnnotation2_0 joinTableResource = (CollectionTableAnnotation2_0) resourceField.getAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME); assertEquals(3, joinTableResource.getJoinColumnsSize()); collectionTable.removeSpecifiedJoinColumn(0); assertEquals(2, joinTableResource.getJoinColumnsSize()); assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); collectionTable.removeSpecifiedJoinColumn(0); assertEquals(1, joinTableResource.getJoinColumnsSize()); assertEquals("BAZ", joinTableResource.joinColumnAt(0).getName()); collectionTable.removeSpecifiedJoinColumn(0); assertEquals(0, joinTableResource.getJoinColumnsSize()); }
public void testModifySpecifiedCatalog() throws Exception { createTestEntityWithElementCollection(); addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE); JavaResourceField resourceField = resourceType.getFields().iterator().next(); CollectionTableAnnotation2_0 resourceCollectionTable = (CollectionTableAnnotation2_0) resourceField.getAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME); assertNull(collectionTable.getSpecifiedCatalog()); assertNull(resourceCollectionTable); // set catalog in the context model, verify resource model modified collectionTable.setSpecifiedCatalog("foo"); resourceCollectionTable = (CollectionTableAnnotation2_0) resourceField.getAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME); assertEquals("foo", collectionTable.getSpecifiedCatalog()); assertEquals("foo", resourceCollectionTable.getCatalog()); // set catalog to null in the context model collectionTable.setSpecifiedCatalog(null); assertNull(collectionTable.getSpecifiedCatalog()); assertNull(resourceField.getAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME)); }
public void testDefaultName() throws Exception { createTestEntityWithValidElementCollection(); addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); assertEquals(TYPE_NAME + "_projects", collectionTable.getDefaultName()); JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE); JavaResourceField resourceField = resourceType.getFields().iterator().next(); assertNull(resourceField.getAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME)); // add the collection table annotation, verify default collection table name is the same resourceField.addAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME); assertEquals(TYPE_NAME + "_projects", collectionTable.getDefaultName()); assertNotNull(resourceField.getAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME)); // set the entity name, verify default collection table name updates getJavaEntity().setSpecifiedName("Foo"); assertEquals("Foo_projects", collectionTable.getDefaultName()); }
public void testGetXmlID() throws Exception { ICompilationUnit cu = this.createTestXmlID(); JavaResourceType resourceType = buildJavaResourceType(cu); JavaResourceField resourceAttribute = getField(resourceType, 0); XmlIDAnnotation xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ID); assertTrue(xmlIDAnnotation != null); resourceAttribute.removeAnnotation(JAXB.XML_ID); assertSourceDoesNotContain("@XmlID", cu); }
public void testContained() throws Exception { // test adding/removing/moving ICompilationUnit cu = createTestXmlPath(); JavaResourceType resourceType = buildJavaResourceType(cu); JavaResourceField resourceAttribute = getField(resourceType, 0); assertEquals(1, resourceAttribute.getAnnotationsSize(ELJaxb.XML_PATH)); resourceAttribute.addAnnotation(1, ELJaxb.XML_PATH); assertEquals(2, resourceAttribute.getAnnotationsSize(ELJaxb.XML_PATH)); assertSourceContains("@XmlPaths({ @XmlPath, @XmlPath })", cu); XmlPathAnnotation annotation1 = getXmlPathAnnotation(resourceAttribute, 0); annotation1.setValue("foo"); XmlPathAnnotation annotation2 = getXmlPathAnnotation(resourceAttribute, 1); annotation2.setValue("bar"); assertSourceContains("@XmlPaths({ @XmlPath(\"foo\"), @XmlPath(\"bar\") })", cu); resourceAttribute.moveAnnotation(0, 1, ELJaxb.XML_PATH); assertSourceContains("@XmlPaths({ @XmlPath(\"bar\"), @XmlPath(\"foo\") })", cu); resourceAttribute.removeAnnotation(0, ELJaxb.XML_PATH); assertEquals(1, resourceAttribute.getAnnotationsSize(ELJaxb.XML_PATH)); assertSourceContains("@XmlPath(\"foo\")", cu); assertSourceDoesNotContain("@XmlPaths", cu); }
public void testUpdateSpecifiedName() throws Exception { createTestEntityWithElementCollection(); addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE); JavaResourceField resourceField = resourceType.getFields().iterator().next(); CollectionTableAnnotation2_0 resourceCollectionTable = (CollectionTableAnnotation2_0) resourceField.getAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME); assertNull(collectionTable.getSpecifiedName()); assertNull(resourceCollectionTable); // set name in the resource model, verify context model updated resourceField.addAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME); resourceCollectionTable = (CollectionTableAnnotation2_0) resourceField.getAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME); resourceCollectionTable.setName("FOO"); getJpaProject().synchronizeContextModel(); assertEquals("FOO", collectionTable.getSpecifiedName()); assertEquals("FOO", resourceCollectionTable.getName()); // set name to null in the resource model resourceCollectionTable.setName(null); getJpaProject().synchronizeContextModel(); assertNull(collectionTable.getSpecifiedName()); assertNull(resourceCollectionTable.getName()); resourceCollectionTable.setName("FOO"); getJpaProject().synchronizeContextModel(); assertEquals("FOO", collectionTable.getSpecifiedName()); assertEquals("FOO", resourceCollectionTable.getName()); resourceField.removeAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME); getJpaProject().synchronizeContextModel(); assertNull(collectionTable.getSpecifiedName()); assertNull(resourceField.getAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME)); }
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()); }