Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Butzke2012-08-13 14:48:55 +0000
committerKaren Butzke2012-08-13 14:48:55 +0000
commit8c0d77936463dd270e0b95e462535345d901d344 (patch)
tree615a5ce7e66a0f0535a9125f2b1c7d46b520edbc /jpa/tests/org.eclipse.jpt.jpa.core.tests
parent972058e65cc0c67f5cd38a461c513305456a3130 (diff)
downloadwebtools.dali-8c0d77936463dd270e0b95e462535345d901d344.tar.gz
webtools.dali-8c0d77936463dd270e0b95e462535345d901d344.tar.xz
webtools.dali-8c0d77936463dd270e0b95e462535345d901d344.zip
bug 373430 - element collection with primitive target class and map key
class has incorrect errors
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.jpa.core.tests')
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java37
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java42
2 files changed, 77 insertions, 2 deletions
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java
index 92f96531e7..1b2160cc96 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 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.
@@ -66,6 +66,19 @@ public class ElementCollection2_0AnnotationTests extends JavaResourceModel2_0Tes
});
}
+ private ICompilationUnit createTestElementCollectionWithPrimitiveTargetClass() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_0.ELEMENT_COLLECTION);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@ElementCollection(targetClass = byte.class)");
+ }
+ });
+ }
+
public void testElementCollection() throws Exception {
ICompilationUnit cu = this.createTestElementCollection();
JavaResourceType resourceType = buildJavaResourceType(cu);
@@ -167,4 +180,26 @@ public class ElementCollection2_0AnnotationTests extends JavaResourceModel2_0Tes
assertEquals("Foo", elementCollection.getFullyQualifiedTargetClassName()); //bug 196200 changed this
}
+
+ public void testGetPrimitiveTargetClass() throws Exception {
+ ICompilationUnit cu = this.createTestElementCollectionWithPrimitiveTargetClass();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceField = CollectionTools.get(resourceType.getFields(), 0);
+
+ ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) resourceField.getAnnotation(JPA2_0.ELEMENT_COLLECTION);
+ assertEquals("byte", elementCollection.getTargetClass());
+ }
+
+ public void testSetPrimitiveTargetClass() throws Exception {
+ ICompilationUnit cu = this.createTestElementCollection();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceField = CollectionTools.get(resourceType.getFields(), 0);
+
+ ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) resourceField.getAnnotation(JPA2_0.ELEMENT_COLLECTION);
+ assertEquals(null, elementCollection.getTargetClass());
+
+ elementCollection.setTargetClass("int");
+
+ assertSourceContains("@ElementCollection(targetClass = int.class)", cu);
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java
index 8d64639bdb..54746b5c89 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 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.
@@ -53,6 +53,19 @@ public class MapKeyClass2_0AnnotationTests extends JavaResourceModel2_0TestCase
});
}
+ private ICompilationUnit createTestMapKeyClassWithPrimitiveValue() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_0.MAP_KEY_CLASS);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@MapKeyClass(value=int.class)");
+ }
+ });
+ }
+
public void testMapKeyClass() throws Exception {
ICompilationUnit cu = this.createTestMapKeyClass();
JavaResourceType resourceType = buildJavaResourceType(cu);
@@ -106,4 +119,31 @@ public class MapKeyClass2_0AnnotationTests extends JavaResourceModel2_0TestCase
assertSourceContains("@MapKeyClass(" + TYPE_NAME + ".class)", cu);
}
+ public void testGetPrimitiveValue() throws Exception {
+ ICompilationUnit cu = this.createTestMapKeyClassWithPrimitiveValue();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceField = CollectionTools.get(resourceType.getFields(), 0);
+
+ MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) resourceField.getAnnotation(JPA2_0.MAP_KEY_CLASS);
+ assertEquals("int", mapKeyClass.getValue());
+ assertEquals("int", mapKeyClass.getFullyQualifiedClassName());
+ }
+
+ public void testSetPrimitiveValue() throws Exception {
+ ICompilationUnit cu = this.createTestMapKeyClassWithValue();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceField = CollectionTools.get(resourceType.getFields(), 0);
+
+ MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) resourceField.getAnnotation(JPA2_0.MAP_KEY_CLASS);
+ assertEquals(MAP_KEY_CLASS_VALUE, mapKeyClass.getValue());
+
+ mapKeyClass.setValue("int");
+ assertEquals("int", mapKeyClass.getValue());
+
+ assertSourceContains("@MapKeyClass(int.class)", cu);
+
+ mapKeyClass.setValue(null);
+
+ assertSourceDoesNotContain("@MapKeyClass(", cu);
+ }
}

Back to the top