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 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 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)); }