Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2010-11-17 14:13:23 -0500
committerkmoore2010-11-17 14:13:23 -0500
commit99aa1028a4b7972edc03b2ed3337438d2179fec3 (patch)
treeeb57177e867539bab51743e9328a0ce54ab60deb
parentdb287299090f592c77820c09e3fa01c283f3ad7b (diff)
downloadwebtools.dali-99aa1028a4b7972edc03b2ed3337438d2179fec3.tar.gz
webtools.dali-99aa1028a4b7972edc03b2ed3337438d2179fec3.tar.xz
webtools.dali-99aa1028a4b7972edc03b2ed3337438d2179fec3.zip
added tests for jaxb GenericRootContextNode packages
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java30
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/GenericRootContextNodeTests.java659
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/JaxbCoreContextModelTests.java1
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/AnnotationTestCase.java17
4 files changed, 696 insertions, 11 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java
index e34ec95878..e4862003cf 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java
@@ -100,15 +100,17 @@ public class GenericRootContextNode
final Set<String> packagesToBuild = CollectionTools.set(initialPackages);
final Set<String> packagesToUpdate = CollectionTools.<String>set();
+ final Set<String> packagesToRemove = CollectionTools.set(this.packages.keySet());
final Set<String> persistentClassesToBuild = CollectionTools.set(initialPersistentClasses);
final Set<String> persistentClassesToUpdate = CollectionTools.<String>set();
for (String packageToBuild : packagesToBuild) {
if (this.packages.containsKey(packageToBuild)) {
packagesToUpdate.add(packageToBuild);
+ packagesToRemove.remove(packageToBuild);
}
else {
- this.packages.put(packageToBuild, buildPackage(packageToBuild));
+ this.addPackage(this.buildPackage(packageToBuild));
}
}
@@ -117,7 +119,7 @@ public class GenericRootContextNode
persistentClassesToUpdate.add(classToBuild);
}
else {
- this.persistentClasses.put(classToBuild, buildPersistentClass(classToBuild));
+ this.addPersistentClass(this.buildPersistentClass(classToBuild));
}
}
@@ -128,6 +130,10 @@ public class GenericRootContextNode
for (String classToUpdate : persistentClassesToUpdate) {
this.persistentClasses.get(classToUpdate).update();
}
+
+ for (String packageToRemove : packagesToRemove) {
+ this.removePackage(packageToRemove);
+ }
}
/*
@@ -203,7 +209,7 @@ public class GenericRootContextNode
protected JaxbPackage addPackage(JaxbPackage contextPackage) {
if (this.packages.containsKey(contextPackage.getName())) {
- throw new IllegalArgumentException("Package with that name already exists.");
+ throw new IllegalArgumentException("Package with that name already exists."); //$NON-NLS-1$
}
this.packages.put(contextPackage.getName(), contextPackage);
fireItemAdded(PACKAGES_COLLECTION, contextPackage);
@@ -211,11 +217,15 @@ public class GenericRootContextNode
}
protected void removePackage(JaxbPackage contextPackage) {
- if (! this.packages.containsKey(contextPackage.getName())) {
- throw new IllegalArgumentException("No package with that name exists.");
+ this.removePackage(contextPackage.getName());
+ }
+
+ protected void removePackage(String packageName) {
+ if (! this.packages.containsKey(packageName)) {
+ throw new IllegalArgumentException("No package with that name exists."); //$NON-NLS-1$
}
- this.packages.remove(contextPackage.getName());
- fireItemRemoved(PACKAGES_COLLECTION, contextPackage);
+ JaxbPackage removedPackage = this.packages.remove(packageName);
+ fireItemRemoved(PACKAGES_COLLECTION, removedPackage);
}
protected JaxbPackage buildPackage(String packageName) {
@@ -239,7 +249,7 @@ public class GenericRootContextNode
protected JaxbPersistentClass addPersistentClass(JaxbPersistentClass persistentClass) {
if (this.persistentClasses.containsKey(persistentClass.getName())) {
- throw new IllegalArgumentException("Class with that name already exists.");
+ throw new IllegalArgumentException("Class with that name already exists."); //$NON-NLS-1$
}
this.persistentClasses.put(persistentClass.getName(), persistentClass);
fireItemAdded(PERSISTENT_CLASSES_COLLECTION, persistentClass);
@@ -248,7 +258,7 @@ public class GenericRootContextNode
protected void removePersistentClass(JaxbPersistentClass persistentClass) {
if (! this.persistentClasses.containsKey(persistentClass.getName())) {
- throw new IllegalArgumentException("No class with that name exists.");
+ throw new IllegalArgumentException("No class with that name exists."); //$NON-NLS-1$
}
this.persistentClasses.remove(persistentClass.getName());
fireItemRemoved(PERSISTENT_CLASSES_COLLECTION, persistentClass);
@@ -257,7 +267,7 @@ public class GenericRootContextNode
protected JaxbPersistentClass buildPersistentClass(String className) {
JavaResourceType resourceType = getJaxbProject().getJavaResourceType(className);
if (resourceType == null) {
- throw new IllegalArgumentException("No resource type exists for class named " + className);
+ throw new IllegalArgumentException("No resource type exists for class named " + className); //$NON-NLS-1$
}
return this.getFactory().buildPersistentClass(this, resourceType);
}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/GenericRootContextNodeTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/GenericRootContextNodeTests.java
new file mode 100644
index 0000000000..ba8d5c14e3
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/GenericRootContextNodeTests.java
@@ -0,0 +1,659 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.tests.internal.context;
+
+import java.util.Iterator;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jpt.core.utility.jdt.AnnotatedElement;
+import org.eclipse.jpt.core.utility.jdt.Member;
+import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration;
+import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
+import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
+import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase;
+
+
+@SuppressWarnings("nls")
+public class GenericRootContextNodeTests extends JaxbContextModelTestCase
+{
+
+ public GenericRootContextNodeTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createPackageInfoWithAccessorOrder() throws CoreException {
+ return createTestPackageInfo(
+ "@XmlAccessorOrder(value = XmlAccessOrder.ALPHABETICAL)",
+ JAXB.XML_ACCESS_ORDER, JAXB.XML_ACCESSOR_ORDER);
+ }
+
+ private ICompilationUnit createUnannotatedPackageInfo(String packageName) throws CoreException {
+ return createTestPackageInfo(packageName);
+ }
+
+ public void testGetPackages() throws Exception {
+ this.createPackageInfoWithAccessorOrder();
+ Iterator<JaxbPackage> packages = this.getRootContextNode().getPackages().iterator();
+ assertEquals(1, this.getRootContextNode().getPackagesSize());
+ assertEquals(PACKAGE_NAME, packages.next().getName());
+ assertFalse(packages.hasNext());
+
+ //add an unannotated package-info.java and make sure it's not added to the root context node
+ this.createUnannotatedPackageInfo("foo");
+ packages = this.getRootContextNode().getPackages().iterator();
+ assertEquals(1, this.getRootContextNode().getPackagesSize());
+ assertEquals(PACKAGE_NAME, packages.next().getName());
+ assertFalse(packages.hasNext());
+
+ //annotate the package-info.java and test it's added to the root context node
+ JavaResourcePackage fooResourcePackage = getJaxbProject().getJavaResourcePackage("foo");
+ AnnotatedElement annotatedElement = this.annotatedElement(fooResourcePackage);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericRootContextNodeTests.this.addXmlAccessorTypeAnnotation(declaration, JAXB.XML_ACCESS_TYPE__PROPERTY);
+ }
+ });
+
+ packages = this.getRootContextNode().getPackages().iterator();
+ assertEquals(2, this.getRootContextNode().getPackagesSize());
+ assertEquals(PACKAGE_NAME, packages.next().getName());
+ assertEquals("foo", packages.next().getName());
+ assertFalse(packages.hasNext());
+
+ //remove the annotation from the package-info.java and test it's removed from the root context node
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericRootContextNodeTests.this.removeXmlAccessorTypeAnnotation(declaration);
+ }
+ });
+
+ packages = this.getRootContextNode().getPackages().iterator();
+ assertEquals(1, this.getRootContextNode().getPackagesSize());
+ assertEquals(PACKAGE_NAME, packages.next().getName());
+ assertFalse(packages.hasNext());
+ }
+
+ protected void addXmlAccessorTypeAnnotation(ModifiedDeclaration declaration, String accessType) {
+ NormalAnnotation annotation = this.addNormalAnnotation(declaration.getDeclaration(), JAXB.XML_ACCESSOR_TYPE);
+ this.addEnumMemberValuePair(annotation, JAXB.XML_ACCESSOR_TYPE__VALUE, accessType);
+ }
+
+ protected void removeXmlAccessorTypeAnnotation(ModifiedDeclaration declaration) {
+ this.removeAnnotation(declaration, JAXB.XML_ACCESSOR_TYPE);
+ }
+
+// public void testGetXmlSchemaTypesSize() throws Exception {
+// this.createPackageInfoWithAccessorOrder();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// assertEquals(0, contextPackageInfo.getXmlSchemaTypesSize());
+//
+// //add 2 XmlSchemaTypes
+// AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.addXmlSchemaType(declaration, 0, "bar");
+// GenericRootContextNodeTests.this.addXmlSchemaType(declaration, 1, "foo");
+// }
+// });
+// assertEquals(2, contextPackageInfo.getXmlSchemaTypesSize());
+// }
+//
+// public void testAddXmlSchemaType() throws Exception {
+// //create a package info with an annotation other than XmlSchema to test
+// //adding things to the null schema annotation
+// this.createPackageInfoWithAccessorType();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// contextPackageInfo.addXmlSchemaType(0).setName("bar");
+// contextPackageInfo.addXmlSchemaType(0).setName("foo");
+// contextPackageInfo.addXmlSchemaType(0).setName("baz");
+//
+// Iterator<XmlSchemaTypeAnnotation> xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+//
+// assertEquals("baz", xmlSchemaTypes.next().getName());
+// assertEquals("foo", xmlSchemaTypes.next().getName());
+// assertEquals("bar", xmlSchemaTypes.next().getName());
+// assertFalse(xmlSchemaTypes.hasNext());
+// }
+//
+// @SuppressWarnings("unchecked")
+// protected Iterator<XmlSchemaTypeAnnotation> getSchemaTypeAnnotations(JavaResourcePackage resourcePackage) {
+// return (Iterator<XmlSchemaTypeAnnotation>) resourcePackage.getAnnotations(JAXB.XML_SCHEMA_TYPE).iterator();
+// }
+//
+// public void testAddXmlSchemaType2() throws Exception {
+// //create a package info with an annotation other than XmlSchema to test
+// //adding things to the null schema annotation
+// this.createPackageInfoWithAccessorType();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// contextPackageInfo.addXmlSchemaType(0).setName("bar");
+// contextPackageInfo.addXmlSchemaType(1).setName("foo");
+// contextPackageInfo.addXmlSchemaType(0).setName("baz");
+//
+// Iterator<XmlSchemaTypeAnnotation> xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+//
+// assertEquals("baz", xmlSchemaTypes.next().getName());
+// assertEquals("bar", xmlSchemaTypes.next().getName());
+// assertEquals("foo", xmlSchemaTypes.next().getName());
+// assertFalse(xmlSchemaTypes.hasNext());
+// }
+//
+// public void testRemoveXmlSchemaType() throws Exception {
+// this.createPackageInfoWithAccessorType();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// contextPackageInfo.addXmlSchemaType(0).setName("bar");
+// contextPackageInfo.addXmlSchemaType(1).setName("foo");
+// contextPackageInfo.addXmlSchemaType(2).setName("baz");
+//
+// Iterator<XmlSchemaTypeAnnotation> xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+// assertEquals("bar", xmlSchemaTypes.next().getName());
+// assertEquals("foo", xmlSchemaTypes.next().getName());
+// assertEquals("baz", xmlSchemaTypes.next().getName());
+// assertFalse(xmlSchemaTypes.hasNext());
+//
+// contextPackageInfo.removeXmlSchemaType(1);
+//
+// xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+// assertEquals("bar", xmlSchemaTypes.next().getName());
+// assertEquals("baz", xmlSchemaTypes.next().getName());
+// assertFalse(xmlSchemaTypes.hasNext());
+//
+// contextPackageInfo.removeXmlSchemaType(1);
+// xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+// assertEquals("bar", xmlSchemaTypes.next().getName());
+// assertFalse(xmlSchemaTypes.hasNext());
+//
+// contextPackageInfo.removeXmlSchemaType(0);
+// xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+// assertFalse(xmlSchemaTypes.hasNext());
+// }
+//
+// public void testMoveXmlSchemaType() throws Exception {
+// this.createPackageInfoWithAccessorType();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// contextPackageInfo.addXmlSchemaType(0).setName("bar");
+// contextPackageInfo.addXmlSchemaType(1).setName("foo");
+// contextPackageInfo.addXmlSchemaType(2).setName("baz");
+//
+// Iterator<XmlSchemaTypeAnnotation> xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+// assertEquals("bar", xmlSchemaTypes.next().getName());
+// assertEquals("foo", xmlSchemaTypes.next().getName());
+// assertEquals("baz", xmlSchemaTypes.next().getName());
+// assertFalse(xmlSchemaTypes.hasNext());
+//
+// contextPackageInfo.moveXmlSchemaType(2, 0);
+// xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+// assertEquals("foo", xmlSchemaTypes.next().getName());
+// assertEquals("baz", xmlSchemaTypes.next().getName());
+// assertEquals("bar", xmlSchemaTypes.next().getName());
+// assertFalse(xmlSchemaTypes.hasNext());
+//
+// contextPackageInfo.moveXmlSchemaType(0, 1);
+// xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage);
+// assertEquals("baz", xmlSchemaTypes.next().getName());
+// assertEquals("foo", xmlSchemaTypes.next().getName());
+// assertEquals("bar", xmlSchemaTypes.next().getName());
+// assertFalse(xmlSchemaTypes.hasNext());
+// }
+//
+// public void testSyncXmlSchemaTypes() throws Exception {
+// this.createPackageInfoWithAccessorType();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// ListIterable<XmlSchemaType> xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes();
+// assertFalse(xmlSchemaTypes.iterator().hasNext());
+//
+// //add 3 XmlSchemaTypes
+// AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.addXmlSchemaType(declaration, 0, "bar");
+// GenericRootContextNodeTests.this.addXmlSchemaType(declaration, 1, "foo");
+// GenericRootContextNodeTests.this.addXmlSchemaType(declaration, 2, "baz");
+// }
+// });
+//
+// xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes();
+// ListIterator<XmlSchemaType> xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+// assertTrue(xmlSchemaTypesIterator.hasNext());
+// assertEquals("bar", xmlSchemaTypesIterator.next().getName());
+// assertEquals("foo", xmlSchemaTypesIterator.next().getName());
+// assertEquals("baz", xmlSchemaTypesIterator.next().getName());
+// assertFalse(xmlSchemaTypesIterator.hasNext());
+//
+//
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.moveXmlSchemaType(declaration, 2, 0);
+// }
+// });
+//
+// xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+// assertTrue(xmlSchemaTypesIterator.hasNext());
+// assertEquals("foo", xmlSchemaTypesIterator.next().getName());
+// assertEquals("baz", xmlSchemaTypesIterator.next().getName());
+// assertEquals("bar", xmlSchemaTypesIterator.next().getName());
+// assertFalse(xmlSchemaTypesIterator.hasNext());
+//
+//
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.moveXmlSchemaType(declaration, 0, 1);
+// }
+// });
+//
+// xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+// assertTrue(xmlSchemaTypesIterator.hasNext());
+// assertEquals("baz", xmlSchemaTypesIterator.next().getName());
+// assertEquals("foo", xmlSchemaTypesIterator.next().getName());
+// assertEquals("bar", xmlSchemaTypesIterator.next().getName());
+// assertFalse(xmlSchemaTypesIterator.hasNext());
+//
+//
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.removeXmlSchemaType(declaration, 1);
+// }
+// });
+//
+// xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+// assertTrue(xmlSchemaTypesIterator.hasNext());
+// assertEquals("baz", xmlSchemaTypesIterator.next().getName());
+// assertEquals("bar", xmlSchemaTypesIterator.next().getName());
+// assertFalse(xmlSchemaTypesIterator.hasNext());
+//
+//
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.removeXmlSchemaType(declaration, 1);
+// }
+// });
+//
+// xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+// assertTrue(xmlSchemaTypesIterator.hasNext());
+// assertEquals("baz", xmlSchemaTypesIterator.next().getName());
+// assertFalse(xmlSchemaTypesIterator.hasNext());
+//
+//
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.removeXmlSchemaType(declaration, 0);
+// }
+// });
+//
+// xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+// assertFalse(xmlSchemaTypesIterator.hasNext());
+// }
+//
+// public void testSyncAddXmlSchemaTypes() throws Exception {
+// this.createPackageInfoWithAccessorType();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// ListIterable<XmlSchemaType> xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes();
+// assertFalse(xmlSchemaTypes.iterator().hasNext());
+//
+// //add 1 XmlSchemaType when none exist
+// AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.addXmlSchemaType(declaration, 0, "bar");
+// }
+// });
+//
+// xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes();
+// ListIterator<XmlSchemaType> xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+// assertTrue(xmlSchemaTypesIterator.hasNext());
+// assertEquals("bar", xmlSchemaTypesIterator.next().getName());
+// assertFalse(xmlSchemaTypesIterator.hasNext());
+//
+//
+// //add 1 XmlSchemaType when 1 standalone exists
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.addXmlSchemaType(declaration, 1, "foo");
+// }
+// });
+//
+// xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes();
+// xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+// assertTrue(xmlSchemaTypesIterator.hasNext());
+// assertEquals("bar", xmlSchemaTypesIterator.next().getName());
+// assertEquals("foo", xmlSchemaTypesIterator.next().getName());
+// assertFalse(xmlSchemaTypesIterator.hasNext());
+//
+// //add 1 XmlSchemaType when a container annotations exists
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.addXmlSchemaType(declaration, 2, "baz");
+// }
+// });
+//
+// xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes();
+// xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+// assertTrue(xmlSchemaTypesIterator.hasNext());
+// assertEquals("bar", xmlSchemaTypesIterator.next().getName());
+// assertEquals("foo", xmlSchemaTypesIterator.next().getName());
+// assertEquals("baz", xmlSchemaTypesIterator.next().getName());
+// assertFalse(xmlSchemaTypesIterator.hasNext());
+//
+// //add 1 XmlSchemaType to beginning of list when a container annotations exists
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.addXmlSchemaType(declaration, 0, "foobaz");
+// }
+// });
+//
+// xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes();
+// xmlSchemaTypesIterator = xmlSchemaTypes.iterator();
+// assertTrue(xmlSchemaTypesIterator.hasNext());
+// assertEquals("foobaz", xmlSchemaTypesIterator.next().getName());
+// assertEquals("bar", xmlSchemaTypesIterator.next().getName());
+// assertEquals("foo", xmlSchemaTypesIterator.next().getName());
+// assertEquals("baz", xmlSchemaTypesIterator.next().getName());
+// assertFalse(xmlSchemaTypesIterator.hasNext());
+// }
+//
+// protected void moveXmlSchemaType(ModifiedDeclaration declaration, int targetIndex, int sourceIndex) {
+// this.moveArrayElement((NormalAnnotation) declaration.getAnnotationNamed(JAXB.XML_SCHEMA_TYPES), JAXB.XML_SCHEMA_TYPES__VALUE, targetIndex, sourceIndex);
+// }
+//
+// protected void removeXmlSchemaType(ModifiedDeclaration declaration, int index) {
+// this.removeArrayElement((NormalAnnotation) declaration.getAnnotationNamed(JAXB.XML_SCHEMA_TYPES), JAXB.XML_SCHEMA_TYPES__VALUE, index);
+// }
+//
+//
+//
+//
+//
+// public void testGetXmlJavaTypeAdapters() throws Exception {
+// this.createPackageInfoWithAccessorOrder();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// ListIterable<XmlJavaTypeAdapter> xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters();
+// assertFalse(xmlJavaTypeAdapters.iterator().hasNext());
+//
+// //add 2 XmlJavaTypeAdapters
+// AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.addXmlJavaTypeAdapter(declaration, 0, "String");
+// GenericRootContextNodeTests.this.addXmlJavaTypeAdapter(declaration, 1, "Integer");
+// }
+// });
+//
+// xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters();
+// ListIterator<XmlJavaTypeAdapter> xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator();
+// assertTrue(xmlJavaTypeAdaptersIterator.hasNext());
+// assertEquals("String", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertEquals("Integer", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertFalse(xmlJavaTypeAdaptersIterator.hasNext());
+// }
+//
+// protected void addXmlJavaTypeAdapter(ModifiedDeclaration declaration, int index, String name) {
+// NormalAnnotation arrayElement = this.newXmlJavaTypeAdapterAnnotation(declaration.getAst(), name);
+// this.addArrayElement(declaration, JAXB.XML_JAVA_TYPE_ADAPTERS, index, JAXB.XML_JAVA_TYPE_ADAPTERS__VALUE, arrayElement);
+// }
+//
+// protected NormalAnnotation newXmlJavaTypeAdapterAnnotation(AST ast, String valueTypeName) {
+// NormalAnnotation annotation = this.newNormalAnnotation(ast, JAXB.XML_JAVA_TYPE_ADAPTER);
+// this.addMemberValuePair(
+// annotation,
+// JAXB.XML_JAVA_TYPE_ADAPTER__VALUE,
+// this.newTypeLiteral(ast, valueTypeName));
+// return annotation;
+// }
+//
+// public void testGetXmlJavaTypeAdaptersSize() throws Exception {
+// this.createPackageInfoWithAccessorOrder();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// assertEquals(0, contextPackageInfo.getXmlJavaTypeAdaptersSize());
+//
+// //add 2 XmlJavaTypeAdapters
+// AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.addXmlJavaTypeAdapter(declaration, 0, "String");
+// GenericRootContextNodeTests.this.addXmlJavaTypeAdapter(declaration, 1, "Integer");
+// }
+// });
+// assertEquals(2, contextPackageInfo.getXmlJavaTypeAdaptersSize());
+// }
+//
+// public void testAddXmlJavaTypeAdapter() throws Exception {
+// //create a package info with an annotation other than XmlSchema to test
+// //adding things to the null schema annotation
+// this.createPackageInfoWithAccessorType();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("bar");
+// contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("foo");
+// contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("baz");
+//
+// Iterator<XmlJavaTypeAdapterAnnotation> xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage);
+//
+// assertEquals("baz", xmlJavaTypeAdapters.next().getValue());
+// assertEquals("foo", xmlJavaTypeAdapters.next().getValue());
+// assertEquals("bar", xmlJavaTypeAdapters.next().getValue());
+// assertFalse(xmlJavaTypeAdapters.hasNext());
+// }
+//
+// @SuppressWarnings("unchecked")
+// protected Iterator<XmlJavaTypeAdapterAnnotation> getXmlJavaTypeAdapterAnnotations(JavaResourcePackage resourcePackage) {
+// return (Iterator<XmlJavaTypeAdapterAnnotation>) resourcePackage.getAnnotations(JAXB.XML_JAVA_TYPE_ADAPTER).iterator();
+// }
+//
+// public void testAddXmlJavaTypeAdapter2() throws Exception {
+// //create a package info with an annotation other than XmlSchema to test
+// //adding things to the null schema annotation
+// this.createPackageInfoWithAccessorType();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("bar");
+// contextPackageInfo.addXmlJavaTypeAdapter(1).setValue("foo");
+// contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("baz");
+//
+// Iterator<XmlJavaTypeAdapterAnnotation> xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage);
+//
+// assertEquals("baz", xmlJavaTypeAdapters.next().getValue());
+// assertEquals("bar", xmlJavaTypeAdapters.next().getValue());
+// assertEquals("foo", xmlJavaTypeAdapters.next().getValue());
+// assertFalse(xmlJavaTypeAdapters.hasNext());
+// }
+//
+// public void testRemoveXmlJavaTypeAdapter() throws Exception {
+// this.createPackageInfoWithAccessorType();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("String");
+// contextPackageInfo.addXmlJavaTypeAdapter(1).setValue("foo");
+// contextPackageInfo.addXmlJavaTypeAdapter(2).setValue("baz");
+//
+// Iterator<XmlJavaTypeAdapterAnnotation> xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage);
+// XmlJavaTypeAdapterAnnotation adapterAnnotation = xmlJavaTypeAdapters.next();
+// assertEquals("String", adapterAnnotation.getValue());
+// assertEquals("java.lang.String", adapterAnnotation.getFullyQualifiedValue());
+// assertEquals("foo", xmlJavaTypeAdapters.next().getValue());
+// assertEquals("baz", xmlJavaTypeAdapters.next().getValue());
+// assertFalse(xmlJavaTypeAdapters.hasNext());
+//
+// contextPackageInfo.removeXmlJavaTypeAdapter(1);
+//
+// xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage);
+// adapterAnnotation = xmlJavaTypeAdapters.next();
+// assertEquals("String", adapterAnnotation.getValue());
+// assertEquals("java.lang.String", adapterAnnotation.getFullyQualifiedValue());
+// assertEquals("baz", xmlJavaTypeAdapters.next().getValue());
+// assertFalse(xmlJavaTypeAdapters.hasNext());
+//
+// contextPackageInfo.removeXmlJavaTypeAdapter(1);
+// xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage);
+// adapterAnnotation = xmlJavaTypeAdapters.next();
+// assertEquals("String", adapterAnnotation.getValue());
+// assertEquals("java.lang.String", adapterAnnotation.getFullyQualifiedValue());
+// assertFalse(xmlJavaTypeAdapters.hasNext());
+//
+// contextPackageInfo.removeXmlJavaTypeAdapter(0);
+// xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage);
+// assertFalse(xmlJavaTypeAdapters.hasNext());
+// }
+//
+// public void testMoveXmlJavaTypeAdapter() throws Exception {
+// this.createPackageInfoWithAccessorType();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("bar");
+// contextPackageInfo.addXmlJavaTypeAdapter(1).setValue("foo");
+// contextPackageInfo.addXmlJavaTypeAdapter(2).setValue("baz");
+//
+// Iterator<XmlJavaTypeAdapterAnnotation> xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage);
+// assertEquals("bar", xmlJavaTypeAdapters.next().getValue());
+// assertEquals("foo", xmlJavaTypeAdapters.next().getValue());
+// assertEquals("baz", xmlJavaTypeAdapters.next().getValue());
+// assertFalse(xmlJavaTypeAdapters.hasNext());
+//
+// contextPackageInfo.moveXmlJavaTypeAdapter(2, 0);
+// xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage);
+// assertEquals("foo", xmlJavaTypeAdapters.next().getValue());
+// assertEquals("baz", xmlJavaTypeAdapters.next().getValue());
+// assertEquals("bar", xmlJavaTypeAdapters.next().getValue());
+// assertFalse(xmlJavaTypeAdapters.hasNext());
+//
+// contextPackageInfo.moveXmlJavaTypeAdapter(0, 1);
+// xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage);
+// assertEquals("baz", xmlJavaTypeAdapters.next().getValue());
+// assertEquals("foo", xmlJavaTypeAdapters.next().getValue());
+// assertEquals("bar", xmlJavaTypeAdapters.next().getValue());
+// assertFalse(xmlJavaTypeAdapters.hasNext());
+// }
+//
+// public void testSyncXmlJavaTypeAdapters() throws Exception {
+// this.createPackageInfoWithAccessorType();
+// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+// JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+//
+// ListIterable<XmlJavaTypeAdapter> xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters();
+// assertFalse(xmlJavaTypeAdapters.iterator().hasNext());
+//
+// //add 3 XmlJavaTypeAdapters
+// AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.addXmlJavaTypeAdapter(declaration, 0, "bar");
+// GenericRootContextNodeTests.this.addXmlJavaTypeAdapter(declaration, 1, "foo");
+// GenericRootContextNodeTests.this.addXmlJavaTypeAdapter(declaration, 2, "baz");
+// }
+// });
+//
+// xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters();
+// ListIterator<XmlJavaTypeAdapter> xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator();
+// assertTrue(xmlJavaTypeAdaptersIterator.hasNext());
+// assertEquals("bar", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertEquals("foo", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertEquals("baz", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertFalse(xmlJavaTypeAdaptersIterator.hasNext());
+//
+//
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.moveXmlJavaTypeAdapter(declaration, 2, 0);
+// }
+// });
+//
+// xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters();
+// xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator();
+// assertTrue(xmlJavaTypeAdaptersIterator.hasNext());
+// assertEquals("foo", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertEquals("baz", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertEquals("bar", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertFalse(xmlJavaTypeAdaptersIterator.hasNext());
+//
+//
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.moveXmlJavaTypeAdapter(declaration, 0, 1);
+// }
+// });
+//
+// xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters();
+// xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator();
+// assertTrue(xmlJavaTypeAdaptersIterator.hasNext());
+// assertEquals("baz", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertEquals("foo", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertEquals("bar", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertFalse(xmlJavaTypeAdaptersIterator.hasNext());
+//
+//
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.removeXmlJavaTypeAdapter(declaration, 1);
+// }
+// });
+//
+// xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters();
+// xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator();
+// assertTrue(xmlJavaTypeAdaptersIterator.hasNext());
+// assertEquals("baz", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertEquals("bar", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertFalse(xmlJavaTypeAdaptersIterator.hasNext());
+//
+//
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.removeXmlJavaTypeAdapter(declaration, 1);
+// }
+// });
+//
+// xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters();
+// xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator();
+// assertTrue(xmlJavaTypeAdaptersIterator.hasNext());
+// assertEquals("baz", xmlJavaTypeAdaptersIterator.next().getValue());
+// assertFalse(xmlJavaTypeAdaptersIterator.hasNext());
+//
+//
+// annotatedElement.edit(new Member.Editor() {
+// public void edit(ModifiedDeclaration declaration) {
+// GenericRootContextNodeTests.this.removeXmlJavaTypeAdapter(declaration, 0);
+// }
+// });
+//
+// xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters();
+// xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator();
+// assertFalse(xmlJavaTypeAdaptersIterator.hasNext());
+// }
+//
+//
+// protected void moveXmlJavaTypeAdapter(ModifiedDeclaration declaration, int targetIndex, int sourceIndex) {
+// this.moveArrayElement((NormalAnnotation) declaration.getAnnotationNamed(JAXB.XML_JAVA_TYPE_ADAPTERS), JAXB.XML_JAVA_TYPE_ADAPTERS__VALUE, targetIndex, sourceIndex);
+// }
+//
+// protected void removeXmlJavaTypeAdapter(ModifiedDeclaration declaration, int index) {
+// this.removeArrayElement((NormalAnnotation) declaration.getAnnotationNamed(JAXB.XML_JAVA_TYPE_ADAPTERS), JAXB.XML_JAVA_TYPE_ADAPTERS__VALUE, index);
+// }
+}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/JaxbCoreContextModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/JaxbCoreContextModelTests.java
index f6ad58cdc5..f14a17beb2 100644
--- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/JaxbCoreContextModelTests.java
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/JaxbCoreContextModelTests.java
@@ -20,6 +20,7 @@ public class JaxbCoreContextModelTests extends TestCase
public static Test suite() {
TestSuite suite = new TestSuite(JaxbCoreContextModelTests.class.getName());
+ suite.addTestSuite(GenericRootContextNodeTests.class);
suite.addTest(JaxbCoreJavaContextModelTests.suite());
return suite;
}
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/AnnotationTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/AnnotationTestCase.java
index 4520c25877..e80584279f 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/AnnotationTestCase.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/AnnotationTestCase.java
@@ -137,6 +137,13 @@ public abstract class AnnotationTestCase extends TestCase {
return this.createTestPackageInfo(new DefaultAnnotationWriter());
}
+ /**
+ * create an un-annotated package-info in a package the given name
+ */
+ protected ICompilationUnit createTestPackageInfo(String packageName) throws CoreException {
+ return this.createTestPackageInfo(packageName, new DefaultAnnotationWriter());
+ }
+
/**
* shortcut for simply adding an annotation to the package declaration
*/
@@ -159,8 +166,12 @@ public abstract class AnnotationTestCase extends TestCase {
}
protected ICompilationUnit createTestPackageInfo(AnnotationWriter annotationWriter) throws CoreException {
+ return this.createTestPackageInfo(PACKAGE_NAME, annotationWriter);
+ }
+
+ protected ICompilationUnit createTestPackageInfo(String packageName, AnnotationWriter annotationWriter) throws CoreException {
return this.javaProject.createCompilationUnit(
- PACKAGE_NAME, PACKAGE_INFO_FILE_NAME, this.createSourceWriter(annotationWriter, null));
+ packageName, PACKAGE_INFO_FILE_NAME, this.createSourceWriter(annotationWriter, packageName, null));
}
@@ -214,6 +225,10 @@ public abstract class AnnotationTestCase extends TestCase {
return new AnnotatedSourceWriter(annotationWriter, typeName);
}
+ protected SourceWriter createSourceWriter(AnnotationWriter annotationWriter, String packageName, String typeName) {
+ return new AnnotatedSourceWriter(annotationWriter, packageName, typeName);
+ }
+
/**
* writes source for package-info java files
*/

Back to the top