Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2010-11-17 15:53:44 -0500
committerkmoore2010-11-17 15:53:44 -0500
commit0fddf023a274d93acf7e21f9c0c5f57ea1134cc2 (patch)
tree7ced043bf12a97dc4df98fd8d368ec48f0af2060
parent99aa1028a4b7972edc03b2ed3337438d2179fec3 (diff)
downloadwebtools.dali-0fddf023a274d93acf7e21f9c0c5f57ea1134cc2.tar.gz
webtools.dali-0fddf023a274d93acf7e21f9c0c5f57ea1134cc2.tar.xz
webtools.dali-0fddf023a274d93acf7e21f9c0c5f57ea1134cc2.zip
added tests for jaxb GenericRootContextNode persistenceClasses
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java2
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java18
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/GenericRootContextNodeTests.java63
3 files changed, 77 insertions, 6 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java
index ff20203a9c..5108419e3f 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java
@@ -665,7 +665,7 @@ public abstract class AbstractJaxbProject
public JavaResourcePackage getAnnotatedJavaResourcePackage(String packageName) {
JavaResourcePackage jrp = getJavaResourcePackage(packageName);
- return (jrp.isAnnotated()) ? jrp : null;
+ return (jrp != null && jrp.isAnnotated()) ? jrp : null;
}
/**
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 e4862003cf..1d7c712720 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
@@ -103,6 +103,7 @@ public class GenericRootContextNode
final Set<String> packagesToRemove = CollectionTools.set(this.packages.keySet());
final Set<String> persistentClassesToBuild = CollectionTools.set(initialPersistentClasses);
final Set<String> persistentClassesToUpdate = CollectionTools.<String>set();
+ final Set<String> persistentClassesToRemove = CollectionTools.set(this.persistentClasses.keySet());
for (String packageToBuild : packagesToBuild) {
if (this.packages.containsKey(packageToBuild)) {
@@ -117,6 +118,7 @@ public class GenericRootContextNode
for (String classToBuild : persistentClassesToBuild) {
if (this.persistentClasses.containsKey(classToBuild)) {
persistentClassesToUpdate.add(classToBuild);
+ persistentClassesToRemove.remove(classToBuild);
}
else {
this.addPersistentClass(this.buildPersistentClass(classToBuild));
@@ -134,6 +136,10 @@ public class GenericRootContextNode
for (String packageToRemove : packagesToRemove) {
this.removePackage(packageToRemove);
}
+
+ for (String persistentClassToRemove : persistentClassesToRemove) {
+ this.removePersistentClass(persistentClassToRemove);
+ }
}
/*
@@ -174,7 +180,7 @@ public class GenericRootContextNode
}) {
@Override
protected String transform(JavaResourceType o) {
- return o.getName();
+ return o.getQualifiedName();
}
});
}
@@ -257,11 +263,15 @@ public class GenericRootContextNode
}
protected void removePersistentClass(JaxbPersistentClass persistentClass) {
- if (! this.persistentClasses.containsKey(persistentClass.getName())) {
+ this.removePersistentClass(persistentClass.getName());
+ }
+
+ protected void removePersistentClass(String persistentClassName) {
+ if (! this.persistentClasses.containsKey(persistentClassName)) {
throw new IllegalArgumentException("No class with that name exists."); //$NON-NLS-1$
}
- this.persistentClasses.remove(persistentClass.getName());
- fireItemRemoved(PERSISTENT_CLASSES_COLLECTION, persistentClass);
+ JaxbPersistentClass removedPersistentClass = this.persistentClasses.remove(persistentClassName);
+ fireItemRemoved(PERSISTENT_CLASSES_COLLECTION, removedPersistentClass);
}
protected JaxbPersistentClass buildPersistentClass(String className) {
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
index ba8d5c14e3..8f5150edd5 100644
--- 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
@@ -17,9 +17,11 @@ 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.context.JaxbPersistentClass;
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;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
@SuppressWarnings("nls")
@@ -40,6 +42,23 @@ public class GenericRootContextNodeTests extends JaxbContextModelTestCase
return createTestPackageInfo(packageName);
}
+ private ICompilationUnit createTypeWithXmlType() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlType");
+ }
+ });
+ }
+
+ private ICompilationUnit createUnannotatedTestTypeNamed(String typeName) throws Exception {
+ return this.createTestType(PACKAGE_NAME, typeName + ".java", typeName, new DefaultAnnotationWriter());
+ }
+
public void testGetPackages() throws Exception {
this.createPackageInfoWithAccessorOrder();
Iterator<JaxbPackage> packages = this.getRootContextNode().getPackages().iterator();
@@ -91,6 +110,48 @@ public class GenericRootContextNodeTests extends JaxbContextModelTestCase
this.removeAnnotation(declaration, JAXB.XML_ACCESSOR_TYPE);
}
+ public void testGetPersistentClasses() throws Exception {
+ this.createTypeWithXmlType();
+ Iterator<JaxbPersistentClass> persistentClasses = this.getRootContextNode().getPersistentClasses().iterator();
+ assertEquals(1, this.getRootContextNode().getPersistentClassesSize());
+ assertEquals(FULLY_QUALIFIED_TYPE_NAME, persistentClasses.next().getName());
+ assertFalse(persistentClasses.hasNext());
+
+ //add an unannotated class and make sure it's not added to the root context node
+ this.createUnannotatedTestTypeNamed("Foo");
+ persistentClasses = this.getRootContextNode().getPersistentClasses().iterator();
+ assertEquals(1, this.getRootContextNode().getPersistentClassesSize());
+ assertEquals(FULLY_QUALIFIED_TYPE_NAME, persistentClasses.next().getName());
+ assertFalse(persistentClasses.hasNext());
+
+ //annotate the class with @XmlType and test it's added to the root context node
+ JavaResourceType fooResourcePackage = getJaxbProject().getJavaResourceType("test.Foo");
+ AnnotatedElement annotatedElement = this.annotatedElement(fooResourcePackage);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericRootContextNodeTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_TYPE);
+ }
+ });
+
+ persistentClasses = this.getRootContextNode().getPersistentClasses().iterator();
+ assertEquals(2, this.getRootContextNode().getPersistentClassesSize());
+ assertEquals("test.Foo", persistentClasses.next().getName());
+ assertEquals(FULLY_QUALIFIED_TYPE_NAME, persistentClasses.next().getName());
+ assertFalse(persistentClasses.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.removeAnnotation(declaration, JAXB.XML_TYPE);
+ }
+ });
+
+ persistentClasses = this.getRootContextNode().getPersistentClasses().iterator();
+ assertEquals(1, this.getRootContextNode().getPersistentClassesSize());
+ assertEquals(FULLY_QUALIFIED_TYPE_NAME, persistentClasses.next().getName());
+ assertFalse(persistentClasses.hasNext());
+ }
+
// public void testGetXmlSchemaTypesSize() throws Exception {
// this.createPackageInfoWithAccessorOrder();
// JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();

Back to the top