Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortle2008-02-03 16:40:54 +0000
committertle2008-02-03 16:40:54 +0000
commit7f7b20a5d66bf69e88734ead5036e4d6664aa381 (patch)
tree97dacecfda81e183389ab1c0adb3a83b953823ad /jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java
parent145c144380950bd4b49fd4597a1a0695cf7c8b7b (diff)
downloadwebtools.dali-7f7b20a5d66bf69e88734ead5036e4d6664aa381.tar.gz
webtools.dali-7f7b20a5d66bf69e88734ead5036e4d6664aa381.tar.xz
webtools.dali-7f7b20a5d66bf69e88734ead5036e4d6664aa381.zip
Merged jpt_2_0_exp branch into Head.v20080202_Merged
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java')
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java259
1 files changed, 259 insertions, 0 deletions
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java
new file mode 100644
index 0000000000..9883e34329
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java
@@ -0,0 +1,259 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.core.tests.internal.context.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jpt.core.internal.IMappingKeys;
+import org.eclipse.jpt.core.internal.context.base.IBasicMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IEmbeddedMapping;
+import org.eclipse.jpt.core.internal.context.base.IIdMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IManyToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToManyMapping;
+import org.eclipse.jpt.core.internal.context.base.IOneToOneMapping;
+import org.eclipse.jpt.core.internal.context.base.IPersistentAttribute;
+import org.eclipse.jpt.core.internal.context.base.ITransientMapping;
+import org.eclipse.jpt.core.internal.context.base.IVersionMapping;
+import org.eclipse.jpt.core.internal.resource.java.Basic;
+import org.eclipse.jpt.core.internal.resource.java.Embedded;
+import org.eclipse.jpt.core.internal.resource.java.EmbeddedId;
+import org.eclipse.jpt.core.internal.resource.java.Id;
+import org.eclipse.jpt.core.internal.resource.java.JPA;
+import org.eclipse.jpt.core.internal.resource.java.JavaPersistentAttributeResource;
+import org.eclipse.jpt.core.internal.resource.java.JavaPersistentTypeResource;
+import org.eclipse.jpt.core.internal.resource.java.ManyToMany;
+import org.eclipse.jpt.core.internal.resource.java.ManyToOne;
+import org.eclipse.jpt.core.internal.resource.java.OneToMany;
+import org.eclipse.jpt.core.internal.resource.java.OneToOne;
+import org.eclipse.jpt.core.internal.resource.java.Transient;
+import org.eclipse.jpt.core.internal.resource.java.Version;
+import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+public class JavaTransientMappingTests extends ContextModelTestCase
+{
+ private void createEntityAnnotation() throws Exception{
+ this.createAnnotationAndMembers("Entity", "String name() default \"\";");
+ }
+
+ private void createTransientAnnotation() throws Exception{
+ this.createAnnotationAndMembers("Transient", "");
+ }
+
+ private IType createTestEntityWithTransientMapping() throws Exception {
+ createEntityAnnotation();
+ createTransientAnnotation();
+
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.TRANSIENT);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity").append(CR);
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Transient").append(CR);
+ }
+ });
+ }
+
+ public JavaTransientMappingTests(String name) {
+ super(name);
+ }
+
+ public void testMorphToBasicMapping() throws Exception {
+ createTestEntityWithTransientMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IPersistentAttribute persistentAttribute = javaPersistentType().attributes().next();
+ ITransientMapping transientMapping = (ITransientMapping) persistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ persistentAttribute.setSpecifiedMappingKey(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof IBasicMapping);
+ assertFalse(persistentAttribute.getMapping().isDefault());
+
+ JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME);
+ JavaPersistentAttributeResource attributeResource = typeResource.attributes().next();
+ assertNull(attributeResource.mappingAnnotation(Transient.ANNOTATION_NAME));
+ assertNotNull(attributeResource.mappingAnnotation(Basic.ANNOTATION_NAME));
+ }
+
+ public void testMorphToDefault() throws Exception {
+ createTestEntityWithTransientMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IPersistentAttribute persistentAttribute = javaPersistentType().attributes().next();
+ ITransientMapping transientMapping = (ITransientMapping) persistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ persistentAttribute.setSpecifiedMappingKey(IMappingKeys.NULL_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof IBasicMapping);
+ assertTrue(persistentAttribute.getMapping().isDefault());
+
+ JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME);
+ JavaPersistentAttributeResource attributeResource = typeResource.attributes().next();
+ assertNull(attributeResource.mappingAnnotation(Transient.ANNOTATION_NAME));
+ }
+
+ public void testMorphToVersionMapping() throws Exception {
+ createTestEntityWithTransientMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IPersistentAttribute persistentAttribute = javaPersistentType().attributes().next();
+ ITransientMapping transientMapping = (ITransientMapping) persistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ persistentAttribute.setSpecifiedMappingKey(IMappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof IVersionMapping);
+
+ JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME);
+ JavaPersistentAttributeResource attributeResource = typeResource.attributes().next();
+ assertNull(attributeResource.mappingAnnotation(Transient.ANNOTATION_NAME));
+ assertNotNull(attributeResource.mappingAnnotation(Version.ANNOTATION_NAME));
+ }
+
+ public void testMorphToEmbeddedMapping() throws Exception {
+ createTestEntityWithTransientMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IPersistentAttribute persistentAttribute = javaPersistentType().attributes().next();
+ ITransientMapping transientMapping = (ITransientMapping) persistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ persistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof IEmbeddedMapping);
+
+ JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME);
+ JavaPersistentAttributeResource attributeResource = typeResource.attributes().next();
+ assertNull(attributeResource.mappingAnnotation(Transient.ANNOTATION_NAME));
+ assertNotNull(attributeResource.mappingAnnotation(Embedded.ANNOTATION_NAME));
+ }
+
+ public void testMorphToIdMapping() throws Exception {
+ createTestEntityWithTransientMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IPersistentAttribute persistentAttribute = javaPersistentType().attributes().next();
+ ITransientMapping transientMapping = (ITransientMapping) persistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ persistentAttribute.setSpecifiedMappingKey(IMappingKeys.ID_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof IIdMapping);
+
+ JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME);
+ JavaPersistentAttributeResource attributeResource = typeResource.attributes().next();
+ assertNull(attributeResource.mappingAnnotation(Transient.ANNOTATION_NAME));
+ assertNotNull(attributeResource.mappingAnnotation(Id.ANNOTATION_NAME));
+ }
+
+ public void testMorphToEmbeddedIdMapping() throws Exception {
+ createTestEntityWithTransientMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IPersistentAttribute persistentAttribute = javaPersistentType().attributes().next();
+ ITransientMapping transientMapping = (ITransientMapping) persistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ persistentAttribute.setSpecifiedMappingKey(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof IEmbeddedIdMapping);
+
+ JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME);
+ JavaPersistentAttributeResource attributeResource = typeResource.attributes().next();
+ assertNull(attributeResource.mappingAnnotation(Transient.ANNOTATION_NAME));
+ assertNotNull(attributeResource.mappingAnnotation(EmbeddedId.ANNOTATION_NAME));
+ }
+
+ public void testMorphToOneToOneMapping() throws Exception {
+ createTestEntityWithTransientMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IPersistentAttribute persistentAttribute = javaPersistentType().attributes().next();
+ ITransientMapping transientMapping = (ITransientMapping) persistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ persistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof IOneToOneMapping);
+
+ JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME);
+ JavaPersistentAttributeResource attributeResource = typeResource.attributes().next();
+ assertNull(attributeResource.mappingAnnotation(Transient.ANNOTATION_NAME));
+ assertNotNull(attributeResource.mappingAnnotation(OneToOne.ANNOTATION_NAME));
+ }
+
+ public void testMorphToOneToManyMapping() throws Exception {
+ createTestEntityWithTransientMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IPersistentAttribute persistentAttribute = javaPersistentType().attributes().next();
+ ITransientMapping transientMapping = (ITransientMapping) persistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ persistentAttribute.setSpecifiedMappingKey(IMappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof IOneToManyMapping);
+
+ JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME);
+ JavaPersistentAttributeResource attributeResource = typeResource.attributes().next();
+ assertNull(attributeResource.mappingAnnotation(Transient.ANNOTATION_NAME));
+ assertNotNull(attributeResource.mappingAnnotation(OneToMany.ANNOTATION_NAME));
+ }
+
+ public void testMorphToManyToOneMapping() throws Exception {
+ createTestEntityWithTransientMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IPersistentAttribute persistentAttribute = javaPersistentType().attributes().next();
+ ITransientMapping transientMapping = (ITransientMapping) persistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ persistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof IManyToOneMapping);
+
+ JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME);
+ JavaPersistentAttributeResource attributeResource = typeResource.attributes().next();
+ assertNull(attributeResource.mappingAnnotation(Transient.ANNOTATION_NAME));
+ assertNotNull(attributeResource.mappingAnnotation(ManyToOne.ANNOTATION_NAME));
+ }
+
+ public void testMorphToManyToManyMapping() throws Exception {
+ createTestEntityWithTransientMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IPersistentAttribute persistentAttribute = javaPersistentType().attributes().next();
+ ITransientMapping transientMapping = (ITransientMapping) persistentAttribute.getMapping();
+ assertFalse(transientMapping.isDefault());
+
+ persistentAttribute.setSpecifiedMappingKey(IMappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ assertTrue(persistentAttribute.getMapping() instanceof IManyToManyMapping);
+
+ JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME);
+ JavaPersistentAttributeResource attributeResource = typeResource.attributes().next();
+ assertNull(attributeResource.mappingAnnotation(Transient.ANNOTATION_NAME));
+ assertNotNull(attributeResource.mappingAnnotation(ManyToMany.ANNOTATION_NAME));
+ }
+
+ public void testTransientMapping() throws Exception {
+ createTestEntityWithTransientMapping();
+ addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);
+
+ IPersistentAttribute persistentAttribute = javaPersistentType().attributes().next();
+ ITransientMapping transientMapping = (ITransientMapping) persistentAttribute.getSpecifiedMapping();
+
+ assertNotNull(transientMapping);
+ }
+
+}

Back to the top