summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Butzke2013-02-07 15:33:04 (EST)
committerKaren Butzke2013-02-07 16:17:58 (EST)
commitbc001eecb86ac5ed062d8b41cde8313c447616d2 (patch)
tree17b302bc5170e9a82946213291cbecc84c424c05
parentdf1e45f9465ccb295be148601fc9f12a7d4defbf (diff)
downloadwebtools.dali-bc001eecb86ac5ed062d8b41cde8313c447616d2.zip
webtools.dali-bc001eecb86ac5ed062d8b41cde8313c447616d2.tar.gz
webtools.dali-bc001eecb86ac5ed062d8b41cde8313c447616d2.tar.bz2
Added a check in the resource model tests for all of the annotations being on the project classpath. This will help when a new jar is need because of new annotations
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java51
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/JavaResourceModel2_0TestCase.java10
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JavaResourceModelTestCase.java171
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JpaJavaResourceModelTestCase.java29
4 files changed, 74 insertions, 187 deletions
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java
index e782a8b..c3793b8 100644
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java
+++ b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2013 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.
@@ -15,6 +15,7 @@ import org.eclipse.jdt.core.IElementChangedListener;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaElementDelta;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jpt.common.core.AnnotationProvider;
import org.eclipse.jpt.common.core.GenericAnnotationProvider;
import org.eclipse.jpt.common.core.internal.resource.java.source.SourcePackageInfoCompilationUnit;
@@ -134,26 +135,26 @@ public abstract class JavaResourceModelTestCase
return this.javaProject.createCompilationUnit(packageName, enumName + ".java", "public enum " + enumName + " { " + enumBody + " }");
}
- protected JavaResourcePackage buildJavaResourcePackage(ICompilationUnit cu) {
+ protected JavaResourcePackage buildJavaResourcePackage(ICompilationUnit cu) throws JavaModelException {
JavaResourcePackageInfoCompilationUnit pkgCu =
new SourcePackageInfoCompilationUnit(
cu,
- this.buildAnnotationProvider(),
+ this.buildAndVerifyAnnotationProvider(),
NullAnnotationEditFormatter.instance(),
CommandExecutor.Default.instance());
this.javaResourceCompilationUnit = pkgCu;
return pkgCu.getPackage();
}
- protected JavaResourceType buildJavaResourceType(ICompilationUnit cu) {
+ protected JavaResourceType buildJavaResourceType(ICompilationUnit cu) throws JavaModelException {
return (JavaResourceType) this.buildJavaResourceType_(cu);
}
- protected JavaResourceEnum buildJavaResourceEnum(ICompilationUnit cu) {
+ protected JavaResourceEnum buildJavaResourceEnum(ICompilationUnit cu) throws JavaModelException {
return (JavaResourceEnum) this.buildJavaResourceType_(cu);
}
- private JavaResourceAbstractType buildJavaResourceType_(ICompilationUnit cu) {
+ private JavaResourceAbstractType buildJavaResourceType_(ICompilationUnit cu) throws JavaModelException {
this.javaResourceCompilationUnit = this.buildJavaResourceCompilationUnit(cu);
return this.hackJavaResourceType();
}
@@ -174,15 +175,22 @@ public abstract class JavaResourceModelTestCase
return (JavaResourceAbstractType) ObjectTools.get(this.javaResourceCompilationUnit, "primaryType");
}
- protected JavaResourceCompilationUnit buildJavaResourceCompilationUnit(ICompilationUnit cu) {
+ protected JavaResourceCompilationUnit buildJavaResourceCompilationUnit(ICompilationUnit cu) throws JavaModelException {
if (this.javaResourceCompilationUnit != null) {
throw new IllegalStateException();
}
return new SourceTypeCompilationUnit(
cu,
- this.buildAnnotationProvider(),
+ this.buildAndVerifyAnnotationProvider(),
NullAnnotationEditFormatter.instance(),
- CommandExecutor.Default.instance());
+ CommandExecutor.Default.instance()
+ );
+ }
+
+ protected AnnotationProvider buildAndVerifyAnnotationProvider() throws JavaModelException {
+ AnnotationProvider annotationProvider = this.buildAnnotationProvider();
+ this.verifyAnnotationClassesExist(annotationProvider);
+ return annotationProvider;
}
protected AnnotationProvider buildAnnotationProvider() {
@@ -192,4 +200,29 @@ public abstract class JavaResourceModelTestCase
protected abstract AnnotationDefinition[] annotationDefinitions();
protected abstract NestableAnnotationDefinition[] nestableAnnotationDefinitions();
+
+
+ private void verifyAnnotationClassesExist(AnnotationProvider annotationProvider) throws JavaModelException {
+ for (String annotationName : this.getAllAnnotationNames(annotationProvider)) {
+ if (getJavaProject().getJavaProject().findType(annotationName) == null) {
+ //if running the tests with jre 1.5, the javax.annotation.Generated class will not be found
+ if (!annotationName.equals("javax.annotation.Generated")) {
+ fail(errorMissingAnnotationClass(annotationName));
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private Iterable<String> getAllAnnotationNames(AnnotationProvider annotationProvider) {
+ return IterableTools.concatenate(
+ annotationProvider.getAnnotationNames(),
+ annotationProvider.getContainerAnnotationNames(),
+ annotationProvider.getNestableAnnotationNames());
+ }
+
+ /*********** private **********/
+ private static String errorMissingAnnotationClass(String annotationName) {
+ return "Annotation class " + annotationName + " is not on the classpath. Check the Java system property org.eclipse.jpt.jpa.jar";
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/JavaResourceModel2_0TestCase.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/JavaResourceModel2_0TestCase.java
index 933d5c1..af9df6d 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/JavaResourceModel2_0TestCase.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/JavaResourceModel2_0TestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2013 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.
@@ -9,8 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.tests.internal.jpa2.resource.java;
-import org.eclipse.jpt.common.core.AnnotationProvider;
-import org.eclipse.jpt.jpa.core.internal.JpaAnnotationProvider;
+import org.eclipse.jpt.jpa.core.JpaAnnotationDefinitionProvider;
import org.eclipse.jpt.jpa.core.internal.jpa2.Generic2_0JpaAnnotationDefinitionProvider;
import org.eclipse.jpt.jpa.core.tests.internal.resource.java.JpaJavaResourceModelTestCase;
@@ -22,8 +21,7 @@ public class JavaResourceModel2_0TestCase extends JpaJavaResourceModelTestCase
}
@Override
- protected AnnotationProvider buildAnnotationProvider() {
- return new JpaAnnotationProvider(
- Generic2_0JpaAnnotationDefinitionProvider.instance());
+ protected JpaAnnotationDefinitionProvider annotationDefinitionProvider() {
+ return Generic2_0JpaAnnotationDefinitionProvider.instance();
}
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JavaResourceModelTestCase.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JavaResourceModelTestCase.java
deleted file mode 100644
index a3075d1..0000000
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JavaResourceModelTestCase.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 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.jpa.core.tests.internal.resource.java;
-
-import org.eclipse.jdt.core.ElementChangedEvent;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IElementChangedListener;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IJavaElementDelta;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jpt.common.core.AnnotationProvider;
-import org.eclipse.jpt.common.core.internal.resource.java.source.SourcePackageInfoCompilationUnit;
-import org.eclipse.jpt.common.core.internal.resource.java.source.SourceTypeCompilationUnit;
-import org.eclipse.jpt.common.core.internal.utility.jdt.NullAnnotationEditFormatter;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
-import org.eclipse.jpt.common.core.resource.java.JavaResourcePackage;
-import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageInfoCompilationUnit;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
-import org.eclipse.jpt.common.core.tests.internal.utility.jdt.AnnotationTestCase;
-import org.eclipse.jpt.common.utility.command.CommandExecutor;
-import org.eclipse.jpt.common.utility.internal.BitTools;
-import org.eclipse.jpt.common.utility.internal.ObjectTools;
-import org.eclipse.jpt.jpa.core.JpaAnnotationDefinitionProvider;
-import org.eclipse.jpt.jpa.core.internal.GenericJpaAnnotationDefinitionProvider;
-import org.eclipse.jpt.jpa.core.internal.JpaAnnotationProvider;
-
-
-@SuppressWarnings("nls")
-public class JavaResourceModelTestCase
- extends AnnotationTestCase {
-
- private JavaElementChangeListener javaElementChangeListener;
- protected JavaResourceCompilationUnit javaResourceCompilationUnit;
-
-
- public JavaResourceModelTestCase(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- this.javaElementChangeListener = new JavaElementChangeListener();
- JavaCore.addElementChangedListener(this.javaElementChangeListener);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- JavaCore.removeElementChangedListener(this.javaElementChangeListener);
- this.javaElementChangeListener = null;
- }
-
- private class JavaElementChangeListener
- implements IElementChangedListener {
-
- JavaElementChangeListener() {
- super();
- }
-
- public void elementChanged(ElementChangedEvent event) {
- JavaResourceModelTestCase.this.javaElementChanged(event);
- }
-
- @Override
- public String toString() {
- return ObjectTools.toString(this);
- }
- }
-
- void javaElementChanged(ElementChangedEvent event) {
- if (this.javaResourceCompilationUnit == null) {
- return;
- }
- this.syncWithJavaDelta(event.getDelta());
- }
-
- /**
- * NB: this is copied from GenericJpaProject, so it might need to be
- * kept in synch with that code if it changes... yech...
- */
- protected void syncWithJavaDelta(IJavaElementDelta delta) {
- switch (delta.getElement().getElementType()) {
- case IJavaElement.JAVA_MODEL :
- case IJavaElement.JAVA_PROJECT :
- case IJavaElement.PACKAGE_FRAGMENT_ROOT :
- case IJavaElement.PACKAGE_FRAGMENT :
- this.syncWithJavaDeltaChildren(delta);
- break;
- case IJavaElement.COMPILATION_UNIT :
- this.javaCompilationUnitChanged(delta);
- break;
- default :
- break; // ignore the elements inside a compilation unit
- }
- }
-
- protected void syncWithJavaDeltaChildren(IJavaElementDelta delta) {
- for (IJavaElementDelta child : delta.getAffectedChildren()) {
- this.syncWithJavaDelta(child); // recurse
- }
- }
-
- protected void javaCompilationUnitChanged(IJavaElementDelta delta) {
- if (this.deltaIsRelevant(delta)) {
- this.javaResourceCompilationUnit.synchronizeWithJavaSource();
- }
- }
-
- protected boolean deltaIsRelevant(IJavaElementDelta delta) {
- if (BitTools.onlyFlagIsSet(delta.getFlags(), IJavaElementDelta.F_PRIMARY_WORKING_COPY)) {
- return false;
- }
- return delta.getKind() == IJavaElementDelta.CHANGED;
- }
-
- protected ICompilationUnit createAnnotationAndMembers(String packageName, String annotationName, String annotationBody) throws Exception {
- return this.javaProject.createCompilationUnit(packageName, annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }");
- }
-
- protected ICompilationUnit createEnumAndMembers(String packageName, String enumName, String enumBody) throws Exception {
- return this.javaProject.createCompilationUnit(packageName, enumName + ".java", "public enum " + enumName + " { " + enumBody + " }");
- }
-
- protected JavaResourcePackage buildJavaResourcePackage(ICompilationUnit cu) {
- JavaResourcePackageInfoCompilationUnit pkgCu =
- new SourcePackageInfoCompilationUnit(
- cu,
- this.buildAnnotationProvider(),
- NullAnnotationEditFormatter.instance(),
- CommandExecutor.Default.instance());
- this.javaResourceCompilationUnit = pkgCu;
- return pkgCu.getPackage();
- }
-
- protected JavaResourceType buildJavaResourceType(ICompilationUnit cu) {
- this.javaResourceCompilationUnit = this.buildJavaResourceCompilationUnit(cu);
- return this.hackJavaResourceType();
- }
-
- protected JavaResourceType hackJavaResourceType() {
- return (JavaResourceType) ObjectTools.get(this.javaResourceCompilationUnit, "primaryType");
- }
-
- protected JavaResourceCompilationUnit buildJavaResourceCompilationUnit(ICompilationUnit cu) {
- if (this.javaResourceCompilationUnit != null) {
- throw new IllegalStateException();
- }
- return new SourceTypeCompilationUnit(
- cu,
- this.buildAnnotationProvider(),
- NullAnnotationEditFormatter.instance(),
- CommandExecutor.Default.instance()
- );
- }
-
- protected AnnotationProvider buildAnnotationProvider() {
- return new JpaAnnotationProvider(this.annotationDefinitionProvider());
- }
-
- protected JpaAnnotationDefinitionProvider annotationDefinitionProvider() {
- return GenericJpaAnnotationDefinitionProvider.instance();
- }
-}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JpaJavaResourceModelTestCase.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JpaJavaResourceModelTestCase.java
index 18e758c..4204193 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JpaJavaResourceModelTestCase.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/resource/java/JpaJavaResourceModelTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 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.
@@ -10,8 +10,16 @@
package org.eclipse.jpt.jpa.core.tests.internal.resource.java;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.common.core.AnnotationProvider;
+import org.eclipse.jpt.common.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.common.core.resource.java.NestableAnnotationDefinition;
+import org.eclipse.jpt.common.core.tests.internal.resource.java.JavaResourceModelTestCase;
+import org.eclipse.jpt.jpa.core.JpaAnnotationDefinitionProvider;
+import org.eclipse.jpt.jpa.core.internal.GenericJpaAnnotationDefinitionProvider;
+import org.eclipse.jpt.jpa.core.internal.JpaAnnotationProvider;
import org.eclipse.jpt.jpa.core.tests.internal.projects.TestJpaProject;
+@SuppressWarnings("nls")
public class JpaJavaResourceModelTestCase
extends JavaResourceModelTestCase {
@@ -37,7 +45,26 @@ public class JpaJavaResourceModelTestCase
super.tearDown();
// nothing as of yet
}
+
+ @Override
+ protected AnnotationProvider buildAnnotationProvider() {
+ return new JpaAnnotationProvider(this.annotationDefinitionProvider());
+ }
+
+ protected JpaAnnotationDefinitionProvider annotationDefinitionProvider() {
+ return GenericJpaAnnotationDefinitionProvider.instance();
+ }
+ @Override
+ protected AnnotationDefinition[] annotationDefinitions() {
+ throw new UnsupportedOperationException("We build the AnnotationProvider for JPA differently for now");
+ }
+
+ @Override
+ protected NestableAnnotationDefinition[] nestableAnnotationDefinitions() {
+ throw new UnsupportedOperationException("We build the AnnotationProvider for JPA differently for now");
+ }
+
protected ICompilationUnit createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception {
return createAnnotationAndMembers(JAVAX_PERSISTENCE_PACKAGE_NAME, annotationName, annotationBody);
}