diff options
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java')
32 files changed, 0 insertions, 21332 deletions
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java deleted file mode 100644 index a729eebd40..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java +++ /dev/null @@ -1,236 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class GenericJavaPersistentAttributeTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEntityAnnotatedField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - - public GenericJavaPersistentAttributeTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - - assertEquals("id", persistentAttribute.getName()); - } - - public void testGetMapping() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertTrue(persistentAttribute.getMapping() instanceof JavaIdMapping); - - persistentAttribute.setSpecifiedMappingKey(null); - assertTrue(persistentAttribute.getMapping() instanceof JavaBasicMapping); - } - - public void testGetSpecifiedMapping() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertTrue(persistentAttribute.getSpecifiedMapping() instanceof JavaIdMapping); - - persistentAttribute.setSpecifiedMappingKey(null); - assertNull(persistentAttribute.getSpecifiedMapping()); - } - - public void testGetSpecifiedMappingNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - - assertNull(persistentAttribute.getSpecifiedMapping()); - assertNotNull(persistentAttribute.getMapping()); - } - - public void testMappingKey() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - persistentAttribute.setSpecifiedMappingKey(null); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - } - - public void testDefaultMappingKey() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - } - - public void testSetSpecifiedMappingKey() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertNull(persistentAttribute.getSpecifiedMapping()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - assertTrue(persistentAttribute.getSpecifiedMapping() instanceof JavaEmbeddedMapping); - } - - public void testSetSpecifiedMappingKey2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - assertTrue(persistentAttribute.getSpecifiedMapping() instanceof JavaEmbeddedMapping); - } - - public void testSetSpecifiedMappingKeyNull() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - - assertNull(persistentAttribute.getSpecifiedMapping()); - } - - public void testGetMappingKeyMappingChangeInResourceModel() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.setPrimaryAnnotation(EmbeddedAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance()); - - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel2() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertNull(persistentAttribute.getSpecifiedMapping()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.setPrimaryAnnotation(BasicAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance()); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getSpecifiedMapping().getKey()); - } - - public void testGetAccessField() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(AccessType.FIELD, persistentAttribute.getAccess()); - assertEquals(AccessType.FIELD, persistentAttribute.getDefaultAccess()); - assertEquals(null, persistentAttribute.getSpecifiedAccess()); - } - - public void testGetAccessProperty() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(AccessType.PROPERTY, persistentAttribute.getAccess()); - assertEquals(AccessType.PROPERTY, persistentAttribute.getDefaultAccess()); - assertEquals(null, persistentAttribute.getSpecifiedAccess()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java deleted file mode 100644 index 92a467dc25..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java +++ /dev/null @@ -1,757 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IField; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - - -@SuppressWarnings("nls") -public class GenericJavaPersistentTypeTests extends ContextModelTestCase -{ - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - private ICompilationUnit createTestEntityAnnotatedFieldAndMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestSubType() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - }); - } - - private ICompilationUnit createTestSubTypeWithFieldAnnotation() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestSubTypeWithMethodAnnotation() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestSubTypeNonPersistent() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - }); - } - - private ICompilationUnit createTestSubTypePersistentExtendsNonPersistent() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild2.java", "AnnotationTestTypeChild2", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends AnnotationTestTypeChild "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - public GenericJavaPersistentTypeTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, getJavaPersistentType().getName()); - } - - public void testGetAccessNothingAnnotated() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessField() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessProperty() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - } - - public void testAccessFieldAndMethodAnnotated() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessInheritance() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessInheritance2() throws Exception { - createTestEntityAnnotatedField(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessInheritance3() throws Exception { - createTestEntityAnnotatedField(); - createTestSubTypeWithMethodAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessInheritance4() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - //inherited class having annotations set wins over the default access set on persistence-unit-defaults - public void testAccessInheritancePersistenceUnitDefaultAccess() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlNoAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityPersistentType.setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - entityPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlPersistenceUnitDefaultsAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityPropertyAccessAndFieldAnnotations() throws Exception { - //xml access set to property, field annotations, JavaPersistentType access is field - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityFieldAccessAndPropertyAnnotations() throws Exception { - //xml access set to field, property annotations, JavaPersistentType access is property - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedMethod(); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - ormPersistentType.setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlPersistenceUnitDefaultsAccessFieldAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - //inheritance wins over entity-mappings specified access - public void testAccessXmlEntityMappingsAccessWithInheritance() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childEntityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - - createTestEntityAnnotatedMethod(); - createTestSubType(); - JavaPersistentType childJavaPersistentType = childEntityPersistentType.getJavaPersistentType(); - - getEntityMappings().setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.PROPERTY, entityPersistentType.getJavaPersistentType().getAccess()); - assertEquals(AccessType.PROPERTY, childJavaPersistentType.getAccess()); - } - - public void testAccessXmlMetadataCompleteFieldAnnotations() throws Exception { - //xml access set to property, java has field annotations so the access should be field - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - } - - public void testAccessNoXmlAccessXmlMetdataCompletePropertyAnnotations() throws Exception { - //xml access not set, metadata complete set. JavaPersistentType access is property because properties are annotated - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedMethod(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testSuperPersistentType() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - ClassRef classRef = classRefs.next(); - JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType(); - - classRef = classRefs.next(); - JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(rootJavaPersistentType, childJavaPersistentType.getSuperPersistentType()); - assertNull(rootJavaPersistentType.getSuperPersistentType()); - } - - public void testSuperPersistentType2() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - //super is not added to the persistenceUnit, but it should still be found - //as the superPersistentType because of impliedClassRefs and changes for bug 190317 - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType javaPersistentType = classRefs.next().getJavaPersistentType(); - - assertNotNull(javaPersistentType.getSuperPersistentType()); - } - - //Entity extends Non-Entity extends Entity - public void testSuperPersistentType3() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - ClassRef classRef = classRefs.next(); - JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType(); - - classRef = classRefs.next(); - JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(rootJavaPersistentType, childJavaPersistentType.getSuperPersistentType()); - assertNull(rootJavaPersistentType.getSuperPersistentType()); - } - - public void testInheritanceHierarchy() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType rootJavaPersistentType = classRefs.next().getJavaPersistentType(); - JavaPersistentType childJavaPersistentType = classRefs.next().getJavaPersistentType(); - - Iterator<PersistentType> inheritanceHierarchy = childJavaPersistentType.inheritanceHierarchy(); - - assertEquals(childJavaPersistentType, inheritanceHierarchy.next()); - assertEquals(rootJavaPersistentType, inheritanceHierarchy.next()); - } - - public void testInheritanceHierarchy2() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType childJavaPersistentType = classRefs.next().getJavaPersistentType(); - JavaPersistentType rootJavaPersistentType = classRefs.next().getJavaPersistentType(); - - Iterator<PersistentType> inheritanceHierarchy = childJavaPersistentType.inheritanceHierarchy(); - - assertEquals(childJavaPersistentType, inheritanceHierarchy.next()); - assertEquals(rootJavaPersistentType, inheritanceHierarchy.next()); - } - - public void testGetMapping() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMapping().getKey()); - } - - public void testGetMappingNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMapping().getKey()); - } - - public void testMappingKey() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testMappingKeyNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKey() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNotNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKey2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNotNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKeyNull() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.setPrimaryAnnotation(EmbeddableAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance()); - - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel2() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.setPrimaryAnnotation(EntityAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance()); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testIsMapped() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertTrue(getJavaPersistentType().isMapped()); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertFalse(getJavaPersistentType().isMapped()); - } - - public void testAttributes() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().attributes(); - - assertEquals("id", attributes.next().getName()); - assertFalse(attributes.hasNext()); - } - - public void testAttributes2() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().attributes(); - - assertEquals("id", attributes.next().getName()); - assertEquals("name", attributes.next().getName()); - assertFalse(attributes.hasNext()); - } - - public void testAttributesSize() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(1, getJavaPersistentType().attributesSize()); - } - - public void testAttributesSize2() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, getJavaPersistentType().attributesSize()); - } - - public void testAttributeNamed() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute attribute = getJavaPersistentType().getAttributeNamed("id"); - - assertEquals("id", attribute.getName()); - assertNull(getJavaPersistentType().getAttributeNamed("name")); - assertNull(getJavaPersistentType().getAttributeNamed("foo")); - } - - public void testAttributeNamed2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute attribute = getJavaPersistentType().getAttributeNamed("name"); - - assertEquals("name", attribute.getName()); - - assertNull(getJavaPersistentType().getAttributeNamed("foo")); - } - - public void testRenameAttribute() throws Exception { - ICompilationUnit testType = createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute idAttribute = attributes.next(); - JavaPersistentAttribute nameAttribute = attributes.next(); - - - assertEquals("id", idAttribute.getName()); - assertEquals("name", nameAttribute.getName()); - - IField idField = testType.findPrimaryType().getField("id"); - idField.rename("id2", false, null); - - attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute nameAttribute2 = attributes.next(); - JavaPersistentAttribute id2Attribute = attributes.next(); - - assertNotSame(idAttribute, id2Attribute); - assertEquals("id2", id2Attribute.getName()); - assertEquals(nameAttribute, nameAttribute2); - assertEquals("name", nameAttribute2.getName()); - assertFalse(attributes.hasNext()); - } - - public void testSuperPersistentTypeGeneric() throws Exception { - createTestGenericEntity(); - createTestGenericMappedSuperclass(); - - addXmlClassRef(PACKAGE_NAME + ".Entity1"); - addXmlClassRef(PACKAGE_NAME + ".Entity2"); - - JavaPersistentType javaPersistentType = getJavaPersistentType(); - assertEquals("test.Entity1", javaPersistentType.getName()); - assertNotNull(javaPersistentType.getSuperPersistentType()); - - assertEquals("test.Entity2", javaPersistentType.getSuperPersistentType().getName()); - } - - private void createTestGenericEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Entity1 "); - sb.append("extends Entity2<Integer> {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity1.java", sourceWriter); - } - - private void createTestGenericMappedSuperclass() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class Entity2<K> {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity2.java", sourceWriter); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAssociationOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAssociationOverrideTests.java deleted file mode 100644 index fa217070aa..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAssociationOverrideTests.java +++ /dev/null @@ -1,442 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaAssociationOverrideTests extends ContextModelTestCase -{ - private static final String ASSOCIATION_OVERRIDE_NAME = "MY_ASSOCIATION_OVERRIDE_NAME"; - - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - sb.append(CR); - sb.append(" private AnnotationTestTypeChild address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithAssociationOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ASSOCIATION_OVERRIDE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\")"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - - - public JavaAssociationOverrideTests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - AssociationOverride javaAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("address", javaAssociationOverride.getName()); - assertEquals("address", associationOverrideResource.getName()); - assertTrue(overrideContainer.associationOverrides().hasNext()); - - //set name in the resource model, verify context model updated - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", javaAssociationOverride.getName()); - assertEquals("FOO", associationOverrideResource.getName()); - - //set name to null in the resource model - associationOverrideResource.setName(null); - getJpaProject().synchronizeContextModel(); - assertEquals(0, overrideContainer.specifiedAssociationOverridesSize()); - assertNull(associationOverrideResource.getName()); - - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, overrideContainer.specifiedAssociationOverridesSize()); - javaAssociationOverride = overrideContainer.specifiedAssociationOverrides().next(); - assertEquals("FOO", javaAssociationOverride.getName()); - assertEquals("FOO", associationOverrideResource.getName()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - assertFalse(overrideContainer.specifiedAssociationOverrides().hasNext()); - assertFalse(typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).hasNext()); - } - - public void testModifyName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - AssociationOverride javaAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("address", javaAssociationOverride.getName()); - assertEquals("address", associationOverrideResource.getName()); - assertTrue(overrideContainer.associationOverrides().hasNext()); - - //set name in the context model, verify resource model modified - javaAssociationOverride.setName("foo"); - assertEquals("foo", javaAssociationOverride.getName()); - assertEquals("foo", associationOverrideResource.getName()); - - //set name to null in the context model - javaAssociationOverride.setName(null); - assertNull(javaAssociationOverride.getName()); - associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - assertNull(associationOverrideResource.getName()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - JavaAssociationOverride javaAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - JavaJoinColumnJoiningStrategy joiningStrategy = javaAssociationOverride.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - - JavaJoinColumn joinColumn = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", associationOverrideResource.joinColumnAt(0).getName()); - - JavaJoinColumn joinColumn2 = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(1).getName()); - - JavaJoinColumn joinColumn3 = joiningStrategy.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - - ListIterator<JavaJoinColumn> joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - AssociationOverride javaAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - JoinColumnJoiningStrategy joiningStrategy = javaAssociationOverride.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(1, associationOverrideResource.joinColumnsSize()); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, associationOverrideResource.joinColumnsSize()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(3, associationOverrideResource.joinColumnsSize()); - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(2, associationOverrideResource.joinColumnsSize()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(0).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(1, associationOverrideResource.joinColumnsSize()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(0, associationOverrideResource.joinColumnsSize()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - JavaAssociationOverride javaAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - JavaJoinColumnJoiningStrategy joiningStrategy = javaAssociationOverride.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, associationOverrideResource.joinColumnsSize()); - - - joiningStrategy.moveSpecifiedJoinColumn(2, 0); - ListIterator<JavaJoinColumn> joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - - - joiningStrategy.moveSpecifiedJoinColumn(0, 1); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAR", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - JavaAssociationOverride javaAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - JavaJoinColumnJoiningStrategy joiningStrategy = javaAssociationOverride.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - ListIterator<JavaJoinColumn> joinColumns = joiningStrategy.specifiedJoinColumns(); - JoinColumn joinColumn = joinColumns.next(); - assertEquals("address_id", joinColumn.getSpecifiedName()); - assertEquals("id", joinColumn.getSpecifiedReferencedColumnName()); - - - associationOverrideResource.addJoinColumn(0); - associationOverrideResource.addJoinColumn(1); - associationOverrideResource.addJoinColumn(2); - - associationOverrideResource.joinColumnAt(0).setName("FOO"); - associationOverrideResource.joinColumnAt(1).setName("BAR"); - associationOverrideResource.joinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.moveJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.moveJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("address_id", joinColumns.next().getName()); - - associationOverrideResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(joiningStrategy.specifiedJoinColumns().hasNext()); - } - - public void testGetName() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedAssociationOverrides().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverride = overrideContainer.specifiedAssociationOverrides().next(); - assertEquals("FOO", specifiedAssociationOverride.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedAssociationOverrides().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName()); - - specifiedAssociationOverride.setName("FOO"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("FOO", associationOverrideResource.getName()); - } - - public void testDefaultName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(1, overrideContainer.virtualAssociationOverridesSize()); - - AssociationOverride associationOverride = overrideContainer.virtualAssociationOverrides().next(); - assertEquals("address", associationOverride.getName()); - } - - public void testIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(1, overrideContainer.virtualAssociationOverridesSize()); - - AssociationOverride associationOverride = overrideContainer.virtualAssociationOverrides().next(); - assertTrue(associationOverride.isVirtual()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAttributeOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAttributeOverrideTests.java deleted file mode 100644 index 33922cda5c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAttributeOverrideTests.java +++ /dev/null @@ -1,258 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaAttributeOverrideTests extends ContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "MY_ATTRIBUTE_OVERRIDE_NAME"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "MY_ATTRIBUTE_OVERRIDE_COLUMN_NAME"; - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - }); - } - - private ICompilationUnit createTestEntityWithAttributeOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - - - public JavaAttributeOverrideTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedAttributeOverrides().next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, specifiedAttributeOverride.getName()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - attributeOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverride = overrideContainer.specifiedAttributeOverrides().next(); - assertEquals("FOO", specifiedAttributeOverride.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedAttributeOverrides().next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, specifiedAttributeOverride.getName()); - - specifiedAttributeOverride.setName("FOO"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - assertEquals("FOO", attributeOverrideResource.getName()); - } - - public void testColumnGetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedAttributeOverrides().next(); - Column column = specifiedAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getName()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation columnResource = attributeOverrideResource.getColumn(); - columnResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - - column = overrideContainer.specifiedAttributeOverrides().next().getColumn(); - assertEquals("FOO", column.getName()); - } - - public void testColumnSetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedAttributeOverrides().next(); - Column column = specifiedAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getName()); - - column.setSpecifiedName("FOO"); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation columnResource = attributeOverrideResource.getColumn(); - - assertEquals("FOO", columnResource.getName()); - - column.setSpecifiedName(null); - - attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - assertNull(attributeOverrideResource.getColumn()); - assertNotNull(specifiedAttributeOverride.getColumn()); - } - - public void testColumnDefaultName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, overrideContainer.virtualAttributeOverridesSize()); - - AttributeOverride attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("id", attributeOverride.getColumn().getDefaultName()); - - - JavaPersistentType mappedSuperclass = CollectionTools.list(getPersistenceUnit().specifiedClassRefs()).get(1).getJavaPersistentType(); - BasicMapping basicMapping = (BasicMapping) mappedSuperclass.getAttributeNamed("id").getMapping(); - basicMapping.getColumn().setSpecifiedName("FOO"); - - attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("FOO", attributeOverride.getColumn().getDefaultName()); - } - - public void testColumnDefaultTableName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, overrideContainer.virtualAttributeOverridesSize()); - - AttributeOverride attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("AnnotationTestTypeChild", attributeOverride.getColumn().getDefaultTable()); - - - JavaPersistentType mappedSuperclass = CollectionTools.list(getPersistenceUnit().specifiedClassRefs()).get(1).getJavaPersistentType(); - BasicMapping basicMapping = (BasicMapping) mappedSuperclass.getAttributeNamed("id").getMapping(); - basicMapping.getColumn().setSpecifiedTable("BAR"); - - attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("BAR", attributeOverride.getColumn().getDefaultTable()); - } - - public void testDefaultName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, overrideContainer.virtualAttributeOverridesSize()); - - AttributeOverride attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("id", attributeOverride.getName()); - } - - public void testIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, overrideContainer.virtualAttributeOverridesSize()); - - AttributeOverride attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertTrue(attributeOverride.isVirtual()); - } - - public void testSetColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - attributeOverride = attributeOverride.setVirtual(false); - attributeOverride.getColumn().setSpecifiedName("FOO"); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - assertEquals("FOO", attributeOverrideResource.getColumn().getName()); - assertEquals("FOO", overrideContainer.specifiedAttributeOverrides().next().getColumn().getSpecifiedName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaBasicMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaBasicMappingTests.java deleted file mode 100644 index 57117e30e6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaBasicMappingTests.java +++ /dev/null @@ -1,995 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.EnumType; -import org.eclipse.jpt.core.context.EnumeratedConverter; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.EnumeratedAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.LobAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaBasicMappingTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithBasicMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithBasicMappingFetchOptionalSpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.FETCH_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic(fetch=FetchType.EAGER, optional=false)").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithLob() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.LOB); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Lob").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithEnumerated() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ENUMERATED, JPA.ENUM_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Enumerated(EnumType.STRING)").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithTemporal() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Temporal(TemporalType.TIMESTAMP)").append(CR); - } - }); - } - - public JavaBasicMappingTests(String name) { - super(name); - } - - public void testDefaultBasicGetDefaultFetch() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(FetchType.EAGER, basicMapping.getDefaultFetch()); - } - - public void testSpecifiedBasicGetDefaultFetch() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertEquals(FetchType.EAGER, basicMapping.getDefaultFetch()); - } - - public void testGetFetch() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(FetchType.EAGER, basicMapping.getFetch()); - - basicMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, basicMapping.getFetch()); - } - - public void testGetSpecifiedFetch() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getSpecifiedFetch()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - basic.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - getJpaProject().synchronizeContextModel(); - - assertEquals(FetchType.LAZY, basicMapping.getSpecifiedFetch()); - } - - public void testGetSpecifiedFetch2() throws Exception { - createTestEntityWithBasicMappingFetchOptionalSpecified(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(FetchType.EAGER, basicMapping.getSpecifiedFetch()); - } - - public void testSetSpecifiedFetch() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(basicMapping.getSpecifiedFetch()); - - basicMapping.setSpecifiedFetch(FetchType.LAZY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, basic.getFetch()); - - basicMapping.setSpecifiedFetch(null); - assertNotNull(attributeResource.getAnnotation(JPA.BASIC)); - } - - public void testSetSpecifiedFetch2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - createOrmXmlFile(); - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getSpecifiedFetch()); - assertTrue(basicMapping.isDefault()); - - basicMapping.setSpecifiedFetch(FetchType.LAZY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableProperties().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, basic.getFetch()); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(FetchType.LAZY, basicMapping.getSpecifiedFetch()); - assertFalse(basicMapping.isDefault()); - - basicMapping.setSpecifiedFetch(null); - assertNotNull(attributeResource.getAnnotation(JPA.BASIC)); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - } - - protected void createOrmXmlFile() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testSetBasicToDefault() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertFalse(basicMapping.isDefault()); - - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNotSame(basicMapping, persistentAttribute.getMapping()); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertTrue(basicMapping.isDefault()); - assertEquals("FOO", basicMapping.getColumn().getSpecifiedName()); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToDefaultBasic() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(Converter.ENUMERATED_CONVERTER); - ((EnumeratedConverter) basicMapping.getConverter()).setSpecifiedEnumType(EnumType.STRING); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getEnumType()); - - assertNull(((BasicMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); - assertNull(((BasicMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToId() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((IdMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((IdMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToVersion() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((VersionMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((VersionMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToEmbedded() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToEmbeddedId() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToTransient() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToOneToOne() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - -//TODO assertEquals(FetchType.EAGER, ((IOneToOneMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertEquals(Boolean.FALSE, ((IOneToOneMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToOneToMany() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - -//TODO assertEquals(FetchType.EAGER, ((IOneToManyMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertNotNull(attributeResource.mappingAnnotation(OneToMany.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - public void testBasicMorphToManyToOne() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - -//TODO assertEquals(FetchType.EAGER, ((IManyToOneMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertEquals(Boolean.FALSE, ((IManyToOneMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToManyToMany() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - -//TODO assertEquals(FetchType.EAGER, ((IManyToManyMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertNotNull(attributeResource.mappingAnnotation(ManyToMany.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultBasicGetDefaultOptional() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(true, basicMapping.isDefaultOptional()); - } - - public void testSpecifiedBasicGetDefaultOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertEquals(true, basicMapping.isDefaultOptional()); - } - - public void testGetOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(true, basicMapping.isOptional()); - - basicMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(true, basicMapping.isOptional()); - } - - public void testGetSpecifiedOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getSpecifiedOptional()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - basic.setOptional(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional()); - } - - public void testGetSpecifiedOptional2() throws Exception { - createTestEntityWithBasicMappingFetchOptionalSpecified(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional()); - } - - public void testSetSpecifiedOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(basicMapping.getSpecifiedOptional()); - - basicMapping.setSpecifiedOptional(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - - assertEquals(Boolean.FALSE, basic.getOptional()); - - basicMapping.setSpecifiedOptional(null); - assertNotNull(attributeResource.getAnnotation(JPA.BASIC)); - } - - public void testSetSpecifiedOptional2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getSpecifiedOptional()); - assertTrue(basicMapping.isDefault()); - - basicMapping.setSpecifiedOptional(Boolean.TRUE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - - assertEquals(Boolean.TRUE, basic.getOptional()); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(Boolean.TRUE, basicMapping.getSpecifiedOptional()); - assertFalse(basicMapping.isDefault()); - - basicMapping.setSpecifiedOptional(null); - assertNotNull(attributeResource.getAnnotation(JPA.BASIC)); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - } - - - public void testGetSpecifiedOptionalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getSpecifiedOptional()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - basic.setOptional(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional()); - - basic.setOptional(null); - getJpaProject().synchronizeContextModel(); - assertNull(basicMapping.getSpecifiedOptional()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getSpecifiedMapping()); - - basic.setOptional(Boolean.FALSE); - attributeResource.setPrimaryAnnotation(null, EmptyIterable.<String>instance()); - getJpaProject().synchronizeContextModel(); - - assertNull(persistentAttribute.getSpecifiedMapping()); - assertEquals(true, ((BasicMapping) persistentAttribute.getMapping()).isOptional()); - } - - - public void testIsLob() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertFalse(basicMapping.getConverter().getType() == Converter.LOB_CONVERTER); - } - - public void testIsLob2() throws Exception { - createTestEntityWithLob(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertTrue(basicMapping.getConverter().getType() == Converter.LOB_CONVERTER); - } - - public void testSetLob() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - basicMapping.setConverter(Converter.LOB_CONVERTER); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNotNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - - basicMapping.setConverter(Converter.NO_CONVERTER); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - } - - public void testIsLobUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertFalse(basicMapping.getConverter().getType() == Converter.LOB_CONVERTER); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertTrue(basicMapping.getConverter().getType() == Converter.LOB_CONVERTER); - - attributeResource.removeAnnotation(LobAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertFalse(basicMapping.getConverter().getType() == Converter.LOB_CONVERTER); - } - - public void testDefaultBasicGetDefaultConverter() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertTrue(basicMapping.getConverter().getType() == Converter.NO_CONVERTER); - } - - public void testSpecifiedBasicGetDefaultConverter() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertTrue(basicMapping.getConverter().getType() == Converter.NO_CONVERTER); - } - - public void testGetEnumerated() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertTrue(basicMapping.getConverter().getType() == Converter.NO_CONVERTER); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EnumeratedAnnotation enumeratedAnnotation = (EnumeratedAnnotation) attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) basicMapping.getConverter()).getDefaultEnumType()); - - enumeratedAnnotation.setValue(org.eclipse.jpt.core.resource.java.EnumType.STRING); - getJpaProject().synchronizeContextModel(); - assertEquals(EnumType.STRING, ((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType()); - } - - public void testGetSpecifiedEnumerated() throws Exception { - createTestEntityWithEnumerated(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(EnumType.STRING, ((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType()); - } - - public void testSetSpecifiedEnumerated() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertTrue(basicMapping.getConverter().getType() == Converter.NO_CONVERTER); - - basicMapping.setConverter(Converter.ENUMERATED_CONVERTER); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - - assertNotNull(enumerated); - assertEquals(null, enumerated.getValue()); - - ((EnumeratedConverter) basicMapping.getConverter()).setSpecifiedEnumType(EnumType.STRING); - assertEquals(org.eclipse.jpt.core.resource.java.EnumType.STRING, enumerated.getValue()); - - ((EnumeratedConverter) basicMapping.getConverter()).setSpecifiedEnumType(null); - assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - assertNull(enumerated.getValue()); - - basicMapping.setConverter(Converter.NO_CONVERTER); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testGetSpecifiedEnumeratedUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertTrue(basicMapping.getConverter().getType() == Converter.NO_CONVERTER); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - enumerated.setValue(org.eclipse.jpt.core.resource.java.EnumType.STRING); - getJpaProject().synchronizeContextModel(); - - assertEquals(EnumType.STRING, ((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType()); - - enumerated.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - assertNull(((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getSpecifiedMapping()); - } - - public void testGetTemporal() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(Converter.TEMPORAL_CONVERTER, basicMapping.getConverter().getType()); - } - - public void testGetTemporal2() throws Exception { - createTestEntityWithTemporal(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(Converter.TEMPORAL_CONVERTER, basicMapping.getConverter().getType()); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) basicMapping.getConverter()).getTemporalType()); - } - - public void testSetTemporal() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertEquals(Converter.NO_CONVERTER, basicMapping.getConverter().getType()); - - basicMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - basicMapping.setConverter(Converter.NO_CONVERTER); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(Converter.NO_CONVERTER, basicMapping.getConverter().getType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.core.resource.java.TemporalType.DATE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Converter.TEMPORAL_CONVERTER, basicMapping.getConverter().getType()); - assertEquals(TemporalType.DATE, ((TemporalConverter) basicMapping.getConverter()).getTemporalType()); - - attributeResource.removeAnnotation(TemporalAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertEquals(Converter.NO_CONVERTER, basicMapping.getConverter().getType()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getSpecifiedMapping()); - } - - public void testGetColumn() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - assertEquals("id", basicMapping.getColumn().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", basicMapping.getColumn().getSpecifiedName()); - assertEquals("foo", basicMapping.getColumn().getName()); - assertEquals("id", basicMapping.getColumn().getDefaultName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaCascadeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaCascadeTests.java deleted file mode 100644 index 97f3d018cb..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaCascadeTests.java +++ /dev/null @@ -1,321 +0,0 @@ -/******************************************************************************* - * 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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaCascade; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaCascadeTests - extends ContextModelTestCase -{ - private ICompilationUnit createTestEntityWithOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - } - - - public JavaCascadeTests(String name) { - super(name); - } - - - public void testUpdateCascadeAll() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isAll()); - assertFalse(annotation.isCascadeAll()); - - //set all in the resource model, verify context model updated - annotation.setCascadeAll(true); - getJpaProject().update(); - assertTrue(annotation.isCascadeAll()); - assertTrue(cascade.isAll()); - - //set all to false in the resource model - annotation.setCascadeAll(false); - getJpaProject().update(); - assertFalse(annotation.isCascadeAll()); - assertFalse(cascade.isAll()); - } - - public void testModifyCascadeAll() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isAll()); - assertFalse(annotation.isCascadeAll()); - - //set all in the context model, verify resource model updated - cascade.setAll(true); - assertTrue(annotation.isCascadeAll()); - assertTrue(cascade.isAll()); - - //set all to false in the context model - cascade.setAll(false); - assertFalse(annotation.isCascadeAll()); - assertFalse(cascade.isAll()); - } - - public void testUpdateCascadePersist() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isPersist()); - assertFalse(annotation.isCascadePersist()); - - //set persist in the resource model, verify context model updated - annotation.setCascadePersist(true); - getJpaProject().update(); - assertTrue(annotation.isCascadePersist()); - assertTrue(cascade.isPersist()); - - //set persist to false in the resource model - annotation.setCascadePersist(false); - getJpaProject().update(); - assertFalse(annotation.isCascadePersist()); - assertFalse(cascade.isPersist()); - } - - public void testModifyCascadePersist() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isPersist()); - assertFalse(annotation.isCascadePersist()); - - //set persist in the context model, verify resource model updated - cascade.setPersist(true); - assertTrue(annotation.isCascadePersist()); - assertTrue(cascade.isPersist()); - - //set persist to false in the context model - cascade.setPersist(false); - assertFalse(annotation.isCascadePersist()); - assertFalse(cascade.isPersist()); - } - - public void testUpdateCascadeMerge() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isMerge()); - assertFalse(annotation.isCascadeMerge()); - - //set merge in the resource model, verify context model updated - annotation.setCascadeMerge(true); - getJpaProject().update(); - assertTrue(annotation.isCascadeMerge()); - assertTrue(cascade.isMerge()); - - //set merge to false in the resource model - annotation.setCascadeMerge(false); - getJpaProject().update(); - assertFalse(annotation.isCascadeMerge()); - assertFalse(cascade.isMerge()); - } - - public void testModifyCascadeMerge() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isMerge()); - assertFalse(annotation.isCascadeMerge()); - - //set merge in the context model, verify resource model updated - cascade.setMerge(true); - assertTrue(annotation.isCascadeMerge()); - assertTrue(cascade.isMerge()); - - //set merge to false in the context model - cascade.setMerge(false); - assertFalse(annotation.isCascadeMerge()); - assertFalse(cascade.isMerge()); - } - - public void testUpdateCascadeRemove() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isRemove()); - assertFalse(annotation.isCascadeRemove()); - - //set remove in the resource model, verify context model updated - annotation.setCascadeRemove(true); - getJpaProject().update(); - assertTrue(annotation.isCascadeRemove()); - assertTrue(cascade.isRemove()); - - //set remove to false in the resource model - annotation.setCascadeRemove(false); - getJpaProject().update(); - assertFalse(annotation.isCascadeRemove()); - assertFalse(cascade.isRemove()); - } - - public void testModifyCascadeRemove() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isRemove()); - assertFalse(annotation.isCascadeRemove()); - - //set remove in the context model, verify resource model updated - cascade.setRemove(true); - assertTrue(annotation.isCascadeRemove()); - assertTrue(cascade.isRemove()); - - //set remove to false in the context model - cascade.setRemove(false); - assertFalse(annotation.isCascadeRemove()); - assertFalse(cascade.isRemove()); - } - - public void testUpdateCascadeRefresh() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isRefresh()); - assertFalse(annotation.isCascadeRefresh()); - - //set refresh in the resource model, verify context model updated - annotation.setCascadeRefresh(true); - getJpaProject().update(); - assertTrue(annotation.isCascadeRefresh()); - assertTrue(cascade.isRefresh()); - - //set refresh to false in the resource model - annotation.setCascadeRefresh(false); - getJpaProject().update(); - assertFalse(annotation.isCascadeRefresh()); - assertFalse(cascade.isRefresh()); - } - - public void testModifyCascadeRefresh() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isRefresh()); - assertFalse(annotation.isCascadeRefresh()); - - //set refresh in the context model, verify resource model updated - cascade.setRefresh(true); - assertTrue(annotation.isCascadeRefresh()); - assertTrue(cascade.isRefresh()); - - //set refresh to false in the context model - cascade.setRefresh(false); - assertFalse(annotation.isCascadeRefresh()); - assertFalse(cascade.isRefresh()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaColumnTests.java deleted file mode 100644 index 78d419cdd1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaColumnTests.java +++ /dev/null @@ -1,836 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaColumnTests extends ContextModelTestCase -{ - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String TABLE_NAME = "MY_TABLE"; - private static final String COLUMN_DEFINITION = "MY_COLUMN_DEFINITION"; - - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithDefaultBasicColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(name=\"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithBasicColumnTableSet() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - sb.append("@Column(table=\"" + TABLE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithBasicColumnColumnDefinitionSet() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - sb.append("@Column(columnDefinition=\"" + COLUMN_DEFINITION + "\")"); - } - }); - } - - public JavaColumnTests(String name) { - super(name); - } - - public void testGetSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(COLUMN_NAME, basicMapping.getColumn().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(basicMapping.getPersistentAttribute().getName(), basicMapping.getColumn().getDefaultName()); - assertEquals("id", basicMapping.getColumn().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals("id", basicMapping.getColumn().getDefaultName()); - - basicMapping.getColumn().setSpecifiedName("foo"); - assertEquals("id", basicMapping.getColumn().getDefaultName()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals("id", basicMapping.getColumn().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(COLUMN_NAME, basicMapping.getColumn().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedName("foo"); - - assertEquals("foo", basicMapping.getColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals("foo", column.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedName(null); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetNameUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", basicMapping.getColumn().getSpecifiedName()); - assertEquals("foo", basicMapping.getColumn().getName()); - - column.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(basicMapping.getColumn().getSpecifiedName()); - } - - - - - - - - - - - - - - public void testGetSpecifiedTableNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedTable()); - } - - public void testGetSpecifiedTable() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(TABLE_NAME, basicMapping.getColumn().getSpecifiedTable()); - } - - public void testGetDefaultTableSpecifiedTableNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(((Entity) basicMapping.getTypeMapping()).getName(), basicMapping.getColumn().getDefaultTable()); - assertEquals(TYPE_NAME, basicMapping.getColumn().getDefaultTable()); - } - - public void testGetDefaultTable() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(TYPE_NAME, basicMapping.getColumn().getDefaultTable()); - - basicMapping.getColumn().setSpecifiedTable("foo"); - assertEquals(TYPE_NAME, basicMapping.getColumn().getDefaultTable()); - } - - public void testGetTable() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(TABLE_NAME, basicMapping.getColumn().getTable()); - } - - public void testSetSpecifiedTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedTable("foo"); - - assertEquals("foo", basicMapping.getColumn().getSpecifiedTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals("foo", column.getTable()); - } - - public void testSetSpecifiedTableNull() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedTable(null); - - assertNull(basicMapping.getColumn().getSpecifiedTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetTableUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - - column.setTable("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", basicMapping.getColumn().getSpecifiedTable()); - assertEquals("foo", basicMapping.getColumn().getTable()); - - column.setTable(null); - getJpaProject().synchronizeContextModel(); - assertNull(basicMapping.getColumn().getSpecifiedTable()); - } - - public void testGetColumnDefinition() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(COLUMN_DEFINITION, basicMapping.getColumn().getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setColumnDefinition("foo"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals("foo", column.getColumnDefinition()); - - basicMapping.getColumn().setColumnDefinition(null); - assertNull(column.getColumnDefinition()); - } - - public void testGetColumnDefinitionUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getColumnDefinition()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - - column.setColumnDefinition("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", basicMapping.getColumn().getColumnDefinition()); - - column.setColumnDefinition(null); - getJpaProject().synchronizeContextModel(); - assertNull(basicMapping.getColumn().getColumnDefinition()); - - } - - public void testGetLength() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_LENGTH, basicMapping.getColumn().getLength()); - basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(55)); - assertEquals(55, basicMapping.getColumn().getLength()); - } - - public void testGetDefaultLength() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_LENGTH, basicMapping.getColumn().getDefaultLength()); - basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(55)); - - assertEquals(Column.DEFAULT_LENGTH, basicMapping.getColumn().getDefaultLength()); - } - - public void testGetSpecifiedLength() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedLength()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setLength(Integer.valueOf(66)); - getJpaProject().synchronizeContextModel(); - - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedLength()); - assertEquals(66, basicMapping.getColumn().getLength()); - - column.setLength(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedLength()); - } - - public void testSetSpecifiedLength() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedLength()); - - basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(100), column.getLength()); - - basicMapping.getColumn().setSpecifiedLength(null); - - assertNull(column.getLength()); - } - - public void testGetPrecision() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_PRECISION, basicMapping.getColumn().getPrecision()); - basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(55)); - assertEquals(55, basicMapping.getColumn().getPrecision()); - } - - public void testGetDefaultPrecision() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_PRECISION, basicMapping.getColumn().getDefaultPrecision()); - basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(55)); - - assertEquals(Column.DEFAULT_PRECISION, basicMapping.getColumn().getDefaultPrecision()); - } - - public void testGetSpecifiedPrecision() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedPrecision()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setPrecision(Integer.valueOf(66)); - getJpaProject().synchronizeContextModel(); - - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedPrecision()); - assertEquals(66, basicMapping.getColumn().getPrecision()); - - column.setPrecision(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedPrecision()); - } - - public void testSetSpecifiedPrecision() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedPrecision()); - - basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(100), column.getPrecision()); - - basicMapping.getColumn().setSpecifiedPrecision(null); - - assertNull(column.getPrecision()); - } - - public void testGetScale() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_SCALE, basicMapping.getColumn().getScale()); - basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(55)); - assertEquals(55, basicMapping.getColumn().getScale()); - } - - public void testGetDefaultScale() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_SCALE, basicMapping.getColumn().getDefaultScale()); - basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(55)); - - assertEquals(Column.DEFAULT_SCALE, basicMapping.getColumn().getDefaultScale()); - } - - public void testGetSpecifiedScale() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedScale()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setScale(Integer.valueOf(66)); - getJpaProject().synchronizeContextModel(); - - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedScale()); - assertEquals(66, basicMapping.getColumn().getScale()); - - column.setScale(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedScale()); - } - - public void testSetSpecifiedScale() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedScale()); - - basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(100), column.getScale()); - - basicMapping.getColumn().setSpecifiedScale(null); - - assertNull(column.getScale()); - } - - public void testGetUnique() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().isUnique()); - basicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - assertEquals(true, basicMapping.getColumn().isUnique()); - } - - public void testGetDefaultUnique() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().isDefaultUnique()); - basicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - - assertEquals(BaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().isDefaultUnique()); - } - - public void testGetSpecifiedUnique() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUnique()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setUnique(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedUnique()); - assertEquals(true, basicMapping.getColumn().isUnique()); - - column.setUnique(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedUnique()); - } - - public void testSetSpecifiedUnique() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUnique()); - - basicMapping.getColumn().setSpecifiedUnique(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.FALSE, column.getUnique()); - - basicMapping.getColumn().setSpecifiedUnique(null); - - assertNull(column.getUnique()); - } - - public void testGetInsertable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().isInsertable()); - basicMapping.getColumn().setSpecifiedInsertable(Boolean.TRUE); - assertEquals(true, basicMapping.getColumn().isInsertable()); - } - - public void testGetDefaultInsertable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().isDefaultInsertable()); - basicMapping.getColumn().setSpecifiedInsertable(Boolean.TRUE); - - assertEquals(BaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().isDefaultInsertable()); - } - - public void testGetSpecifiedInsertable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedInsertable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setInsertable(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedInsertable()); - assertEquals(true, basicMapping.getColumn().isInsertable()); - - column.setInsertable(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedInsertable()); - } - - public void testSetSpecifiedInsertable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedInsertable()); - - basicMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.FALSE, column.getInsertable()); - - basicMapping.getColumn().setSpecifiedInsertable(null); - - assertNull(column.getInsertable()); - } - - public void testGetNullable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().isNullable()); - basicMapping.getColumn().setSpecifiedNullable(Boolean.TRUE); - assertEquals(true, basicMapping.getColumn().isNullable()); - } - - public void testGetDefaultNullable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().isDefaultNullable()); - basicMapping.getColumn().setSpecifiedNullable(Boolean.TRUE); - - assertEquals(BaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().isDefaultNullable()); - } - - public void testGetSpecifiedNullable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedNullable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setNullable(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedNullable()); - assertEquals(true, basicMapping.getColumn().isNullable()); - - column.setNullable(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedNullable()); - } - - public void testSetSpecifiedNullable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedNullable()); - - basicMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.FALSE, column.getNullable()); - - basicMapping.getColumn().setSpecifiedNullable(null); - - assertNull(column.getNullable()); - } - - public void testGetUpdatable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().isUpdatable()); - basicMapping.getColumn().setSpecifiedUpdatable(Boolean.TRUE); - assertEquals(true, basicMapping.getColumn().isUpdatable()); - } - - public void testGetDefaultUpdatable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().isDefaultUpdatable()); - basicMapping.getColumn().setSpecifiedUpdatable(Boolean.TRUE); - - assertEquals(BaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().isDefaultUpdatable()); - } - - public void testGetSpecifiedUpdatable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUpdatable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setUpdatable(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedUpdatable()); - assertEquals(true, basicMapping.getColumn().isUpdatable()); - - column.setUpdatable(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedUpdatable()); - } - - public void testSetSpecifiedUpdatable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUpdatable()); - - basicMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.FALSE, column.getUpdatable()); - - basicMapping.getColumn().setSpecifiedUpdatable(null); - - assertNull(column.getUpdatable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java deleted file mode 100644 index 686a032f63..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java +++ /dev/null @@ -1,459 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.DiscriminatorColumn; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaDiscriminatorColumnTests extends ContextModelTestCase -{ - private static final String DISCRIMINATOR_COLUMN_NAME = "MY_DISCRIMINATOR_COLUMN"; - private static final String COLUMN_DEFINITION = "MY_COLUMN_DEFINITION"; - - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithDiscriminatorColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.DISCRIMINATOR_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@DiscriminatorColumn(name=\"" + DISCRIMINATOR_COLUMN_NAME + "\")"); - } - }); - } - - private void createTestAbstractEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public abstract class ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, sourceWriter); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - - public JavaDiscriminatorColumnTests(String name) { - super(name); - } - - public void testGetSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_COLUMN_NAME, getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDefaultName()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDefaultName()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getDefaultName()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName("foo"); - assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getDefaultName()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getName()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_COLUMN_NAME, getJavaEntity().getDiscriminatorColumn().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName("foo"); - - assertEquals("foo", getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals("foo", discriminatorColumn.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName(null); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertNull(discriminatorColumn); - } - - public void testGetDefaultDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDefaultDiscriminatorType()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DiscriminatorType.STRING, getJavaEntity().getDiscriminatorColumn().getDefaultDiscriminatorType()); - } - - public void testGetDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DiscriminatorType.STRING, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR); - assertEquals(DiscriminatorType.CHAR, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - } - - public void testGetSpecifiedDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - discriminatorColumn.setDiscriminatorType(org.eclipse.jpt.core.resource.java.DiscriminatorType.CHAR); - getJpaProject().synchronizeContextModel(); - - assertEquals(DiscriminatorType.CHAR, getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - } - - public void testSetSpecifiedDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals(org.eclipse.jpt.core.resource.java.DiscriminatorType.CHAR, discriminatorColumn.getDiscriminatorType()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName(null); - getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(null); - assertNull(typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN)); - } - - public void testGetDiscriminatorTypeUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN); - - column.setDiscriminatorType(org.eclipse.jpt.core.resource.java.DiscriminatorType.INTEGER); - getJpaProject().synchronizeContextModel(); - assertEquals(DiscriminatorType.INTEGER, getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - assertEquals(DiscriminatorType.INTEGER, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - column.setDiscriminatorType(null); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - } - - public void testGetLength() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, getJavaEntity().getDiscriminatorColumn().getLength()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getLength()); - getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(55)); - assertEquals(55, getJavaEntity().getDiscriminatorColumn().getLength()); - } - - public void testGetDefaultLength() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, getJavaEntity().getDiscriminatorColumn().getDefaultLength()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getDefaultLength()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(55)); - - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getDefaultLength()); - } - - public void testGetSpecifiedLength() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - discriminatorColumn.setLength(Integer.valueOf(66)); - getJpaProject().synchronizeContextModel(); - - assertEquals(Integer.valueOf(66), getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(66, getJavaEntity().getDiscriminatorColumn().getLength()); - discriminatorColumn.setName(null); - discriminatorColumn.setLength(null); - getJpaProject().synchronizeContextModel(); - - assertNull(typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN)); - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - } - - public void testSetSpecifiedLength() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals(Integer.valueOf(100), discriminatorColumn.getLength()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName(null); - getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(null); - assertNull(typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN)); - } - - public void testGetLengthUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN); - - column.setLength(Integer.valueOf(78)); - getJpaProject().synchronizeContextModel(); - assertEquals(Integer.valueOf(78), getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(78, getJavaEntity().getDiscriminatorColumn().getLength()); - - column.setLength(null); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(0, getJavaEntity().getDiscriminatorColumn().getLength()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getLength()); - } - - - public void testGetColumnDefinition() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getColumnDefinition()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - column.setColumnDefinition(COLUMN_DEFINITION); - getJpaProject().synchronizeContextModel(); - - assertEquals(COLUMN_DEFINITION, getJavaEntity().getDiscriminatorColumn().getColumnDefinition()); - - column.setColumnDefinition(null); - getJpaProject().synchronizeContextModel(); - - assertNull(getJavaEntity().getDiscriminatorColumn().getColumnDefinition()); - - typeResource.removeAnnotation(JPA.DISCRIMINATOR_COLUMN); - } - - public void testSetColumnDefinition() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().getDiscriminatorColumn().setColumnDefinition("foo"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals("foo", column.getColumnDefinition()); - - getJavaEntity().getDiscriminatorColumn().setColumnDefinition(null); - column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - assertNull(column.getColumnDefinition()); - } - - public void testDefaults() throws Exception { - createTestAbstractEntity(); - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + "." + "AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - JavaEntity childEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - - //test defaults with single-table inheritance, no specified discriminator column set - assertEquals(InheritanceType.SINGLE_TABLE, abstractEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - - //test defaults with single-table inheritance, specified discriminator column set on root - abstractEntity.getDiscriminatorColumn().setSpecifiedName("DTYPE2"); - abstractEntity.getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(5)); - abstractEntity.getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR); - - assertEquals(InheritanceType.SINGLE_TABLE, abstractEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - assertEquals("DTYPE2", abstractEntity.getDiscriminatorColumn().getSpecifiedName()); - assertEquals(Integer.valueOf(5), abstractEntity.getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(DiscriminatorType.CHAR, abstractEntity.getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - assertEquals("DTYPE2", childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(5, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorType.CHAR, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedName()); - assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - - //test defaults with table-per-class inheritance, discriminator column does not apply - abstractEntity.getDiscriminatorColumn().setSpecifiedName(null); - abstractEntity.getDiscriminatorColumn().setSpecifiedLength(null); - abstractEntity.getDiscriminatorColumn().setSpecifiedDiscriminatorType(null); - abstractEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - assertEquals(InheritanceType.TABLE_PER_CLASS, abstractEntity.getInheritanceStrategy()); - assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(0, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - assertEquals(InheritanceType.TABLE_PER_CLASS, childEntity.getDefaultInheritanceStrategy()); - assertEquals(null, childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(0, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(null, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddableTests.java deleted file mode 100644 index 9885cce9ad..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddableTests.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.MappedSuperclass; -import org.eclipse.jpt.core.internal.context.java.JavaNullTypeMapping; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaEmbeddableTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEmbeddable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.EMBEDDABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Embeddable"); - } - }); - } - - - public JavaEmbeddableTests(String name) { - super(name); - } - - public void testMorphToEntity() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof Entity); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToMappedSuperclass() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaPersistentType().setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof MappedSuperclass); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToNull() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof JavaNullTypeMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - } - - public void testEmbeddable() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(getJavaPersistentType().getMapping() instanceof Embeddable); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - Iterator<String> overridableAttributeNames = embeddable.overridableAttributeNames(); - assertEquals(overridableAttributeNames.next(), "id"); - assertEquals(overridableAttributeNames.next(), "name"); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - Iterator<String> overridableAssociationNames = embeddable.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testTableNameIsInvalid() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - - assertFalse(embeddable.tableNameIsInvalid(FULLY_QUALIFIED_TYPE_NAME)); - assertFalse(embeddable.tableNameIsInvalid("FOO")); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - assertTrue(embeddable.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(embeddable.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - - public void testAssociatedTables() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - - assertFalse(embeddable.associatedTables().hasNext()); - } - - public void testAssociatedTablesIncludingInherited() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - - assertFalse(embeddable.associatedTablesIncludingInherited().hasNext()); - } - - public void testAssociatedTableNamesIncludingInherited() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - - assertFalse(embeddable.associatedTableNamesIncludingInherited().hasNext()); - } - - //TODO need to create a subclass mappedSuperclass and test this - public void testAllOverridableAssociationNames() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - Iterator<String> overridableAssociationNames = embeddable.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java deleted file mode 100644 index 8618c20fa5..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java +++ /dev/null @@ -1,658 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaEmbeddedIdMappingTests extends ContextModelTestCase -{ - - public static final String EMBEDDABLE_TYPE_NAME = "MyEmbeddable"; - public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - private ICompilationUnit createTestEntityWithEmbeddedIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@EmbeddedId").append(CR); - sb.append(CR); - sb.append(" private " + EMBEDDABLE_TYPE_NAME +" myEmbeddedId;").append(CR); - sb.append(CR); - } - }); - } - - private void createEmbeddableType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append(EMBEDDABLE_TYPE_NAME).append(" {"); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, EMBEDDABLE_TYPE_NAME + ".java", sourceWriter); - } - - - public JavaEmbeddedIdMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(((EmbeddedMapping) persistentAttribute.getMapping()).getAttributeOverrideContainer().attributeOverrides().hasNext()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultEmbeddedIdMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("myEmbeddedId", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - AttributeOverride defaultAttributeOverride = attributeOverrideContainer.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable embeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) embeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("myEmbeddedId", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualAttributeOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - assertEquals(0, attributeOverrideContainer.specifiedAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.specifiedAttributeOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.attributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, attributeOverrideContainer.attributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(4, attributeOverrideContainer.attributeOverridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualAttributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("state"); - getJpaProject().synchronizeContextModel(); - assertEquals(0, attributeOverrideContainer.virtualAttributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - attributeOverrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("city", attributeOverrideContainer.virtualAttributeOverrides().next().getName()); - assertEquals(1, attributeOverrideContainer.virtualAttributeOverridesSize()); - - attributeOverrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator<AttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.virtualAttributeOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state", virtualAttributeOverrides.next().getName()); - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - ListIterator<JavaAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.virtualAttributeOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().setVirtual(false); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - - Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedMappingTests.java deleted file mode 100644 index 8d859abc8b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedMappingTests.java +++ /dev/null @@ -1,863 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaEmbeddedMappingTests extends ContextModelTestCase -{ - - public static final String EMBEDDABLE_TYPE_NAME = "MyEmbeddable"; - public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - private ICompilationUnit createTestEntityWithEmbeddedMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded").append(CR); - sb.append(" private " + EMBEDDABLE_TYPE_NAME + " myEmbedded;").append(CR); - sb.append(CR); - } - }); - } - - private void createEmbeddableType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append(EMBEDDABLE_TYPE_NAME).append(" {"); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, EMBEDDABLE_TYPE_NAME + ".java", sourceWriter); - } - - private void createTestEntityCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Customer").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - - public JavaEmbeddedMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(((EmbeddedMapping) persistentAttribute.getMapping()).getAttributeOverrideContainer().attributeOverrides().hasNext()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultEmbeddedMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testDefaultEmbeddedMappingGenericEmbeddable() throws Exception { - createTestEntityWithDefaultEmbeddedMapping(); - createTestGenericEmbeddable(); - addXmlClassRef(PACKAGE_NAME + ".Entity1"); - addXmlClassRef(PACKAGE_NAME + ".Embeddable1"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertNull(persistentAttribute.getSpecifiedMapping()); - assertNotNull(persistentAttribute.getMapping()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - private void createTestEntityWithDefaultEmbeddedMapping() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Entity1 { ").append(CR); - sb.append("private Embeddable1<Integer> myEmbeddable;").append(CR); - sb.append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity1.java", sourceWriter); - } - - private void createTestGenericEmbeddable() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class Embeddable1<T> {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Embeddable1.java", sourceWriter); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("myEmbedded", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - AttributeOverride defaultAttributeOverride = attributeOverrideContainer.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable embeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) embeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("myEmbedded", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualAttributeOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(0, attributeOverrideContainer.specifiedAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.specifiedAttributeOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.attributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, attributeOverrideContainer.attributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(4, attributeOverrideContainer.attributeOverridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualAttributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("state"); - getJpaProject().synchronizeContextModel(); - assertEquals(0, attributeOverrideContainer.virtualAttributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - attributeOverrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("city", attributeOverrideContainer.virtualAttributeOverrides().next().getName()); - assertEquals(1, attributeOverrideContainer.virtualAttributeOverridesSize()); - - attributeOverrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator<AttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.virtualAttributeOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state", virtualAttributeOverrides.next().getName()); - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - ListIterator<AttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.virtualAttributeOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().setVirtual(false); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - - Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - //1.0 projects do not support dot-notation, this tests to make sure that support does not exist - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestEntityCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - PersistentType customerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - assertEquals(3, attributeOverrideContainer.virtualAttributeOverridesSize()); - ListIterator<AttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.virtualAttributeOverrides(); - AttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualAttributeOverride.getName()); - assertEquals(false, virtualAttributeOverrides.hasNext()); - - - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - EmbeddedMapping nestedEmbeddedMapping = (EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping(); - AttributeOverrideContainer nestedAttributeOverrideContainer = nestedEmbeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, nestedAttributeOverrideContainer.virtualAttributeOverridesSize()); - virtualAttributeOverrides = nestedAttributeOverrideContainer.virtualAttributeOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("plusfour", virtualAttributeOverride.getName()); - - PersistentType zipCodePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - //check the nested embedded (Address.zipCode) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getAttributeOverrideNamed("plusfour"); - assertEquals("plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //check the top-level embedded (Customer.address) attribute override to verify there is no attribute override named zipCode.plusfour - virtualAttributeOverride = ((EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping()).getAttributeOverrideContainer().getAttributeOverrideNamed("zipCode.plusfour"); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEntityTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEntityTests.java deleted file mode 100644 index aaa33ecce1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEntityTests.java +++ /dev/null @@ -1,3409 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.MappedSuperclass; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaNamedNativeQuery; -import org.eclipse.jpt.core.context.java.JavaNamedQuery; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.internal.context.java.JavaNullTypeMapping; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorValueAnnotation; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.InheritanceAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedNativeQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTablesAnnotation; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaEntityTests extends ContextModelTestCase -{ - private static final String ENTITY_NAME = "entityName"; - private static final String TABLE_NAME = "MY_TABLE"; - private static final String DISCRIMINATOR_VALUE = "MY_DISCRIMINATOR_VALUE"; - protected static final String SUB_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_SUB_TYPE_NAME = PACKAGE_NAME + "." + SUB_TYPE_NAME; - - - public JavaEntityTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityInvalidNamedQueries() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.NAMED_QUERIES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@NamedQueries(value={@NamedQuery(query=\"asdf\", name=\"foo\"), @NamedQuer})"); - } - }); - } - - private void createTestAbstractEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public abstract class ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, sourceWriter); - } - - private ICompilationUnit createTestEntityAnnotationOnProperty() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>( - JPA.MAPPED_SUPERCLASS, - JPA.BASIC, - JPA.VERSION, - JPA.TRANSIENT, - JPA.EMBEDDED, - JPA.EMBEDDED_ID, - JPA.ONE_TO_ONE, - JPA.ONE_TO_MANY, - JPA.MANY_TO_ONE, - JPA.MANY_TO_MANY, - JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @Basic"); - sb.append(CR); - sb.append(" private int basic;").append(CR); - sb.append(CR); - sb.append(" @Version"); - sb.append(CR); - sb.append(" private int version;").append(CR); - sb.append(CR); - sb.append(" @Transient"); - sb.append(CR); - sb.append(" private int transient;").append(CR); - sb.append(CR); - sb.append(" @Embedded"); - sb.append(CR); - sb.append(" private int embedded;").append(CR); - sb.append(CR); - sb.append(" @EmbeddedId"); - sb.append(CR); - sb.append(" private int embeddedId;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private " + SUB_TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int oneToMany;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int manyToOne;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int manyToMany;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestAbstractEntityTablePerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)"); - sb.append("abstract"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private ICompilationUnit createTestEntityWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity(name=\"" + ENTITY_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Table(name=\"" + TABLE_NAME + "\")"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithInheritance() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithDiscriminatorValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.DISCRIMINATOR_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@DiscriminatorValue(value=\"" + DISCRIMINATOR_VALUE + "\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.SECONDARY_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@SecondaryTable(name=\"foo\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTables() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@SecondaryTables({@SecondaryTable(name=\"foo\"), @SecondaryTable(name=\"bar\")})"); - } - }); - } - - private ICompilationUnit createAbstractTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)").append(CR); - sb.append("abstract"); - } - }); - } - - private void createTestIdClass() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append("TestTypeId").append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "TestTypeId.java", sourceWriter); - } - - public void testMorphToMappedSuperclass() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = (JavaEntity) getJavaPersistentType().getMapping(); - entity.getTable().setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(0); - entity.addSpecifiedPrimaryKeyJoinColumn(0); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedDiscriminatorValue("asdf"); - entity.getDiscriminatorColumn().setSpecifiedName("BAR"); - entity.getGeneratorContainer().addTableGenerator(); - entity.getGeneratorContainer().addSequenceGenerator(); - entity.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - entity.getQueryContainer().addNamedNativeQuery(0); - entity.getQueryContainer().addNamedQuery(0); - - getJavaPersistentType().setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof MappedSuperclass); - - assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SecondaryTableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = (JavaEntity) getJavaPersistentType().getMapping(); - entity.getTable().setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(0); - entity.addSpecifiedPrimaryKeyJoinColumn(0); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedDiscriminatorValue("asdf"); - entity.getDiscriminatorColumn().setSpecifiedName("BAR"); - entity.getGeneratorContainer().addTableGenerator(); - entity.getGeneratorContainer().addSequenceGenerator(); - entity.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - entity.getQueryContainer().addNamedNativeQuery(0); - entity.getQueryContainer().addNamedQuery(0); - - getJavaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof Embeddable); - - assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SecondaryTableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = (JavaEntity) getJavaPersistentType().getMapping(); - entity.getTable().setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(0); - entity.addSpecifiedPrimaryKeyJoinColumn(0); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedDiscriminatorValue("asdf"); - entity.getDiscriminatorColumn().setSpecifiedName("BAR"); - entity.getGeneratorContainer().addTableGenerator(); - entity.getGeneratorContainer().addSequenceGenerator(); - entity.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - entity.getQueryContainer().addNamedNativeQuery(0); - entity.getQueryContainer().addNamedQuery(0); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof JavaNullTypeMapping); - - assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SecondaryTableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME)); - } - - public void testAccessNoAnnotations() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessAnnotationsOnSuper() throws Exception { - createTestEntityAnnotationOnProperty(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - JavaPersistentType childPersistentType = getJavaPersistentType(); - PersistentType superPersistentType = childPersistentType.getSuperPersistentType(); - - assertEquals(AccessType.PROPERTY, superPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - ((IdMapping) superPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("FOO"); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - typeResource.persistableProperties().next().removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - //no mapping(Id) annotation, but still a Column annotation, so access should still be property - assertEquals(AccessType.PROPERTY, superPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - ((BasicMapping) superPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName(null); - assertEquals(AccessType.FIELD, superPersistentType.getAccess()); - assertEquals(AccessType.FIELD, childPersistentType.getAccess()); - - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, superPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - getEntityMappings().setSpecifiedAccess(AccessType.FIELD); - //still accessType of PROPERTY because the java class is not specified in this orm.xml - assertEquals(AccessType.PROPERTY, superPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - removeXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //only parent specified in orm.xml, i think this outcome is right?? - assertEquals(AccessType.FIELD, ormPersistentType.getJavaPersistentType().getAccess()); - assertEquals(AccessType.FIELD, childPersistentType.getAccess()); - - OrmPersistentType childOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - removeXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - //both parent and child specified in orm.xml - assertEquals(AccessType.FIELD, ormPersistentType.getJavaPersistentType().getAccess()); - assertEquals(AccessType.FIELD, childOrmPersistentType.getJavaPersistentType().getAccess()); - } - - public void testAccessWithXmlSettings() throws Exception { - createTestEntityAnnotationOnProperty(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("FOO"); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - typeResource.persistableProperties().next().removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - //no mapping(Id) annotation, but still a Column annotation, so access should still be property - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - ((BasicMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName(null); - getJpaProject().synchronizeContextModel(); - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - getEntityMappings().setSpecifiedAccess(AccessType.FIELD); - //still accessType of PROPERTY because the java class is not specified in this orm.xml - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //now class is specified in orm.xml, so entityMappings access setting wins over persistence-unit-defaults - assertEquals(AccessType.FIELD, ormPersistentType.getJavaPersistentType().getAccess()); - - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - - //accessType should be PROPERTY now, java gets the access from xml entity if it is specified - assertEquals(AccessType.PROPERTY, ormPersistentType.getJavaPersistentType().getAccess()); - } - - public void testGetSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(ENTITY_NAME, getJavaEntity().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getDefaultName()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(ENTITY_NAME, getJavaEntity().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().setSpecifiedName("foo"); - - assertEquals("foo", getJavaEntity().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals("foo", ((EntityAnnotation) typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)).getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().setSpecifiedName(null); - - assertNull(getJavaEntity().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(((EntityAnnotation) typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)).getName()); - } - - public void testUpdateFromSpecifiedNameChangeInResourceModel() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EntityAnnotation entity = (EntityAnnotation) typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME); - entity.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", getJavaEntity().getSpecifiedName()); - } - - public void testGetTableName() throws Exception { - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - createTestEntityWithName(); - - assertEquals(ENTITY_NAME, getJavaEntity().getPrimaryTableName()); - } - - public void testGetTableName2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getPrimaryTableName()); - } - - public void testGetTableName3() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TABLE_NAME, getJavaEntity().getPrimaryTableName()); - } - - public void testSetTableNameWithNullTable() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = getJavaEntity().getTable(); - assertEquals(TYPE_NAME, table.getName()); - assertSourceDoesNotContain("@Table", cu); - - table.setSpecifiedName(TABLE_NAME); - assertSourceContains("@Table(name = \"" + TABLE_NAME + "\")", cu); - - assertEquals(TABLE_NAME, getJavaEntity().getPrimaryTableName()); - assertEquals(TABLE_NAME, table.getName()); - - table.setSpecifiedCatalog(TABLE_NAME); - } - - public void testGetInheritanceStrategy() throws Exception { - createTestEntityWithInheritance(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(InheritanceType.TABLE_PER_CLASS, getJavaEntity().getInheritanceStrategy()); - } - - public void testGetDefaultInheritanceStrategy() throws Exception { - createTestEntity(); - createTestSubType(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - - assertNotSame(childEntity, rootEntity); - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - - //change root inheritance strategy, verify default is changed for child entity - rootEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - assertEquals(InheritanceType.SINGLE_TABLE, rootEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, childEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, childEntity.getInheritanceStrategy()); - assertNull(childEntity.getSpecifiedInheritanceStrategy()); - } - - public void testGetSpecifiedInheritanceStrategy() throws Exception { - createTestEntityWithInheritance(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(InheritanceType.TABLE_PER_CLASS, getJavaEntity().getSpecifiedInheritanceStrategy()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME); - - inheritance.setStrategy(org.eclipse.jpt.core.resource.java.InheritanceType.JOINED); - getJpaProject().synchronizeContextModel(); - - assertEquals(InheritanceType.JOINED, getJavaEntity().getSpecifiedInheritanceStrategy()); - - inheritance.setStrategy(null); - getJpaProject().synchronizeContextModel(); - - assertNull(getJavaEntity().getSpecifiedInheritanceStrategy()); - } - - public void testSetSpecifiedInheritanceStrategy() throws Exception { - createTestEntityWithInheritance(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(InheritanceType.TABLE_PER_CLASS, getJavaEntity().getSpecifiedInheritanceStrategy()); - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - - assertEquals(InheritanceType.JOINED, getJavaEntity().getSpecifiedInheritanceStrategy()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME); - assertEquals(org.eclipse.jpt.core.resource.java.InheritanceType.JOINED, inheritance.getStrategy()); - - } - - public void testGetDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_VALUE, getJavaEntity().getDiscriminatorValue()); - } - - public void testGetDefaultDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDefaultDiscriminatorValue()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - assertEquals(getJavaEntity().getName(), getJavaEntity().getDefaultDiscriminatorValue()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.INTEGER); - assertNull(getJavaEntity().getDefaultDiscriminatorValue()); - } - - public void testGetSpecifiedDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_VALUE, getJavaEntity().getSpecifiedDiscriminatorValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME); - - discriminatorValue.setValue("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", getJavaEntity().getSpecifiedDiscriminatorValue()); - - discriminatorValue.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(getJavaEntity().getSpecifiedDiscriminatorValue()); - assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME)); - } - - public void testSetSpecifiedDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DISCRIMINATOR_VALUE, getJavaEntity().getSpecifiedDiscriminatorValue()); - - getJavaEntity().setSpecifiedDiscriminatorValue("foo"); - - assertEquals("foo", getJavaEntity().getSpecifiedDiscriminatorValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME); - assertEquals("foo", discriminatorValue.getValue()); - } - - public void testSecondaryTables() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables(); - - assertTrue(secondaryTables.hasNext()); - assertEquals("foo", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - } - - public void testSecondaryTablesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.secondaryTablesSize()); - - ((SecondaryTableAnnotation) typeResource.addAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(2, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.secondaryTablesSize()); - } - - public void testSpecifiedSecondaryTables() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<JavaSecondaryTable> specifiedSecondaryTables = getJavaEntity().specifiedSecondaryTables(); - - assertTrue(specifiedSecondaryTables.hasNext()); - assertEquals("foo", specifiedSecondaryTables.next().getName()); - assertEquals("bar", specifiedSecondaryTables.next().getName()); - assertFalse(specifiedSecondaryTables.hasNext()); - } - - public void testSpecifiedSecondaryTablesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.specifiedSecondaryTablesSize()); - - ((SecondaryTableAnnotation) typeResource.addAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(2, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.specifiedSecondaryTablesSize()); - } - - public void testAddSpecifiedSecondaryTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator<NestableAnnotation> secondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("BAR", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertFalse(secondaryTables.hasNext()); - } - - public void testAddSpecifiedSecondaryTable2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator<NestableAnnotation> secondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("BAR", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertFalse(secondaryTables.hasNext()); - } - - public void testAddSpecifiedSecondaryTablePreservePkJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable specifiedSecondaryTable = getJavaEntity().addSpecifiedSecondaryTable(0); - specifiedSecondaryTable.setSpecifiedName("FOO"); - specifiedSecondaryTable.setSpecifiedCatalog("CATALOG"); - specifiedSecondaryTable.setSpecifiedSchema("SCHEMA"); - specifiedSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("PK_NAME"); - - //add another specified secondary table, pkJoinColumns from first should be saved. - SecondaryTable specifiedSecondaryTable2 = getJavaEntity().addSpecifiedSecondaryTable(1); - specifiedSecondaryTable2.setSpecifiedName("BAR"); - - - Iterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables(); - SecondaryTable secondaryTable = secondaryTables.next(); - assertEquals(secondaryTable, specifiedSecondaryTable); - assertEquals("FOO", secondaryTable.getName()); - assertEquals("CATALOG", secondaryTable.getCatalog()); - assertEquals("SCHEMA", secondaryTable.getSchema()); - assertEquals(1, secondaryTable.specifiedPrimaryKeyJoinColumnsSize()); - PrimaryKeyJoinColumn pkJoinColumn = secondaryTable.specifiedPrimaryKeyJoinColumns().next(); - assertEquals("PK_NAME", pkJoinColumn.getName()); - - secondaryTable = secondaryTables.next(); - assertEquals(secondaryTable, specifiedSecondaryTable2); - assertEquals("BAR", secondaryTable.getName()); - assertEquals(0, secondaryTable.specifiedPrimaryKeyJoinColumnsSize()); - - } - - public void testRemoveSpecifiedSecondaryTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, CollectionTools.size(typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME))); - - getJavaEntity().removeSpecifiedSecondaryTable(1); - - Iterator<NestableAnnotation> secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTableResources.next()).getName()); - assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTableResources.next()).getName()); - assertFalse(secondaryTableResources.hasNext()); - - Iterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - - getJavaEntity().removeSpecifiedSecondaryTable(1); - secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTableResources.next()).getName()); - assertFalse(secondaryTableResources.hasNext()); - - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - - getJavaEntity().removeSpecifiedSecondaryTable(0); - secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertFalse(secondaryTableResources.hasNext()); - secondaryTables = getJavaEntity().secondaryTables(); - assertFalse(secondaryTables.hasNext()); - - assertNull(typeResource.getAnnotation(SecondaryTablesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedSecondaryTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - entity.addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - Iterator<NestableAnnotation> javaSecondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaSecondaryTables)); - - - entity.moveSpecifiedSecondaryTable(2, 0); - ListIterator<SecondaryTable> secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getSpecifiedName()); - assertEquals("BAZ", secondaryTables.next().getSpecifiedName()); - assertEquals("FOO", secondaryTables.next().getSpecifiedName()); - - javaSecondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - assertEquals("BAZ", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - - - entity.moveSpecifiedSecondaryTable(0, 1); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getSpecifiedName()); - assertEquals("BAR", secondaryTables.next().getSpecifiedName()); - assertEquals("FOO", secondaryTables.next().getSpecifiedName()); - - javaSecondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - assertEquals("BAR", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - } - - public void testUpdateSpecifiedSecondaryTables() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((SecondaryTableAnnotation) typeResource.addAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(2, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<SecondaryTable> secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.moveAnnotation(2, 0, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.moveAnnotation(0, 1, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.removeAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.removeAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.removeAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertFalse(secondaryTables.hasNext()); - } - - public void testAssociatedTables() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, CollectionTools.size(getJavaEntity().associatedTables())); - Iterator<Table> associatedTables = getJavaEntity().associatedTables(); - Table table1 = associatedTables.next(); - SecondaryTable table2 = (SecondaryTable) associatedTables.next(); - SecondaryTable table3 = (SecondaryTable) associatedTables.next(); - assertEquals(TYPE_NAME, table1.getName()); - assertEquals("foo", table2.getName()); - assertEquals("bar", table3.getName()); - } - - public void testAssociatedTablesIncludingInherited() throws Exception { - createTestEntityWithSecondaryTables(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - - assertEquals(3, CollectionTools.size(rootEntity.associatedTablesIncludingInherited())); - Iterator<Table> associatedTables = rootEntity.associatedTablesIncludingInherited(); - Table table1 = associatedTables.next(); - SecondaryTable table2 = (SecondaryTable) associatedTables.next(); - SecondaryTable table3 = (SecondaryTable) associatedTables.next(); - assertEquals(TYPE_NAME, table1.getName()); - assertEquals("foo", table2.getName()); - assertEquals("bar", table3.getName()); - - //TODO probably want this to be 3, since in this case the child descriptor really uses the - //parent table because it is single table inheritance strategy. Not sure yet how to deal with this. - assertEquals(4, CollectionTools.size(childEntity.associatedTablesIncludingInherited())); - } - - public void testAssociatedTableNamesIncludingInherited() throws Exception { - createTestEntityWithSecondaryTables(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - - assertEquals(3, CollectionTools.size(rootEntity.associatedTableNamesIncludingInherited())); - Iterator<String> associatedTables = rootEntity.associatedTableNamesIncludingInherited(); - String table1 = associatedTables.next(); - String table2 = associatedTables.next(); - String table3 = associatedTables.next(); - assertEquals(TYPE_NAME, table1); - assertEquals("foo", table2); - assertEquals("bar", table3); - - //TODO probably want this to be 3, since in this case the child descriptor really uses the - //parent table because it is single table inheritance strategy. Not sure yet how to deal with this. - assertEquals(4, CollectionTools.size(childEntity.associatedTableNamesIncludingInherited())); - } - - public void testAddSecondaryTableToResourceModel() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - assertEquals(1, getJavaEntity().secondaryTablesSize()); - assertEquals("FOO", getJavaEntity().secondaryTables().next().getSpecifiedName()); - assertEquals("FOO", getJavaEntity().secondaryTables().next().getName()); - - SecondaryTableAnnotation secondaryTable2 = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable2.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, getJavaEntity().secondaryTablesSize()); - ListIterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables(); - assertEquals("FOO", secondaryTables.next().getSpecifiedName()); - assertEquals("BAR", secondaryTables.next().getSpecifiedName()); - - SecondaryTableAnnotation secondaryTable3 = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable3.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - assertEquals(3, getJavaEntity().secondaryTablesSize()); - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals("BAZ", secondaryTables.next().getSpecifiedName()); - assertEquals("FOO", secondaryTables.next().getSpecifiedName()); - assertEquals("BAR", secondaryTables.next().getSpecifiedName()); - } - - public void testRemoveSecondaryTableFromResourceModel() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedSecondaryTable(2).setSpecifiedName("baz"); - ListIterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables(); - - assertEquals(3, getJavaEntity().secondaryTablesSize()); - assertEquals("foo", secondaryTables.next().getSpecifiedName()); - assertEquals("bar", secondaryTables.next().getSpecifiedName()); - assertEquals("baz", secondaryTables.next().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals(2, getJavaEntity().secondaryTablesSize()); - assertEquals("bar", secondaryTables.next().getSpecifiedName()); - assertEquals("baz", secondaryTables.next().getSpecifiedName()); - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals(1, getJavaEntity().secondaryTablesSize()); - assertEquals("baz", secondaryTables.next().getSpecifiedName()); - - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - getJpaProject().synchronizeContextModel(); - - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals(0, getJavaEntity().secondaryTablesSize()); - assertFalse(secondaryTables.hasNext()); - } - - public void testGetSequenceGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - assertEquals(0, getJavaEntity().getPersistenceUnit().generatorsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - assertNotNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - assertEquals(2, typeResource.annotationsSize()); - assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize()); - - getJavaEntity().getGeneratorContainer().getSequenceGenerator().setName("foo"); - assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize()); - } - - public void testAddSequenceGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - - getJavaEntity().getGeneratorContainer().addSequenceGenerator(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(typeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - assertNotNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - getJavaEntity().getGeneratorContainer().addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - getJavaEntity().getGeneratorContainer().removeSequenceGenerator(); - - assertNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - assertNull(typeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - - //try removing the sequence generator again, should get an IllegalStateException - try { - getJavaEntity().getGeneratorContainer().removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetTableGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - assertEquals(0, getJavaEntity().getPersistenceUnit().generatorsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.TABLE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - assertNotNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - assertEquals(2, typeResource.annotationsSize()); - assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize()); - - getJavaEntity().getGeneratorContainer().getTableGenerator().setName("foo"); - assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize()); - } - - public void testAddTableGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - - getJavaEntity().getGeneratorContainer().addTableGenerator(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(typeResource.getAnnotation(JPA.TABLE_GENERATOR)); - assertNotNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - getJavaEntity().getGeneratorContainer().addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.TABLE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - getJavaEntity().getGeneratorContainer().removeTableGenerator(); - - assertNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - assertNull(typeResource.getAnnotation(JPA.TABLE_GENERATOR)); - - //try removing the table generator again, should get an IllegalStateException - try { - getJavaEntity().getGeneratorContainer().removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetDiscriminatorColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(getJavaEntity().getDiscriminatorColumn()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - - column.setName(null); - getJpaProject().synchronizeContextModel(); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - - typeResource.removeAnnotation(JPA.DISCRIMINATOR_COLUMN); - getJpaProject().synchronizeContextModel(); - - assertNotNull(getJavaEntity().getDiscriminatorColumn()); - } - - public void testSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<JavaPrimaryKeyJoinColumn> specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - - assertFalse(specifiedPkJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - PrimaryKeyJoinColumnAnnotation pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - pkJoinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - pkJoinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - - pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - pkJoinColumn.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - typeResource.moveAnnotation(1, 0, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - typeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - typeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - - typeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertFalse(specifiedPkJoinColumns.hasNext()); - } - - public void testSpecifiedPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, getJavaEntity().specifiedPrimaryKeyJoinColumnsSize()); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertEquals(3, getJavaEntity().specifiedPrimaryKeyJoinColumnsSize()); - } - - public void testPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - //just the default pkJoinColumn, so 1 - assertEquals(1, getJavaEntity().primaryKeyJoinColumnsSize()); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - //only the specified pkJoinColumns, 3 - assertEquals(3, getJavaEntity().primaryKeyJoinColumnsSize()); - } - - public void testGetDefaultPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator<NestableAnnotation> pkJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertFalse(pkJoinColumns.hasNext()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator<NestableAnnotation> pkJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertFalse(pkJoinColumns.hasNext()); - } - public void testRemoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, CollectionTools.size(typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME))); - - getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(1); - - Iterator<NestableAnnotation> pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - Iterator<JavaPrimaryKeyJoinColumn> pkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(1); - pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - pkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(0); - pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertFalse(pkJoinColumnResources.hasNext()); - pkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertFalse(pkJoinColumns.hasNext()); - - assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - entity.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - entity.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - Iterator<NestableAnnotation> javaPrimaryKeyJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaPrimaryKeyJoinColumns)); - - - entity.moveSpecifiedPrimaryKeyJoinColumn(2, 0); - ListIterator<PrimaryKeyJoinColumn> primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaPrimaryKeyJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - - - entity.moveSpecifiedPrimaryKeyJoinColumn(0, 1); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaPrimaryKeyJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - } - - public void testUpdateSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(2, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<PrimaryKeyJoinColumn> primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.moveAnnotation(2, 0, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.moveAnnotation(0, 1, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.removeAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertFalse(primaryKeyJoinColumns.hasNext()); - } - - public void testPrimaryKeyJoinColumnIsVirtual() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertTrue(getJavaEntity().getDefaultPrimaryKeyJoinColumn().isVirtual()); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0); - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertFalse(specifiedPkJoinColumn.isVirtual()); - - assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - } - - public void testTableNameIsInvalid() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertFalse(getJavaEntity().tableNameIsInvalid(TYPE_NAME)); - assertTrue(getJavaEntity().tableNameIsInvalid("FOO")); - - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - - assertFalse(getJavaEntity().tableNameIsInvalid("BAR")); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = (Entity) getJavaPersistentType().getMapping(); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - public void testOverridableAttributes() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributes = getJavaEntity().overridableAttributeNames(); - assertFalse(overridableAttributes.hasNext()); - - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributes = getJavaEntity().overridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributeNames = getJavaEntity().overridableAttributeNames(); - assertFalse(overridableAttributeNames.hasNext()); - - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributeNames = getJavaEntity().overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testAllOverridableAttributes() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("foo", overridableAttributes.next()); - assertEquals("basic", overridableAttributes.next()); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributesTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - overridableAttributes = abstractEntity.allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAssociationsTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociations = getJavaEntity().allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - overridableAssociations = abstractEntity.allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testAllOverridableAttributesMappedSuperclassInOrmXml() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("foo", overridableAttributes.next()); - assertEquals("basic", overridableAttributes.next()); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributeNames = getJavaEntity().allOverridableAttributeNames(); - assertEquals("foo", overridableAttributeNames.next()); - assertEquals("basic", overridableAttributeNames.next()); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - typeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrideDefaults() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.virtualAttributeOverridesSize()); - AttributeOverride virtualAttributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertEquals("foo", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - BasicMapping fooMapping = (BasicMapping) mappedSuperclass.getPersistentType().getAttributeNamed("foo").getMapping(); - fooMapping.getColumn().setSpecifiedName("FOO"); - fooMapping.getColumn().setSpecifiedTable("BAR"); - fooMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - fooMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - fooMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - fooMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - fooMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - fooMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - fooMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - fooMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.virtualAttributeOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - fooMapping.getColumn().setSpecifiedName(null); - fooMapping.getColumn().setSpecifiedTable(null); - fooMapping.getColumn().setColumnDefinition(null); - fooMapping.getColumn().setSpecifiedInsertable(null); - fooMapping.getColumn().setSpecifiedUpdatable(null); - fooMapping.getColumn().setSpecifiedUnique(null); - fooMapping.getColumn().setSpecifiedNullable(null); - fooMapping.getColumn().setSpecifiedLength(null); - fooMapping.getColumn().setSpecifiedPrecision(null); - fooMapping.getColumn().setSpecifiedScale(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - virtualAttributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertEquals("foo", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - virtualAttributeOverride = virtualAttributeOverride.setVirtual(false); - assertEquals(3, overrideContainer.virtualAttributeOverridesSize()); - } - - public void testVirtualAttributeOverridesEntityHierachy() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualAttributeOverridesSize()); - AttributeOverride virtualAttributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - JavaEntity superclass = (JavaEntity) getJavaPersistentType().getMapping(); - - BasicMapping idMapping = (BasicMapping) superclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualAttributeOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - virtualAttributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride = virtualAttributeOverride.setVirtual(false); - assertEquals(2, overrideContainer.virtualAttributeOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - assertEquals(0, overrideContainer.specifiedAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.specifiedAttributeOverridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - assertEquals(4, overrideContainer.virtualAttributeOverridesSize()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(3, overrideContainer.virtualAttributeOverridesSize()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(2, overrideContainer.virtualAttributeOverridesSize()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(1, overrideContainer.virtualAttributeOverridesSize()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(0, overrideContainer.virtualAttributeOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - assertEquals(4, overrideContainer.attributeOverridesSize()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(4, overrideContainer.attributeOverridesSize()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(4, overrideContainer.attributeOverridesSize()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(5, overrideContainer.attributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator<NestableAnnotation> attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("basic", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - ListIterator<JavaAttributeOverride> virtualAttributeOverrides = overrideContainer.virtualAttributeOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().setVirtual(false); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator<NestableAnnotation> attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("basic", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(3, CollectionTools.size(typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME))); - - overrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - - Iterator<NestableAnnotation> attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("basic", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - Iterator<JavaAttributeOverride> attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("basic", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("id", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrideResources.hasNext()); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertFalse(attributeOverrides.hasNext()); - - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - - Iterator<NestableAnnotation> javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaAttributeOverrides)); - - overrideContainer.moveSpecifiedAttributeOverride(2, 0); - ListIterator<AttributeOverride> attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("basic", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - - javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("basic", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedAttributeOverride(0, 1); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("id", attributeOverrides.next().getName()); - assertEquals("basic", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - - javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("basic", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - } - - public void testUpdateSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((AttributeOverrideAnnotation) typeResource.addAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((AttributeOverrideAnnotation) typeResource.addAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((AttributeOverrideAnnotation) typeResource.addAnnotation(2, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<AttributeOverride> attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.moveAnnotation(2, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.moveAnnotation(0, 1, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - ListIterator<JavaAttributeOverride> virtualAttributeOverrides = overrideContainer.virtualAttributeOverrides(); - AttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("basic", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedAttributeOverrides().next(); - assertFalse(specifiedAttributeOverride.isVirtual()); - - - virtualAttributeOverrides = overrideContainer.virtualAttributeOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("basic", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociationNames = getJavaEntity().overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAllOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociationNames = getJavaEntity().allOverridableAssociationNames(); - assertEquals("oneToOne", overridableAssociationNames.next()); - assertEquals("manyToOne", overridableAssociationNames.next()); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAllOverridableAssociations() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociations = getJavaEntity().allOverridableAssociationNames(); - assertEquals("oneToOne", overridableAssociations.next()); - assertEquals("manyToOne", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } -// -// public void testAllOverridableAssociationsMappedSuperclassInOrmXml() throws Exception { -// createTestMappedSuperclass(); -// createTestSubType(); -// addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); -// getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// -// Iterator<RelationshipMapping> overridableAssociations = getJavaEntity().allOverridableAssociations(); -// assertEquals("oneToOne", overridableAssociations.next().getName()); -// assertEquals("manyToOne", overridableAssociations.next().getName()); -// assertFalse(overridableAssociations.hasNext()); -// } - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ListIterator<JavaAssociationOverride> specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - typeResource.moveAnnotation(1, 0, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testVirtualAssociationOverrideDefaults() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AssociationOverrideContainer overrideContainer = javaEntity.getAssociationOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.virtualAssociationOverridesSize()); - AssociationOverride virtualAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - JoinColumnJoiningStrategy joiningStrategy = virtualAssociationOverride.getRelationshipReference().getJoinColumnJoiningStrategy(); - assertEquals("oneToOne", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.joinColumnsSize()); - JoinColumn virtualJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("oneToOne_id", virtualJoinColumn.getName()); - assertEquals("id", virtualJoinColumn.getReferencedColumnName()); - assertEquals(SUB_TYPE_NAME, virtualJoinColumn.getTable()); - assertEquals(null, virtualJoinColumn.getColumnDefinition()); - assertEquals(true, virtualJoinColumn.isInsertable()); - assertEquals(true, virtualJoinColumn.isUpdatable()); - assertEquals(false, virtualJoinColumn.isUnique()); - assertEquals(true, virtualJoinColumn.isNullable()); - - - OneToOneMapping oneToOneMapping = (OneToOneMapping) getJavaPersistentType().getAttributeNamed("oneToOne").getMapping(); - JoinColumn joinColumn = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("MY_JOIN_COLUMN"); - joinColumn.setSpecifiedReferencedColumnName("MY_REFERENCE_COLUMN"); - joinColumn.setSpecifiedTable("BAR"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.virtualAssociationOverridesSize()); - virtualAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - joiningStrategy = virtualAssociationOverride.getRelationshipReference().getJoinColumnJoiningStrategy(); - assertEquals("oneToOne", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.joinColumnsSize()); - virtualAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - virtualJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition()); - assertEquals(false, virtualJoinColumn.isInsertable()); - assertEquals(false, virtualJoinColumn.isUpdatable()); - assertEquals(true, virtualJoinColumn.isUnique()); - assertEquals(false, virtualJoinColumn.isNullable()); - - assertEquals("MY_JOIN_COLUMN", joiningStrategy.joinColumns().next().getName()); - - - - - - - //idMapping.getColumn().setSpecifiedName(null); - //idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - virtualAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - assertEquals("oneToOne", virtualAssociationOverride.getName()); - - virtualAssociationOverride = virtualAssociationOverride.setVirtual(false); - assertEquals(1, overrideContainer.virtualAssociationOverridesSize()); - - - -// //TODO joinColumns for default association overrides -//// IJoinColumn defaultJoinColumn = defaultAssociationOverride.joinColumns().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// -//// IMappedSuperclass mappedSuperclass = (IMappedSuperclass) javaPersistentType().getMapping(); -//// -//// IOneToOneMapping addressMapping = (IOneToOneMapping) mappedSuperclass.persistentType().attributeNamed("address").getMapping(); -//// IJoinColumn joinColumn = addressMapping.addSpecifiedJoinColumn(0); -//// joinColumn.setSpecifiedName("FOO"); -//// joinColumn.setSpecifiedReferencedColumnName("BAR"); -//// joinColumn.setSpecifiedTable("BAZ"); -//// -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// assertEquals(1, CollectionTools.size(javaEntity.defaultAssociationOverrides())); -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultAssociationOverride.getName()); -//// assertEquals("FOO", defaultJoinColumn.getName()); -//// assertEquals("BAR", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals("BAZ", defaultJoinColumn.getTable()); -//// -//// joinColumn.setSpecifiedName(null); -//// joinColumn.setSpecifiedReferencedColumnName(null); -//// joinColumn.setSpecifiedTable(null); -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// javaEntity.addSpecifiedAssociationOverride(0).setName("address"); -//// assertEquals(0, CollectionTools.size(javaEntity.defaultAssociationOverrides())); - - } - - public void testSpecifiedAssociationOverridesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - assertEquals(0, overrideContainer.specifiedAssociationOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("FOO"); - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.specifiedAssociationOverridesSize()); - } - - public void testVirtualAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.virtualAssociationOverridesSize()); - - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - assertEquals(1, overrideContainer.virtualAssociationOverridesSize()); - - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - assertEquals(0, overrideContainer.virtualAssociationOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.associationOverridesSize()); - - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - assertEquals(2, overrideContainer.associationOverridesSize()); - - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - assertEquals(2, overrideContainer.associationOverridesSize()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - AssociationOverrideAnnotation annotation = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, overrideContainer.associationOverridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator<NestableAnnotation> associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("oneToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("manyToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ListIterator<JavaAssociationOverride> virtualAssociationOverrides = overrideContainer.virtualAssociationOverrides(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().setVirtual(false); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator<NestableAnnotation> associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("manyToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("oneToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(2, CollectionTools.size(typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME))); - - overrideContainer.specifiedAssociationOverrides().next().setVirtual(true); - - Iterator<NestableAnnotation> associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("manyToOne", ((AssociationOverrideAnnotation) associationOverrideResources.next()).getName()); - assertFalse(associationOverrideResources.hasNext()); - - Iterator<JavaAssociationOverride> associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("manyToOne", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - overrideContainer.specifiedAssociationOverrides().next().setVirtual(true); - associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertFalse(associationOverrideResources.hasNext()); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertFalse(associationOverrides.hasNext()); - - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - - Iterator<NestableAnnotation> javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaAssociationOverrides)); - - - overrideContainer.moveSpecifiedAssociationOverride(1, 0); - ListIterator<AssociationOverride> associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("manyToOne", associationOverrides.next().getName()); - assertEquals("oneToOne", associationOverrides.next().getName()); - - javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("manyToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("oneToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedAssociationOverride(0, 1); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("oneToOne", associationOverrides.next().getName()); - assertEquals("manyToOne", associationOverrides.next().getName()); - - javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("oneToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("manyToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((AssociationOverrideAnnotation) typeResource.addAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((AssociationOverrideAnnotation) typeResource.addAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((AssociationOverrideAnnotation) typeResource.addAnnotation(2, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<AssociationOverride> associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.moveAnnotation(2, 0, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.moveAnnotation(0, 1, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ListIterator<JavaAssociationOverride> virtualAssociationOverrides = overrideContainer.virtualAssociationOverrides(); - AssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("oneToOne", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("manyToOne", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedAssociationOverrides().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = overrideContainer.virtualAssociationOverrides(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("manyToOne", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - public void testAddNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - NamedQuery namedQuery1 = entity.getQueryContainer().addNamedQuery(0); - namedQuery1.setName("FOO"); - - Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - NamedQuery namedQuery2 = entity.getQueryContainer().addNamedQuery(0); - namedQuery2.setName("BAR"); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - NamedQuery namedQuery3 = entity.getQueryContainer().addNamedQuery(1); - namedQuery3.setName("BAZ"); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery1, namedQueries.next()); - - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("foo"); - } - - public void testInvalidNamedQueries() throws Exception { - createTestEntityInvalidNamedQueries(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - assertEquals(2, entity.getQueryContainer().namedQueriesSize()); - } - - public void testRemoveNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedQuery(0).setName("FOO"); - entity.getQueryContainer().addNamedQuery(1).setName("BAR"); - entity.getQueryContainer().addNamedQuery(2).setName("BAZ"); - - Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(1, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(0, CollectionTools.size(javaNamedQueries)); - } - - public void testAddNamedNativeQueryWithNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedQuery(0).setName("FOO"); - - - NamedNativeQueryAnnotation nativeQuery = (NamedNativeQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - nativeQuery.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(1, entity.getQueryContainer().namedNativeQueriesSize()); - ListIterator<JavaNamedNativeQuery> namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedQueries.next().getName()); - } - - public void testAddNamedQueryWithNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("FOO"); - - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - namedQuery.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(1, entity.getQueryContainer().namedQueriesSize()); - ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - } - - public void testMoveNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedQuery(0).setName("FOO"); - entity.getQueryContainer().addNamedQuery(1).setName("BAR"); - entity.getQueryContainer().addNamedQuery(2).setName("BAZ"); - - Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - - entity.getQueryContainer().moveNamedQuery(2, 0); - ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - - entity.getQueryContainer().moveNamedQuery(0, 1); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - } - - public void testUpdateNamedQueries() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - - ((NamedQueryAnnotation) typeResource.addAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedQueryAnnotation) typeResource.addAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((NamedQueryAnnotation) typeResource.addAnnotation(2, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, entity.getPersistenceUnit().queriesSize()); - - typeResource.moveAnnotation(2, 0, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.moveAnnotation(0, 1, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.removeAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertFalse(namedQueries.hasNext()); - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - } - - public void testNamedQueriesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getQueryContainer().namedQueriesSize()); - - ((NamedQueryAnnotation) typeResource.addAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedQueryAnnotation) typeResource.addAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((NamedQueryAnnotation) typeResource.addAnnotation(2, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.getQueryContainer().namedQueriesSize()); - } - - public void testAddNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().addNamedNativeQuery(0); - namedNativeQuery.setName("FOO"); - - Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - NamedNativeQuery namedNativeQuery2 = entity.getQueryContainer().addNamedNativeQuery(0); - namedNativeQuery2.setName("BAR"); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - NamedNativeQuery namedNativeQuery3 = entity.getQueryContainer().addNamedNativeQuery(1); - namedNativeQuery3.setName("BAZ"); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - ListIterator<JavaNamedNativeQuery> namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals(namedNativeQuery2, namedQueries.next()); - assertEquals(namedNativeQuery3, namedQueries.next()); - assertEquals(namedNativeQuery, namedQueries.next()); - - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - } - - public void testRemoveNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("FOO"); - entity.getQueryContainer().addNamedNativeQuery(1).setName("BAR"); - entity.getQueryContainer().addNamedNativeQuery(2).setName("BAZ"); - - Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - entity.getQueryContainer().removeNamedNativeQuery(0); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - entity.getQueryContainer().removeNamedNativeQuery(0); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(1, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - entity.getQueryContainer().removeNamedNativeQuery(0); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(0, CollectionTools.size(javaNamedQueries)); - } - - public void testMoveNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("FOO"); - entity.getQueryContainer().addNamedNativeQuery(1).setName("BAR"); - entity.getQueryContainer().addNamedNativeQuery(2).setName("BAZ"); - - Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - entity.getQueryContainer().moveNamedNativeQuery(2, 0); - ListIterator<JavaNamedNativeQuery> namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - - entity.getQueryContainer().moveNamedNativeQuery(0, 1); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - } - - public void testUpdateNamedNativeQueries() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(0, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(2, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - ListIterator<JavaNamedNativeQuery> namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, entity.getPersistenceUnit().queriesSize()); - - typeResource.moveAnnotation(2, 0, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.moveAnnotation(0, 1, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.removeAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(0, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertFalse(namedQueries.hasNext()); - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - } - - public void testNamedNativeQueriesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getQueryContainer().namedNativeQueriesSize()); - - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(0, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(2, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.getQueryContainer().namedNativeQueriesSize()); - } - - public void testUpdateIdClass() throws Exception { - createTestEntity(); - createTestIdClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - // test setting id class name to nonexistent class. test class name is set, but class is null - String nonExistentIdClassName = PACKAGE_NAME + ".Foo"; - idClass.setValue(nonExistentIdClassName); - getJpaProject().synchronizeContextModel(); - assertEquals(nonExistentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertEquals(nonExistentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - - // test setting id class name to existent class. test class name is set and class is not null - String existentIdClassName = PACKAGE_NAME + ".TestTypeId"; - idClass.setValue(existentIdClassName); - getJpaProject().synchronizeContextModel(); - assertEquals(existentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertEquals(existentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertNotNull(getJavaEntity().getIdClassReference().getIdClass()); - - //test setting @IdClass value to null, IdClass annotation is removed - idClass.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - - //reset @IdClass value and then remove @IdClass - idClass = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - idClass.setValue(existentIdClassName); - typeResource.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - } - - public void testModifyIdClass() throws Exception { - createTestEntity(); - createTestIdClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - - String nonExistentIdClassName = PACKAGE_NAME + ".Foo"; - getJavaEntity().getIdClassReference().setSpecifiedIdClassName(nonExistentIdClassName); - assertEquals(nonExistentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(nonExistentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - - String existentIdClassName = PACKAGE_NAME + ".TestTypeId"; - getJavaEntity().getIdClassReference().setSpecifiedIdClassName(existentIdClassName); - assertEquals(existentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(existentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNotNull(getJavaEntity().getIdClassReference().getIdClass()); - - getJavaEntity().getIdClassReference().setSpecifiedIdClassName(null); - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - } - - public void testGetPrimaryKeyColumnNameWithAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType entityPersistentType = classRefs.next().getJavaPersistentType(); - JavaEntity javaEntity = (JavaEntity) entityPersistentType.getMapping(); - JavaPersistentType mappedSuperclassPersistentType = classRefs.next().getJavaPersistentType(); - - assertEquals("id", javaEntity.getPrimaryKeyColumnName()); - - ((JavaIdMapping) mappedSuperclassPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID"); - assertEquals("MY_ID", javaEntity.getPrimaryKeyColumnName()); - - ListIterator<JavaAttributeOverride> virtualAttributeOverrides = javaEntity.getAttributeOverrideContainer().virtualAttributeOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next(); - JavaAttributeOverride javaAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", javaAttributeOverride.getName()); - - javaAttributeOverride = javaAttributeOverride.setVirtual(false); - javaAttributeOverride.getColumn().setSpecifiedName("ID"); - assertEquals("ID", javaEntity.getPrimaryKeyColumnName()); - } - - public void testDiscriminatorValueIsUndefinedConcreteClass() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(getJavaEntity().discriminatorValueIsUndefined()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertFalse(getJavaEntity().discriminatorValueIsUndefined()); - } - - public void testDiscriminatorValueIsUndefinedAbstractClass() throws Exception { - createTestAbstractEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(getJavaEntity().discriminatorValueIsUndefined()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertTrue(getJavaEntity().discriminatorValueIsUndefined()); - } - - public void testSpecifiedDiscriminatorColumnIsAllowed() throws Exception { - createAbstractTestEntity(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity concreteEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals("AnnotationTestTypeChild", concreteEntity.getName()); - - Entity abstractEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals(TYPE_NAME, abstractEntity.getName()); - - //table-per-class, no discriminator column allowed - assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed()); - assertFalse(abstractEntity.specifiedDiscriminatorColumnIsAllowed()); - - - //single-table, discriminator column allowed on root entity - abstractEntity.setSpecifiedInheritanceStrategy(null); - assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed()); - assertTrue(abstractEntity.specifiedDiscriminatorColumnIsAllowed()); - } - - public void testAbstractEntityGetDefaultDiscriminatorColumnNameTablePerClassInheritance() throws Exception { - createAbstractTestEntity(); - createTestSubType(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity concreteEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals("AnnotationTestTypeChild", concreteEntity.getName()); - - Entity abstractEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals(TYPE_NAME, abstractEntity.getName()); - - - assertEquals(InheritanceType.TABLE_PER_CLASS, abstractEntity.getSpecifiedInheritanceStrategy()); - assertEquals(null, concreteEntity.getSpecifiedInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, concreteEntity.getDefaultInheritanceStrategy()); - - - assertTrue(abstractEntity.discriminatorValueIsUndefined()); - assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed()); - assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(null, concreteEntity.getDiscriminatorColumn().getDefaultName()); - - assertTrue(abstractEntity.discriminatorValueIsUndefined()); - assertEquals(null, abstractEntity.getDefaultDiscriminatorValue()); - assertTrue(concreteEntity.discriminatorValueIsUndefined()); - assertEquals(null, concreteEntity.getDefaultDiscriminatorValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaGeneratedValueTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaGeneratedValueTests.java deleted file mode 100644 index a198b737a1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaGeneratedValueTests.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.GeneratedValue; -import org.eclipse.jpt.core.context.GenerationType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaGeneratedValueTests extends ContextModelTestCase -{ - private static final String GENERATOR = "MY_GENERATOR"; - - private ICompilationUnit createTestEntityWithGeneratedValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.GENERATED_VALUE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@GeneratedValue(generator=\"" + GENERATOR + "\")"); - } - }); - } - - public JavaGeneratedValueTests(String name) { - super(name); - } - - public void testGetGenerator() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator()); - - //change resource model sequenceGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - generatedValue.setGenerator("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", idMapping.getGeneratedValue().getGenerator()); - } - - public void testSetSpecifiedGenerator() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator()); - - idMapping.getGeneratedValue().setSpecifiedGenerator("foo"); - - assertEquals("foo", idMapping.getGeneratedValue().getGenerator()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - assertEquals("foo", generatedValue.getGenerator()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator()); - - idMapping.getGeneratedValue().setSpecifiedGenerator(null); - - assertNotNull(idMapping.getGeneratedValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - assertNotNull(generatedValue); - } - - public void testGetStrategy() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy()); - - //change resource model sequenceGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - generatedValue.setStrategy(org.eclipse.jpt.core.resource.java.GenerationType.IDENTITY); - getJpaProject().synchronizeContextModel(); - - assertEquals(GenerationType.IDENTITY, idMapping.getGeneratedValue().getStrategy()); - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getDefaultStrategy()); - } - - public void testSetSpecifiedStrategy() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy()); - - idMapping.getGeneratedValue().setSpecifiedStrategy(GenerationType.IDENTITY); - - assertEquals(GenerationType.IDENTITY, idMapping.getGeneratedValue().getStrategy()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - assertEquals(org.eclipse.jpt.core.resource.java.GenerationType.IDENTITY, generatedValue.getStrategy()); - - idMapping.getGeneratedValue().setSpecifiedStrategy(null); - - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy()); - generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - assertNotNull(generatedValue); - assertNull(generatedValue.getStrategy()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaIdMappingTests.java deleted file mode 100644 index c06b8b4f93..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaIdMappingTests.java +++ /dev/null @@ -1,717 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaIdMappingTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithTemporal() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@Temporal(TemporalType.TIMESTAMP)").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithIdMappingGeneratedValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.GENERATED_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@GeneratedValue").append(CR); - } - }); - } - - public JavaIdMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((VersionMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((VersionMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporal() throws Exception { - createTestEntityWithTemporal(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) idMapping.getConverter()).getTemporalType()); - } - - public void testSetTemporal() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - assertEquals(Converter.NO_CONVERTER, idMapping.getConverter().getType()); - - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - idMapping.setConverter(Converter.NO_CONVERTER); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(Converter.NO_CONVERTER, idMapping.getConverter().getType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.core.resource.java.TemporalType.DATE); - getJpaProject().synchronizeContextModel(); - - assertEquals(TemporalType.DATE, ((TemporalConverter) idMapping.getConverter()).getTemporalType()); - - attributeResource.removeAnnotation(TemporalAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertEquals(Converter.NO_CONVERTER, idMapping.getConverter().getType()); - assertFalse(idMapping.isDefault()); - assertSame(idMapping, persistentAttribute.getSpecifiedMapping()); - } - - public void testGetColumn() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getColumn().getSpecifiedName()); - assertEquals("id", idMapping.getColumn().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", idMapping.getColumn().getSpecifiedName()); - assertEquals("foo", idMapping.getColumn().getName()); - assertEquals("id", idMapping.getColumn().getDefaultName()); - } - - public void testGetSequenceGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - assertEquals(0, idMapping.getPersistenceUnit().generatorsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - getJpaProject().synchronizeContextModel(); - attributeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - getJpaProject().synchronizeContextModel(); - assertNotNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - assertEquals(2, attributeResource.annotationsSize()); - assertEquals(1, idMapping.getPersistenceUnit().generatorsSize()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setName("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, idMapping.getPersistenceUnit().generatorsSize()); - } - - public void testAddSequenceGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - - idMapping.getGeneratorContainer().addSequenceGenerator(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNotNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - assertNotNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - idMapping.getGeneratorContainer().addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - - idMapping.getGeneratorContainer().removeSequenceGenerator(); - - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - assertNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - - //try removing the sequence generator again, should get an IllegalStateException - try { - idMapping.getGeneratorContainer().removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetTableGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(idMapping.getGeneratorContainer().getTableGenerator()); - assertEquals(0, idMapping.getPersistenceUnit().generatorsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.TABLE_GENERATOR); - getJpaProject().synchronizeContextModel(); - assertNotNull(idMapping.getGeneratorContainer().getTableGenerator()); - assertEquals(2, attributeResource.annotationsSize()); - assertEquals(1, idMapping.getPersistenceUnit().generatorsSize()); - - idMapping.getGeneratorContainer().getTableGenerator().setName("foo"); - assertEquals(1, idMapping.getPersistenceUnit().generatorsSize()); - } - - public void testAddTableGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator()); - - idMapping.getGeneratorContainer().addTableGenerator(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNotNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - assertNotNull(idMapping.getGeneratorContainer().getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - idMapping.getGeneratorContainer().addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.TABLE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - - idMapping.getGeneratorContainer().removeTableGenerator(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator()); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - - //try removing the table generator again, should get an IllegalStateException - try { - idMapping.getGeneratorContainer().removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetGeneratedValue() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getGeneratedValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.GENERATED_VALUE); - getJpaProject().synchronizeContextModel(); - - assertNotNull(idMapping.getGeneratedValue()); - assertEquals(2, attributeResource.annotationsSize()); - } - - public void testGetGeneratedValue2() throws Exception { - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - createTestEntityWithIdMappingGeneratedValue(); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNotNull(idMapping.getGeneratedValue()); - assertEquals(2, attributeResource.annotationsSize()); - } - - public void testAddGeneratedValue() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getGeneratedValue()); - - idMapping.addGeneratedValue(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNotNull(attributeResource.getAnnotation(JPA.GENERATED_VALUE)); - assertNotNull(idMapping.getGeneratedValue()); - - //try adding another generated value, should get an IllegalStateException - try { - idMapping.addGeneratedValue(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveGeneratedValue() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.GENERATED_VALUE); - getJpaProject().synchronizeContextModel(); - - idMapping.removeGeneratedValue(); - - assertNull(idMapping.getGeneratedValue()); - assertNull(attributeResource.getAnnotation(JPA.GENERATED_VALUE)); - - //try removing the generatedValue again, should get an IllegalStateException - try { - idMapping.removeGeneratedValue(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinColumnTests.java deleted file mode 100644 index 3d6bc5689d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinColumnTests.java +++ /dev/null @@ -1,547 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaJoinColumnTests extends ContextModelTestCase -{ - public JavaJoinColumnTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithOneToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidOneToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - sb.append(" private Project project;").append(CR); - } - }); - } - - private void createTargetEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Project {").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int proj_id;").append(CR); - sb.append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter); - } - - public void testUpdateSpecifiedName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set name in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("FOO", javaJoinColumn.getName()); - - //set name to null in the resource model, annotation removed, specified join column removed - javaJoinColumn.setName(null); - getJpaProject().synchronizeContextModel(); - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set name in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals("foo", joinColumn.getSpecifiedName()); - assertEquals("foo", javaJoinColumn.getName()); - - //set name to null in the context model - joinColumn.setSpecifiedName(null); - assertNull(joinColumn.getSpecifiedName()); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - // <attribute name>_<referenced column name> - // or - // <target entity name>_<referenced column name> - public void testDefaultName() throws Exception { - createTestEntityWithValidOneToOne(); - createTargetEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - -// JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); -// JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); -// JavaJoinColumn defaultJavaJoinColumn = joinColumns.getDefaultJoinColumn(); -// -// assertNull(defaultJavaJoinColumn.getDefaultName()); -//TODO test default join column name -// //add target entity to the persistence unit, now join table name is [table name]_[target table name] -// addXmlClassRef(PACKAGE_NAME + ".Project"); -// assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); -// -// JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); -// JavaPersistentAttributeResource attributeResource = typeResource.attributes().next(); -// assertNull(attributeResource.annotation(JoinTable.ANNOTATION_NAME)); -// -// //target entity does not resolve, default name is null -// manyToManyMapping.setSpecifiedTargetEntity("Foo"); -// assertNull(joinTable.getDefaultName()); -// -// //default target entity does resolve, so default name is again [table name]_[target table name] -// manyToManyMapping.setSpecifiedTargetEntity(null); -// assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); -// -// //add the join table annotation, verify default join table name is the same -// attributeResource.addAnnotation(JoinTable.ANNOTATION_NAME); -// assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); -// assertNotNull(attributeResource.annotation(JoinTable.ANNOTATION_NAME)); -// -// //set a table on the target entity, very default join table name updates -// manyToManyMapping.getResolvedTargetEntity().getTable().setSpecifiedName("FOO"); -// assertEquals(TYPE_NAME + "_FOO", joinTable.getDefaultName()); -// -// //set a table on the owning entity, very default join table name updates -// javaEntity().getTable().setSpecifiedName("BAR"); -// assertEquals("BAR_FOO", joinTable.getDefaultName()); - } - - public void testUpdateSpecifiedReferencedColumnName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set referenced column name in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setReferencedColumnName("BAR"); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals("BAR", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("BAR", javaJoinColumn.getReferencedColumnName()); - - //set referenced column name to null in the resource model, - javaJoinColumn.setReferencedColumnName(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull("BAR", javaJoinColumn.getReferencedColumnName()); - } - - public void testModifySpecifiedReferencedColumnName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set referenced column name in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedReferencedColumnName("BAR"); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals("BAR", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("BAR", javaJoinColumn.getReferencedColumnName()); - - //set referenced column name to null in the context model - joinColumn.setSpecifiedReferencedColumnName(null); - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(javaJoinColumn.getReferencedColumnName()); - } - - public void testDefaultReferencedColumnName() throws Exception { - //TODO test default join column referenced column name - - } - - public void testUpdateTable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set table in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setTable("BAR"); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals("BAR", joinColumn.getSpecifiedTable()); - assertEquals("BAR", javaJoinColumn.getTable()); - - //set table to null in the resource model, - javaJoinColumn.setTable(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedTable()); - assertNull("BAR", javaJoinColumn.getTable()); - } - - public void testModifyTable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set table in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedTable("BAR"); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals("BAR", joinColumn.getSpecifiedTable()); - assertEquals("BAR", javaJoinColumn.getTable()); - - //set table to null in the context model - joinColumn.setSpecifiedTable(null); - assertNull(joinColumn.getSpecifiedTable()); - assertNull(javaJoinColumn.getTable()); - } - - public void testDefaultTable() throws Exception { - //TODO test default join column table - - } - - public void testUpdateUnique() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set unique in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setUnique(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals(Boolean.TRUE, joinColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, javaJoinColumn.getUnique()); - - //set unique to null in the resource model, - javaJoinColumn.setUnique(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedUnique()); - assertNull(javaJoinColumn.getUnique()); - } - - public void testModifyUnique() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set unique in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.TRUE, joinColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, javaJoinColumn.getUnique()); - - //set unique to null in the context model - joinColumn.setSpecifiedUnique(null); - assertNull(joinColumn.getSpecifiedUnique()); - assertNull(javaJoinColumn.getUnique()); - } - - public void testUpdateNullable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set nullable in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setNullable(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getNullable()); - - //set nullable to null in the resource model, - javaJoinColumn.setNullable(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedNullable()); - assertNull(javaJoinColumn.getNullable()); - } - - public void testModifyNullable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set nullable in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getNullable()); - - //set nullable to null in the context model - joinColumn.setSpecifiedNullable(null); - assertNull(joinColumn.getSpecifiedNullable()); - assertNull(javaJoinColumn.getNullable()); - } - - public void testUpdateInsertable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set insertable in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setInsertable(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getInsertable()); - - //set insertable to null in the resource model, - javaJoinColumn.setInsertable(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedInsertable()); - assertNull(javaJoinColumn.getInsertable()); - } - - public void testModifyInsertable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set insertable in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getInsertable()); - - //set insertable to null in the context model - joinColumn.setSpecifiedInsertable(null); - assertNull(joinColumn.getSpecifiedInsertable()); - assertNull(javaJoinColumn.getInsertable()); - } - - public void testUpdateUpdatable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set updatable in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setUpdatable(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getUpdatable()); - - //set updatable to null in the resource model, - javaJoinColumn.setUpdatable(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedUpdatable()); - assertNull(javaJoinColumn.getUpdatable()); - } - - public void testModifyUpdatable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set updatable in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getUpdatable()); - - //set updatable to null in the context model - joinColumn.setSpecifiedUpdatable(null); - assertNull(joinColumn.getSpecifiedUpdatable()); - assertNull(javaJoinColumn.getUpdatable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinTableTests.java deleted file mode 100644 index 2b49da9e61..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinTableTests.java +++ /dev/null @@ -1,1163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaJoinTableTests extends ContextModelTestCase -{ - public JavaJoinTableTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany").append(CR); - sb.append(" private Collection<Project> projects;").append(CR); - } - }); - } - - private void createTargetEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Project {").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int proj_id;").append(CR); - sb.append(CR); - sb.append("}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter); - } - - private void createTargetEntityWithBackPointer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Project {").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int proj_id;").append(CR); - sb.append(" @ManyToMany(mappedBy=\"projects\"").append(CR); - sb.append(" private java.util.Collection<" + TYPE_NAME + "> employees;").append(CR); - sb.append(CR); - sb.append("}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter); - } - - public void testUpdateSpecifiedName() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedName()); - assertNull(javaJoinTable); - - - //set name in the resource model, verify context model updated - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedName()); - assertEquals("FOO", javaJoinTable.getName()); - - //set name to null in the resource model - javaJoinTable.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedName()); - assertNull(javaJoinTable.getName()); - - javaJoinTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedName()); - assertEquals("FOO", javaJoinTable.getName()); - - attributeResource.removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedName()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedName() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedName()); - assertNull(javaJoinTable); - - //set name in the context model, verify resource model modified - joinTable.setSpecifiedName("foo"); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals("foo", joinTable.getSpecifiedName()); - assertEquals("foo", javaJoinTable.getName()); - - //set name to null in the context model - joinTable.setSpecifiedName(null); - assertNull(joinTable.getSpecifiedName()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultName() throws Exception { - createTestEntityWithValidManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - //joinTable default name is null because targetEntity is not in the persistence unit - assertNull(joinTable.getDefaultName()); - - //add target entity to the persistence unit, now join table name is [table name]_[target table name] - createTargetEntity(); - addXmlClassRef(PACKAGE_NAME + ".Project"); - assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - - //target entity does not resolve, default name is null - manyToManyMapping.setSpecifiedTargetEntity("Foo"); - assertNull(joinTable.getDefaultName()); - - //default target entity does resolve, so default name is again [table name]_[target table name] - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); - - //add the join table annotation, verify default join table name is the same - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - - //set a table on the target entity, very default join table name updates - manyToManyMapping.getResolvedTargetEntity().getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_FOO", joinTable.getDefaultName()); - - //set a table on the owning entity, very default join table name updates - getJavaEntity().getTable().setSpecifiedName("BAR"); - assertEquals("BAR_FOO", joinTable.getDefaultName()); - } - - public void testDefaultJoinColumns() throws Exception { - createTestEntityWithValidManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - JoinColumn joinColumn = joinTable.joinColumns().next(); - JoinColumn inverseJoinColumn = joinTable.inverseJoinColumns().next(); - - //joinTable default name is null because targetEntity is not in the persistence unit - assertNull(joinColumn.getDefaultName()); - assertNull(joinColumn.getDefaultReferencedColumnName()); - assertNull(inverseJoinColumn.getDefaultName()); - assertNull(inverseJoinColumn.getDefaultReferencedColumnName()); - - //add target entity to the persistence unit, join column default name and referenced column still null because owning entity has no primary key - createTargetEntity(); - addXmlClassRef(PACKAGE_NAME + ".Project"); - assertNull(joinColumn.getDefaultName()); - assertNull(joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //create primary key in owning entity - getJavaPersistentType().getAttributeNamed("id").setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(TYPE_NAME + "_id", joinColumn.getDefaultName()); - assertEquals("id", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //set specified column name on primary key in owning entity - ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID"); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - - //target entity does not resolve, inverse join column name and referenced column name is null - manyToManyMapping.setSpecifiedTargetEntity("Foo"); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertNull(inverseJoinColumn.getDefaultName()); - assertNull(inverseJoinColumn.getDefaultReferencedColumnName()); - - //default target entity does resolve, so defaults for join column are back - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //add the join table annotation, verify default join table name is the same - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultJoinColumnsBidirectionalRelationship() throws Exception { - createTestEntityWithValidManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - JoinColumn joinColumn = joinTable.joinColumns().next(); - JoinColumn inverseJoinColumn = joinTable.inverseJoinColumns().next(); - - //joinTable default name is null because targetEntity is not in the persistence unit - assertNull(joinColumn.getDefaultName()); - assertNull(joinColumn.getDefaultReferencedColumnName()); - assertNull(inverseJoinColumn.getDefaultName()); - assertNull(inverseJoinColumn.getDefaultReferencedColumnName()); - - //add target entity to the persistence unit, join column default name and referenced column still null because owning entity has no primary key - createTargetEntityWithBackPointer(); - addXmlClassRef(PACKAGE_NAME + ".Project"); - assertNull(joinColumn.getDefaultName()); - assertNull(joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //create primary key in owning entity - getJavaPersistentType().getAttributeNamed("id").setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("employees_id", joinColumn.getDefaultName()); - assertEquals("id", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //set specified column name on primary key in owning entity - ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID"); - assertEquals("employees_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - - //target entity does not resolve, inverse join column name and referenced column name is null - manyToManyMapping.setSpecifiedTargetEntity("Foo"); - assertEquals(TYPE_NAME + "_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertNull(inverseJoinColumn.getDefaultName()); - assertNull(inverseJoinColumn.getDefaultReferencedColumnName()); - - //default target entity does resolve, so defaults for join column are back - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals("employees_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - - //add the join table annotation, verify default join table name is the same - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals("employees_MY_ID", joinColumn.getDefaultName()); - assertEquals("MY_ID", joinColumn.getDefaultReferencedColumnName()); - assertEquals("projects_proj_id", inverseJoinColumn.getDefaultName()); - assertEquals("proj_id", inverseJoinColumn.getDefaultReferencedColumnName()); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedSchema() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedSchema()); - assertNull(javaJoinTable); - - - //set schema in the resource model, verify context model updated - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable.setSchema("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedSchema()); - assertEquals("FOO", javaJoinTable.getSchema()); - - //set schema to null in the resource model - javaJoinTable.setSchema(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedSchema()); - assertNull(javaJoinTable.getSchema()); - - javaJoinTable.setSchema("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedSchema()); - assertEquals("FOO", javaJoinTable.getSchema()); - - attributeResource.removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedSchema()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedSchema() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedSchema()); - assertNull(javaJoinTable); - - //set schema in the context model, verify resource model modified - joinTable.setSpecifiedSchema("foo"); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals("foo", joinTable.getSpecifiedSchema()); - assertEquals("foo", javaJoinTable.getSchema()); - - //set schema to null in the context model - joinTable.setSpecifiedSchema(null); - assertNull(joinTable.getSpecifiedSchema()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(javaJoinTable); - - - //set catalog in the resource model, verify context model updated - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable.setCatalog("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedCatalog()); - assertEquals("FOO", javaJoinTable.getCatalog()); - - //set catalog to null in the resource model - javaJoinTable.setCatalog(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(javaJoinTable.getCatalog()); - - javaJoinTable.setCatalog("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedCatalog()); - assertEquals("FOO", javaJoinTable.getCatalog()); - - attributeResource.removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedCatalog() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(javaJoinTable); - - //set catalog in the context model, verify resource model modified - joinTable.setSpecifiedCatalog("foo"); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals("foo", joinTable.getSpecifiedCatalog()); - assertEquals("foo", javaJoinTable.getCatalog()); - - //set catalog to null in the context model - joinTable.setSpecifiedCatalog(null); - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JoinColumn joinColumn = joinTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", joinTableResource.joinColumnAt(0).getName()); - - JoinColumn joinColumn2 = joinTable.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(1).getName()); - - JoinColumn joinColumn3 = joinTable.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - - ListIterator<JoinColumn> joinColumns = joinTable.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - joinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.joinColumnsSize()); - - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(2, joinTableResource.joinColumnsSize()); - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(1, joinTableResource.joinColumnsSize()); - assertEquals("BAZ", joinTableResource.joinColumnAt(0).getName()); - - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(0, joinTableResource.joinColumnsSize()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - joinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.joinColumnsSize()); - - - joinTable.moveSpecifiedJoinColumn(2, 0); - ListIterator<JoinColumn> joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - - - joinTable.moveSpecifiedJoinColumn(0, 1); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAR", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - joinTableResource.addJoinColumn(0); - joinTableResource.addJoinColumn(1); - joinTableResource.addJoinColumn(2); - - joinTableResource.joinColumnAt(0).setName("FOO"); - joinTableResource.joinColumnAt(1).setName("BAR"); - joinTableResource.joinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<JoinColumn> joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.moveJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.moveJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(joinTable.specifiedJoinColumns().hasNext()); - } - - public void testSpecifiedJoinColumnsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - assertEquals(0, joinTable.specifiedJoinColumnsSize()); - - joinTable.addSpecifiedJoinColumn(0); - assertEquals(1, joinTable.specifiedJoinColumnsSize()); - - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(0, joinTable.specifiedJoinColumnsSize()); - } - - public void testJoinColumnsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - assertEquals(1, joinTable.joinColumnsSize()); - - joinTable.addSpecifiedJoinColumn(0); - assertEquals(1, joinTable.joinColumnsSize()); - - joinTable.addSpecifiedJoinColumn(0); - assertEquals(2, joinTable.joinColumnsSize()); - - joinTable.removeSpecifiedJoinColumn(0); - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(1, joinTable.joinColumnsSize()); - - //if non-owning side of the relationship then no default join table - manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().setMappedByAttribute("foo"); - assertNull(manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable()); - } - - public void testAddSpecifiedInverseJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JoinColumn inverseJoinColumn = joinTable.addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("FOO"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(0).getName()); - - JoinColumn inverseJoinColumn2 = joinTable.addSpecifiedInverseJoinColumn(0); - inverseJoinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(1).getName()); - - JoinColumn inverseJoinColumn3 = joinTable.addSpecifiedInverseJoinColumn(1); - inverseJoinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(2).getName()); - - ListIterator<JoinColumn> inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals(inverseJoinColumn2, inverseJoinColumns.next()); - assertEquals(inverseJoinColumn3, inverseJoinColumns.next()); - assertEquals(inverseJoinColumn, inverseJoinColumns.next()); - - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - } - - public void testRemoveSpecifiedInverseJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - joinTable.addSpecifiedInverseJoinColumn(0).setSpecifiedName("FOO"); - joinTable.addSpecifiedInverseJoinColumn(1).setSpecifiedName("BAR"); - joinTable.addSpecifiedInverseJoinColumn(2).setSpecifiedName("BAZ"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.inverseJoinColumnsSize()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(2, joinTableResource.inverseJoinColumnsSize()); - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(1).getName()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTableResource.inverseJoinColumnsSize()); - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(0).getName()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(0, joinTableResource.inverseJoinColumnsSize()); - } - - public void testMoveSpecifiedInverseJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - joinTable.addSpecifiedInverseJoinColumn(0).setSpecifiedName("FOO"); - joinTable.addSpecifiedInverseJoinColumn(1).setSpecifiedName("BAR"); - joinTable.addSpecifiedInverseJoinColumn(2).setSpecifiedName("BAZ"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.inverseJoinColumnsSize()); - - - joinTable.moveSpecifiedInverseJoinColumn(2, 0); - ListIterator<JoinColumn> inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(2).getName()); - - - joinTable.moveSpecifiedInverseJoinColumn(0, 1); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(2).getName()); - } - - public void testUpdateInverseJoinColumns() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - joinTableResource.addInverseJoinColumn(0); - joinTableResource.addInverseJoinColumn(1); - joinTableResource.addInverseJoinColumn(2); - - joinTableResource.inverseJoinColumnAt(0).setName("FOO"); - joinTableResource.inverseJoinColumnAt(1).setName("BAR"); - joinTableResource.inverseJoinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<JoinColumn> inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.moveInverseJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.moveInverseJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.removeInverseJoinColumn(1); - getJpaProject().synchronizeContextModel(); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.removeInverseJoinColumn(1); - getJpaProject().synchronizeContextModel(); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.removeInverseJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(joinTable.specifiedInverseJoinColumns().hasNext()); - } - - public void testGetDefaultInverseJoinColumn() { - //TODO - } - - public void testSpecifiedInverseJoinColumnsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - assertEquals(0, joinTable.specifiedInverseJoinColumnsSize()); - - joinTable.addSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTable.specifiedInverseJoinColumnsSize()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(0, joinTable.specifiedInverseJoinColumnsSize()); - } - - public void testInverseJoinColumnsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - assertEquals(1, joinTable.inverseJoinColumnsSize()); - - joinTable.addSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTable.inverseJoinColumnsSize()); - - joinTable.addSpecifiedInverseJoinColumn(0); - assertEquals(2, joinTable.inverseJoinColumnsSize()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTable.inverseJoinColumnsSize()); - - //if non-owning side of the relationship then no default join table - manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().setMappedByAttribute("foo"); - assertNull(manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable()); - } - - public void testUniqueConstraints() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - ListIterator<JavaUniqueConstraint> uniqueConstraints = joinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - getJpaProject().synchronizeContextModel(); - - uniqueConstraints = joinTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - assertEquals(0, joinTable.uniqueConstraintsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - joinTableAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - getJpaProject().synchronizeContextModel(); - assertEquals(2, joinTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - joinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - joinTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - joinTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = joinTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - joinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - joinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - joinTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = joinTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - joinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - joinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - joinTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertEquals(3, joinTableAnnotation.uniqueConstraintsSize()); - - joinTable.removeUniqueConstraint(1); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator<UniqueConstraint> uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - joinTable.removeUniqueConstraint(1); - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - joinTable.removeUniqueConstraint(0); - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = joinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - joinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - joinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - joinTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertEquals(3, joinTableAnnotation.uniqueConstraintsSize()); - - - joinTable.moveUniqueConstraint(2, 0); - ListIterator<UniqueConstraint> uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - joinTable.moveUniqueConstraint(0, 1); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - joinTableAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - joinTableAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - joinTableAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<UniqueConstraint> uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.moveUniqueConstraint(2, 0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.moveUniqueConstraint(0, 1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = joinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java deleted file mode 100644 index 7b5cfa2b5a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java +++ /dev/null @@ -1,1176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToManyRelationshipReference; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OrderByAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaManyToManyMappingTests extends ContextModelTestCase -{ - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Collection<Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithCollectionManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithNonCollectionManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Address addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map<String, Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapManyToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestDepartment() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("import java.util.Map;"); - sb.append(CR); - sb.append("import ").append(JPA.MANY_TO_MANY).append(";"); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Department").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Map<Integer, Employee> employees;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Department.java", sourceWriter); - } - - private void createTestEmployee() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Employee").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int empId;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Employee.java", sourceWriter); - } - - public JavaManyToManyMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertNull(persistentAttribute.getSpecifiedMapping()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME); - - assertNull(manyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - manyToMany.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", manyToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToMany.getTargetEntity()); - - //set target entity to null in the resource model - manyToMany.setTargetEntity(null); - assertNull(manyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME); - - assertNull(manyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - manyToManyMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", manyToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToMany.getTargetEntity()); - - //set target entity to null in the context model - manyToManyMapping.setSpecifiedTargetEntity(null); - assertNull(manyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME); - - assertNull(manyToManyMapping.getSpecifiedFetch()); - assertNull(manyToMany.getFetch()); - - //set fetch in the resource model, verify context model updated - manyToMany.setFetch(org.eclipse.jpt.core.resource.java.FetchType.EAGER); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.EAGER, manyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, manyToMany.getFetch()); - - manyToMany.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.LAZY, manyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, manyToMany.getFetch()); - - - //set fetch to null in the resource model - manyToMany.setFetch(null); - getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getSpecifiedFetch()); - assertNull(manyToMany.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME); - - assertNull(manyToManyMapping.getSpecifiedFetch()); - assertNull(manyToMany.getFetch()); - - //set fetch in the context model, verify resource model updated - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(FetchType.EAGER, manyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, manyToMany.getFetch()); - - manyToManyMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, manyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, manyToMany.getFetch()); - - //set fetch to null in the context model - manyToManyMapping.setSpecifiedFetch(null); - assertNull(manyToManyMapping.getSpecifiedFetch()); - assertNull(manyToMany.getFetch()); - } - - public void testUpdateMappedBy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME); - - assertNull(manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute()); - assertNull(manyToMany.getMappedBy()); - - //set mappedByJoiningStrategy in the resource model, verify context model updated - manyToMany.setMappedBy("newMappedBy"); - getJpaProject().synchronizeContextModel(); - assertEquals("newMappedBy", manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute()); - assertEquals("newMappedBy", manyToMany.getMappedBy()); - - //set mappedByJoiningStrategy to null in the resource model - manyToMany.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute()); - assertNull(manyToMany.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME); - - assertNull(manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute()); - assertNull(manyToMany.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().setMappedByAttribute("newTargetEntity"); - assertEquals("newTargetEntity", manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute()); - assertEquals("newTargetEntity", manyToMany.getMappedBy()); - - //set mappedBy to null in the context model - manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().setMappedByAttribute(null); - assertNull(manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute()); - assertNull(manyToMany.getMappedBy()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - ManyToManyAnnotation annotation = (ManyToManyAnnotation) resourceAttribute.getAnnotation(JPA.MANY_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping mapping = (ManyToManyMapping) contextAttribute.getMapping(); - ManyToManyRelationshipReference relationshipReference = mapping.getRelationshipReference(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - - relationshipReference.setMappedByJoiningStrategy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); - assertTrue(relationshipReference.usesMappedByJoiningStrategy()); - - relationshipReference.setJoinTableJoiningStrategy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - ManyToManyAnnotation annotation = (ManyToManyAnnotation) resourceAttribute.getAnnotation(JPA.MANY_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping mapping = (ManyToManyMapping) contextAttribute.getMapping(); - ManyToManyRelationshipReference relationshipReference = mapping.getRelationshipReference(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - - annotation.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); - assertTrue(relationshipReference.usesMappedByJoiningStrategy()); - - resourceAttribute.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); - assertTrue(relationshipReference.usesMappedByJoiningStrategy()); - - annotation.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - - resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - manyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = manyToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertNull(stateFooMapping); - } - - public void testDefaultTargetEntity() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getDefaultTargetEntity()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getDefaultTargetEntity()); - - //test default still the same when specified target entity it set - manyToManyMapping.setSpecifiedTargetEntity("foo"); - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getDefaultTargetEntity()); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Entity, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityCollectionType() throws Exception { - createTestEntityWithCollectionManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityNonCollectionType() throws Exception { - createTestEntityWithNonCollectionManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getDefaultTargetEntity()); - } - - public void testTargetEntity() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getTargetEntity()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - assertEquals("foo", manyToManyMapping.getTargetEntity()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getTargetEntity()); - } - - public void testResolvedTargetEntity() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit - assertNull(manyToManyMapping.getResolvedTargetEntity()); - - //add targetEntity to the persistence unit, now target entity should resolve - createTestTargetEntityAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, manyToManyMapping.getResolvedTargetEntity()); - - //test default still the same when specified target entity it set - manyToManyMapping.setSpecifiedTargetEntity("foo"); - assertNull(manyToManyMapping.getResolvedTargetEntity()); - - - manyToManyMapping.setSpecifiedTargetEntity(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, manyToManyMapping.getResolvedTargetEntity()); - - - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(addressTypeMapping, manyToManyMapping.getResolvedTargetEntity()); - } - - - public void testUpdateMapKey() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - getJpaProject().synchronizeContextModel(); - assertEquals("myMapKey", manyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - attributeResource.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - manyToManyMapping.setSpecifiedMapKey("myMapKey"); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", manyToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey to null in the context model - manyToManyMapping.setSpecifiedMapKey(null); - assertNull(manyToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator<String> mapKeyNames = - javaManyToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapManyToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator<String> mapKeyNames = javaManyToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaManyToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = javaManyToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - public void testUpdateOrderBy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertEquals("newOrderBy", manyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertEquals("newOrderBy", orderBy.getValue()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(manyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testModifyOrderBy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(manyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set mappedBy in the context model, verify resource model updated - manyToManyMapping.getOrderable().setSpecifiedOrderBy("newOrderBy"); - assertEquals("newOrderBy", manyToManyMapping.getOrderable().getSpecifiedOrderBy()); - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertEquals("newOrderBy", orderBy.getValue()); - - //set mappedBy to null in the context model - manyToManyMapping.getOrderable().setSpecifiedOrderBy(null); - assertNull(manyToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateNoOrdering() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertTrue(manyToManyMapping.getOrderable().isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertFalse(manyToManyMapping.getOrderable().isNoOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertFalse(manyToManyMapping.getOrderable().isNoOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertTrue(manyToManyMapping.getOrderable().isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testModifyNoOrdering() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertTrue(manyToManyMapping.getOrderable().isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - -// manyToManyMapping.setNoOrdering(false); //this does nothing -// //set mappedBy in the context model, verify resource model updated -// manyToManyMapping.setOrderBy("newOrderBy"); -// assertEquals("newOrderBy", manyToManyMapping.getOrderBy()); -// OrderBy orderBy = (OrderBy) attributeResource.annotation(OrderBy.ANNOTATION_NAME); -// assertEquals("newOrderBy", orderBy.getValue()); -// -// //set mappedBy to null in the context model -// manyToManyMapping.setOrderBy(null); -// assertNull(manyToManyMapping.getOrderBy()); -// assertNull(attributeResource.annotation(OrderBy.ANNOTATION_NAME)); - } - - public void testUpdatePkOrdering() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertFalse(manyToManyMapping.getOrderable().isPkOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertTrue(manyToManyMapping.getOrderable().isPkOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertFalse(manyToManyMapping.getOrderable().isPkOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertFalse(manyToManyMapping.getOrderable().isPkOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateCustomOrdering() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertFalse(manyToManyMapping.getOrderable().isCustomOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.getOrderable().isCustomOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertTrue(manyToManyMapping.getOrderable().isCustomOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertFalse(manyToManyMapping.getOrderable().isCustomOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultTargetEntityForMap() throws Exception { - createTestEmployee(); - createTestDepartment(); - addXmlClassRef(PACKAGE_NAME + ".Department"); - addXmlClassRef(PACKAGE_NAME + ".Employee"); - - JavaPersistentType departmentPersistentType = getJavaPersistentType(); - ManyToManyMapping employeesMapping = (ManyToManyMapping) departmentPersistentType.getAttributeNamed("employees").getSpecifiedMapping(); - assertEquals(PACKAGE_NAME + ".Employee", employeesMapping.getTargetEntity()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java deleted file mode 100644 index dfcac10aa7..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java +++ /dev/null @@ -1,959 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.ManyToOneRelationshipReference; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaManyToOneMappingTests extends ContextModelTestCase -{ - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithCollectionManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private Collection address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericizedCollectionManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private Collection<Address> address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - public JavaManyToOneMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertNull(persistentAttribute.getSpecifiedMapping()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME); - - assertNull(manyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - manyToOne.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", manyToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToOne.getTargetEntity()); - - //set target entity to null in the resource model - manyToOne.setTargetEntity(null); - assertNull(manyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME); - - assertNull(manyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - manyToOneMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", manyToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToOne.getTargetEntity()); - - //set target entity to null in the context model - manyToOneMapping.setSpecifiedTargetEntity(null); - assertNull(manyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - } - - public void testUpdateSpecifiedOptional() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME); - - assertNull(manyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOne.getOptional()); - - //set optional in the resource model, verify context model updated - manyToOne.setOptional(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, manyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - - manyToOne.setOptional(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.FALSE, manyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, manyToOne.getOptional()); - - //set optional to null in the resource model - manyToOne.setOptional(null); - getJpaProject().synchronizeContextModel(); - assertNull(manyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOne.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME); - - assertNull(manyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOne.getOptional()); - - //set optional in the context model, verify resource model updated - manyToOneMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, manyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - - manyToOneMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, manyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, manyToOne.getOptional()); - - - //set optional to null in the context model - manyToOneMapping.setSpecifiedOptional(null); - assertNull(manyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOne.getOptional()); - } - - - public void testSpecifiedJoinColumns() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - ListIterator<? extends JoinColumn> specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - - assertFalse(specifiedJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - JoinColumnAnnotation joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertFalse(specifiedJoinColumns.hasNext()); - } - - public void testGetDefaultJoin() { - //TODO - } - - public void testSpecifiedJoinColumnsSize() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - - joinColumns.addSpecifiedJoinColumn(0); - assertEquals(1, joinColumns.specifiedJoinColumnsSize()); - - joinColumns.removeSpecifiedJoinColumn(0); - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - } - - public void testJoinColumnsSize() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - assertEquals(1, joinColumns.joinColumnsSize()); - - joinColumns.addSpecifiedJoinColumn(0); - assertEquals(1, joinColumns.joinColumnsSize()); - - joinColumns.addSpecifiedJoinColumn(0); - assertEquals(2, joinColumns.joinColumnsSize()); - - joinColumns.removeSpecifiedJoinColumn(0); - joinColumns.removeSpecifiedJoinColumn(0); - assertEquals(1, joinColumns.joinColumnsSize()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> joinColumnsIterator = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testAddSpecifiedJoinColumn2() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> joinColumnsIterator = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertEquals(3, CollectionTools.size(attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME))); - - joinColumns.removeSpecifiedJoinColumn(1); - - Iterator<NestableAnnotation> joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - Iterator<? extends JoinColumn> joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - joinColumns.removeSpecifiedJoinColumn(1); - joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - joinColumns.removeSpecifiedJoinColumn(0); - joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertFalse(joinColumnResources.hasNext()); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertFalse(joinColumnsIterator.hasNext()); - - assertNull(attributeResource.getAnnotation(JoinColumnsAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentAttribute attributeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - Iterator<NestableAnnotation> javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaJoinColumns)); - - joinColumns.moveSpecifiedJoinColumn(2, 0); - ListIterator<? extends JoinColumn> primaryKeyJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - - - joinColumns.moveSpecifiedJoinColumn(0, 1); - primaryKeyJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - } - - public void testUpdateSpecifiedJoinColumns() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - JavaResourcePersistentAttribute attributeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - ((JoinColumnAnnotation) attributeResource.addAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((JoinColumnAnnotation) attributeResource.addAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((JoinColumnAnnotation) attributeResource.addAnnotation(2, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<? extends JoinColumn> joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.moveAnnotation(2, 0, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.moveAnnotation(0, 1, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.removeAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.removeAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.removeAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertFalse(joinColumnsIterator.hasNext()); - } - public void testJoinColumnIsVirtual() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = manyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - assertTrue(joinColumns.getDefaultJoinColumn().isVirtual()); - - joinColumns.addSpecifiedJoinColumn(0); - JoinColumn specifiedJoinColumn = joinColumns.specifiedJoinColumns().next(); - assertFalse(specifiedJoinColumn.isVirtual()); - - assertNull(joinColumns.getDefaultJoinColumn()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping mapping = (ManyToOneMapping) contextAttribute.getMapping(); - ManyToOneRelationshipReference relationshipReference = mapping.getRelationshipReference(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); - - relationshipReference.setJoinColumnJoiningStrategy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping mapping = (ManyToOneMapping) contextAttribute.getMapping(); - ManyToOneRelationshipReference relationshipReference = mapping.getRelationshipReference(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); - - resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); - - resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); - } - - public void testDefaultTargetEntity() throws Exception { - createTestEntityWithValidManyToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getDefaultTargetEntity()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getDefaultTargetEntity()); - - //test default still the same when specified target entity it set - manyToOneMapping.setSpecifiedTargetEntity("foo"); - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getDefaultTargetEntity()); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Entity, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityCollectionType() throws Exception { - createTestEntityWithCollectionManyToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - assertNull(manyToOneMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityGenericizedCollectionType() throws Exception { - createTestEntityWithGenericizedCollectionManyToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - assertNull(manyToOneMapping.getDefaultTargetEntity()); - } - - public void testTargetEntity() throws Exception { - createTestEntityWithValidManyToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getTargetEntity()); - - manyToOneMapping.setSpecifiedTargetEntity("foo"); - assertEquals("foo", manyToOneMapping.getTargetEntity()); - - manyToOneMapping.setSpecifiedTargetEntity(null); - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getTargetEntity()); - } - - public void testResolvedTargetEntity() throws Exception { - createTestEntityWithValidManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit - assertNull(manyToOneMapping.getResolvedTargetEntity()); - - //add targetEntity to the persistence unit, now target entity should resolve - createTestTargetEntityAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, manyToOneMapping.getResolvedTargetEntity()); - - //test default still the same when specified target entity it set - manyToOneMapping.setSpecifiedTargetEntity("foo"); - assertNull(manyToOneMapping.getResolvedTargetEntity()); - - - manyToOneMapping.setSpecifiedTargetEntity(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, manyToOneMapping.getResolvedTargetEntity()); - - - manyToOneMapping.setSpecifiedTargetEntity(null); - assertEquals(addressTypeMapping, manyToOneMapping.getResolvedTargetEntity()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaMappedSuperclassTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaMappedSuperclassTests.java deleted file mode 100644 index dc16827d7e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaMappedSuperclassTests.java +++ /dev/null @@ -1,283 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.IdClassReference; -import org.eclipse.jpt.core.context.MappedSuperclass; -import org.eclipse.jpt.core.internal.context.java.JavaNullTypeMapping; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaMappedSuperclassTests extends ContextModelTestCase -{ - public JavaMappedSuperclassTests(String name) { - super(name); - } - - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - }); - } - - private void createTestIdClass() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append("TestTypeId").append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "TestTypeId.java", sourceWriter); - } - - public void testMorphToEntity() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - mappedSuperclass.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - - getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof Entity); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(MappedSuperclassAnnotation.ANNOTATION_NAME)); - assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddable() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - mappedSuperclass.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - - getJavaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof Embeddable); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(MappedSuperclassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToNull() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - mappedSuperclass.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof JavaNullTypeMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(MappedSuperclassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - } - - public void testMappedSuperclass() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(getJavaPersistentType().getMapping() instanceof MappedSuperclass); - } - - public void testOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - Iterator<String> overridableAttributeNames = mappedSuperclass.overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - Iterator<String> overridableAssociationNames = mappedSuperclass.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testTableNameIsInvalid() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - assertFalse(mappedSuperclass.tableNameIsInvalid(FULLY_QUALIFIED_TYPE_NAME)); - assertFalse(mappedSuperclass.tableNameIsInvalid("FOO")); - } - - public void testAssociatedTables() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - assertFalse(mappedSuperclass.associatedTables().hasNext()); - } - - public void testAssociatedTablesIncludingInherited() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - assertFalse(mappedSuperclass.associatedTablesIncludingInherited().hasNext()); - } - - public void testAssociatedTableNamesIncludingInherited() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - assertFalse(mappedSuperclass.associatedTableNamesIncludingInherited().hasNext()); - } - - public void testAllOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - Iterator<String> overridableAttributeNames = mappedSuperclass.overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - //TODO need to create a subclass mappedSuperclass and test this - public void testAllOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - Iterator<String> overridableAssociationNames = mappedSuperclass.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - public void testUpdateIdClass() throws Exception { - createTestMappedSuperclass(); - createTestIdClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - IdClassReference idClassRef = mappedSuperclass.getIdClassReference(); - - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - // test setting id class name to nonexistent class. test class name is set, but class is null - String nonExistentIdClassName = PACKAGE_NAME + ".Foo"; - idClass.setValue(nonExistentIdClassName); - assertEquals(nonExistentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(nonExistentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - // test setting id class name to existent class. test class name is set and class is not null - String existentIdClassName = PACKAGE_NAME + ".TestTypeId"; - idClass.setValue(existentIdClassName); - assertEquals(existentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(existentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNotNull(idClassRef.getIdClass()); - - //test setting @IdClass value to null, IdClass annotation is removed - idClass.setValue(null); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - //reset @IdClass value and then remove @IdClass - idClass = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - idClass.setValue(existentIdClassName); - typeResource.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - } - - public void testModifyIdClass() throws Exception { - createTestMappedSuperclass(); - createTestIdClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - IdClassReference idClassRef = mappedSuperclass.getIdClassReference(); - - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - String nonExistentIdClassName = PACKAGE_NAME + ".Foo"; - idClassRef.setSpecifiedIdClassName(nonExistentIdClassName); - assertEquals(nonExistentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(nonExistentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - - String existentIdClassName = PACKAGE_NAME + ".TestTypeId"; - idClassRef.setSpecifiedIdClassName(existentIdClassName); - assertEquals(existentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(existentIdClassName, idClassRef.getSpecifiedIdClassName()); - assertNotNull(idClassRef.getIdClass()); - - idClassRef.setSpecifiedIdClassName(null); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(idClassRef.getSpecifiedIdClassName()); - assertNull(idClassRef.getIdClass()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedNativeQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedNativeQueryTests.java deleted file mode 100644 index 38a43a72e1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedNativeQueryTests.java +++ /dev/null @@ -1,434 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaNamedNativeQueryTests extends ContextModelTestCase -{ - private static final String QUERY_NAME = "QUERY_NAME"; - private static final String QUERY_QUERY = "MY_QUERY"; - - private ICompilationUnit createTestEntityWithNamedNativeQuery() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@NamedNativeQuery(name=\"" + QUERY_NAME + "\", query=\"" + QUERY_QUERY + "\")"); - } - }); - } - - - - public JavaNamedNativeQueryTests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_NAME, javaNamedNativeQuery.getName()); - assertEquals(QUERY_NAME, namedNativeQuery.getName()); - - //set name to null in the resource model - javaNamedNativeQuery.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(javaNamedNativeQuery.getName()); - assertNull(namedNativeQuery.getName()); - - //set name in the resource model, verify context model updated - javaNamedNativeQuery.setName("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", javaNamedNativeQuery.getName()); - assertEquals("foo", namedNativeQuery.getName()); - } - - public void testModifyName() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_NAME, javaNamedNativeQuery.getName()); - assertEquals(QUERY_NAME, namedNativeQuery.getName()); - - //set name to null in the context model - namedNativeQuery.setName(null); - assertNull(javaNamedNativeQuery.getName()); - assertNull(namedNativeQuery.getName()); - - //set name in the context model, verify resource model updated - namedNativeQuery.setName("foo"); - assertEquals("foo", javaNamedNativeQuery.getName()); - assertEquals("foo", namedNativeQuery.getName()); - } - - public void testUpdateQuery() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_QUERY, javaNamedNativeQuery.getQuery()); - assertEquals(QUERY_QUERY, namedNativeQuery.getQuery()); - - //set name to null in the resource model - javaNamedNativeQuery.setQuery(null); - getJpaProject().synchronizeContextModel(); - assertNull(javaNamedNativeQuery.getQuery()); - assertNull(namedNativeQuery.getQuery()); - - //set name in the resource model, verify context model updated - javaNamedNativeQuery.setQuery("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", javaNamedNativeQuery.getQuery()); - assertEquals("foo", namedNativeQuery.getQuery()); - } - - public void testModifyQuery() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_QUERY, javaNamedNativeQuery.getQuery()); - assertEquals(QUERY_QUERY, namedNativeQuery.getQuery()); - - //set name to null in the context model - namedNativeQuery.setQuery(null); - assertNull(javaNamedNativeQuery.getQuery()); - assertNull(namedNativeQuery.getQuery()); - - //set name in the context model, verify resource model updated - namedNativeQuery.setQuery("foo"); - assertEquals("foo", javaNamedNativeQuery.getQuery()); - assertEquals("foo", namedNativeQuery.getQuery()); - } - - - public void testAddHint() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - - QueryHint queryHint = namedNativeQuery.addHint(0); - queryHint.setName("FOO"); - - assertEquals("FOO", javaNamedNativeQuery.hintAt(0).getName()); - - QueryHint queryHint2 = namedNativeQuery.addHint(0); - queryHint2.setName("BAR"); - - assertEquals("BAR", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("FOO", javaNamedNativeQuery.hintAt(1).getName()); - - QueryHint queryHint3 = namedNativeQuery.addHint(1); - queryHint3.setName("BAZ"); - - assertEquals("BAR", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedNativeQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedNativeQuery.hintAt(2).getName()); - - ListIterator<QueryHint> hints = namedNativeQuery.hints(); - assertEquals(queryHint2, hints.next()); - assertEquals(queryHint3, hints.next()); - assertEquals(queryHint, hints.next()); - - hints = namedNativeQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - } - - public void testRemoveHint() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - namedNativeQuery.addHint(0).setName("FOO"); - namedNativeQuery.addHint(1).setName("BAR"); - namedNativeQuery.addHint(2).setName("BAZ"); - - assertEquals(3, javaNamedNativeQuery.hintsSize()); - - namedNativeQuery.removeHint(0); - assertEquals(2, javaNamedNativeQuery.hintsSize()); - assertEquals("BAR", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedNativeQuery.hintAt(1).getName()); - - namedNativeQuery.removeHint(0); - assertEquals(1, javaNamedNativeQuery.hintsSize()); - assertEquals("BAZ", javaNamedNativeQuery.hintAt(0).getName()); - - namedNativeQuery.removeHint(0); - assertEquals(0, javaNamedNativeQuery.hintsSize()); - } - - public void testMoveHint() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - namedNativeQuery.addHint(0).setName("FOO"); - namedNativeQuery.addHint(1).setName("BAR"); - namedNativeQuery.addHint(2).setName("BAZ"); - - assertEquals(3, javaNamedNativeQuery.hintsSize()); - - - namedNativeQuery.moveHint(2, 0); - ListIterator<QueryHint> hints = namedNativeQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAR", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedNativeQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedNativeQuery.hintAt(2).getName()); - - - namedNativeQuery.moveHint(0, 1); - hints = namedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAZ", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("BAR", javaNamedNativeQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedNativeQuery.hintAt(2).getName()); - } - - public void testUpdateHints() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - javaNamedNativeQuery.addHint(0); - javaNamedNativeQuery.addHint(1); - javaNamedNativeQuery.addHint(2); - - javaNamedNativeQuery.hintAt(0).setName("FOO"); - javaNamedNativeQuery.hintAt(1).setName("BAR"); - javaNamedNativeQuery.hintAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<QueryHint> hints = namedNativeQuery.hints(); - assertEquals("FOO", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedNativeQuery.moveHint(2, 0); - getJpaProject().synchronizeContextModel(); - hints = namedNativeQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedNativeQuery.moveHint(0, 1); - getJpaProject().synchronizeContextModel(); - hints = namedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedNativeQuery.removeHint(1); - getJpaProject().synchronizeContextModel(); - hints = namedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedNativeQuery.removeHint(1); - getJpaProject().synchronizeContextModel(); - hints = namedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedNativeQuery.removeHint(0); - getJpaProject().synchronizeContextModel(); - assertFalse(namedNativeQuery.hints().hasNext()); - } - - public void testHintsSize() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - assertEquals(0, namedNativeQuery.hintsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - - javaNamedNativeQuery.addHint(0); - getJpaProject().synchronizeContextModel(); - assertEquals(1, namedNativeQuery.hintsSize()); - - javaNamedNativeQuery.addHint(0); - getJpaProject().synchronizeContextModel(); - assertEquals(2, namedNativeQuery.hintsSize()); - - javaNamedNativeQuery.removeHint(0); - javaNamedNativeQuery.removeHint(0); - getJpaProject().synchronizeContextModel(); - assertEquals(0, namedNativeQuery.hintsSize()); - } - - public void testUpdateResultClass() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(null, javaNamedNativeQuery.getResultClass()); - assertEquals(null, namedNativeQuery.getResultClass()); - - //set name in the resource model, verify context model updated - javaNamedNativeQuery.setResultClass("foo"); - assertEquals("foo", javaNamedNativeQuery.getResultClass()); - assertEquals("foo", namedNativeQuery.getResultClass()); - - //set name to null in the resource model - javaNamedNativeQuery.setResultClass(null); - assertNull(javaNamedNativeQuery.getResultClass()); - assertNull(namedNativeQuery.getResultClass()); - } - - public void testModifyResultClass() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(null, javaNamedNativeQuery.getResultClass()); - assertEquals(null, namedNativeQuery.getResultClass()); - - //set name in the context model, verify resource model updated - namedNativeQuery.setResultClass("foo"); - assertEquals("foo", javaNamedNativeQuery.getResultClass()); - assertEquals("foo", namedNativeQuery.getResultClass()); - - //set name to null in the context model - namedNativeQuery.setResultClass(null); - assertNull(javaNamedNativeQuery.getResultClass()); - assertNull(namedNativeQuery.getResultClass()); - } - - public void testUpdateResultSetMapping() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(null, javaNamedNativeQuery.getResultSetMapping()); - assertEquals(null, namedNativeQuery.getResultSetMapping()); - - //set name in the resource model, verify context model updated - javaNamedNativeQuery.setResultSetMapping("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", javaNamedNativeQuery.getResultSetMapping()); - assertEquals("foo", namedNativeQuery.getResultSetMapping()); - - //set name to null in the resource model - javaNamedNativeQuery.setResultSetMapping(null); - getJpaProject().synchronizeContextModel(); - assertNull(javaNamedNativeQuery.getResultSetMapping()); - assertNull(namedNativeQuery.getResultSetMapping()); - } - - public void testModifyResultSetMapping() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(null, javaNamedNativeQuery.getResultSetMapping()); - assertEquals(null, namedNativeQuery.getResultSetMapping()); - - //set name in the context model, verify resource model updated - namedNativeQuery.setResultSetMapping("foo"); - assertEquals("foo", javaNamedNativeQuery.getResultSetMapping()); - assertEquals("foo", namedNativeQuery.getResultSetMapping()); - - //set name to null in the context model - namedNativeQuery.setResultSetMapping(null); - assertNull(javaNamedNativeQuery.getResultSetMapping()); - assertNull(namedNativeQuery.getResultSetMapping()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedQueryTests.java deleted file mode 100644 index 56198df7db..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedQueryTests.java +++ /dev/null @@ -1,337 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaNamedQueryTests extends ContextModelTestCase -{ - private static final String QUERY_NAME = "QUERY_NAME"; - private static final String QUERY_QUERY = "MY_QUERY"; - - private ICompilationUnit createTestEntityWithNamedQuery() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.NAMED_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@NamedQuery(name=\"" + QUERY_NAME + "\", query=\"" + QUERY_QUERY + "\")"); - } - }); - } - - - - public JavaNamedQueryTests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_NAME, javaNamedQuery.getName()); - assertEquals(QUERY_NAME, namedQuery.getName()); - - //set name to null in the resource model - javaNamedQuery.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(javaNamedQuery.getName()); - assertNull(namedQuery.getName()); - - //set name in the resource model, verify context model updated - javaNamedQuery.setName("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", javaNamedQuery.getName()); - assertEquals("foo", namedQuery.getName()); - } - - public void testModifyName() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_NAME, javaNamedQuery.getName()); - assertEquals(QUERY_NAME, namedQuery.getName()); - - //set name to null in the context model - namedQuery.setName(null); - assertNull(javaNamedQuery.getName()); - assertNull(namedQuery.getName()); - - //set name in the context model, verify resource model updated - namedQuery.setName("foo"); - assertEquals("foo", javaNamedQuery.getName()); - assertEquals("foo", namedQuery.getName()); - } - - public void testUpdateQuery() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_QUERY, javaNamedQuery.getQuery()); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - //set name to null in the resource model - javaNamedQuery.setQuery(null); - getJpaProject().synchronizeContextModel(); - assertNull(javaNamedQuery.getQuery()); - assertNull(namedQuery.getQuery()); - - //set name in the resource model, verify context model updated - javaNamedQuery.setQuery("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", javaNamedQuery.getQuery()); - assertEquals("foo", namedQuery.getQuery()); - } - - public void testModifyQuery() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_QUERY, javaNamedQuery.getQuery()); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - //set name to null in the context model - namedQuery.setQuery(null); - assertNull(javaNamedQuery.getQuery()); - assertNull(namedQuery.getQuery()); - - //set name in the context model, verify resource model updated - namedQuery.setQuery("foo"); - assertEquals("foo", javaNamedQuery.getQuery()); - assertEquals("foo", namedQuery.getQuery()); - } - - - public void testAddHint() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - - QueryHint queryHint = namedQuery.addHint(0); - queryHint.setName("FOO"); - - assertEquals("FOO", javaNamedQuery.hintAt(0).getName()); - - QueryHint queryHint2 = namedQuery.addHint(0); - queryHint2.setName("BAR"); - - assertEquals("BAR", javaNamedQuery.hintAt(0).getName()); - assertEquals("FOO", javaNamedQuery.hintAt(1).getName()); - - QueryHint queryHint3 = namedQuery.addHint(1); - queryHint3.setName("BAZ"); - - assertEquals("BAR", javaNamedQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedQuery.hintAt(2).getName()); - - ListIterator<QueryHint> hints = namedQuery.hints(); - assertEquals(queryHint2, hints.next()); - assertEquals(queryHint3, hints.next()); - assertEquals(queryHint, hints.next()); - - hints = namedQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - } - - public void testRemoveHint() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1).setName("BAR"); - namedQuery.addHint(2).setName("BAZ"); - - assertEquals(3, javaNamedQuery.hintsSize()); - - namedQuery.removeHint(0); - assertEquals(2, javaNamedQuery.hintsSize()); - assertEquals("BAR", javaNamedQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedQuery.hintAt(1).getName()); - - namedQuery.removeHint(0); - assertEquals(1, javaNamedQuery.hintsSize()); - assertEquals("BAZ", javaNamedQuery.hintAt(0).getName()); - - namedQuery.removeHint(0); - assertEquals(0, javaNamedQuery.hintsSize()); - } - - public void testMoveHint() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1).setName("BAR"); - namedQuery.addHint(2).setName("BAZ"); - - assertEquals(3, javaNamedQuery.hintsSize()); - - - namedQuery.moveHint(2, 0); - ListIterator<QueryHint> hints = namedQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAR", javaNamedQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedQuery.hintAt(2).getName()); - - - namedQuery.moveHint(0, 1); - hints = namedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAZ", javaNamedQuery.hintAt(0).getName()); - assertEquals("BAR", javaNamedQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedQuery.hintAt(2).getName()); - } - - public void testUpdateHints() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - javaNamedQuery.addHint(0); - javaNamedQuery.addHint(1); - javaNamedQuery.addHint(2); - - javaNamedQuery.hintAt(0).setName("FOO"); - javaNamedQuery.hintAt(1).setName("BAR"); - javaNamedQuery.hintAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<QueryHint> hints = namedQuery.hints(); - assertEquals("FOO", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedQuery.moveHint(2, 0); - getJpaProject().synchronizeContextModel(); - hints = namedQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedQuery.moveHint(0, 1); - getJpaProject().synchronizeContextModel(); - hints = namedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedQuery.removeHint(1); - getJpaProject().synchronizeContextModel(); - hints = namedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedQuery.removeHint(1); - getJpaProject().synchronizeContextModel(); - hints = namedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedQuery.removeHint(0); - getJpaProject().synchronizeContextModel(); - assertFalse(namedQuery.hints().hasNext()); - } - - public void testHintsSize() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = getJavaEntity(); - - NamedQuery namedQuery = entity.getQueryContainer().namedQueries().next(); - assertEquals(0, namedQuery.hintsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - - javaNamedQuery.addHint(0); - getJpaProject().synchronizeContextModel(); - assertEquals(1, namedQuery.hintsSize()); - - javaNamedQuery.addHint(0); - getJpaProject().synchronizeContextModel(); - assertEquals(2, namedQuery.hintsSize()); - - javaNamedQuery.removeHint(0); - javaNamedQuery.removeHint(0); - getJpaProject().synchronizeContextModel(); - assertEquals(0, namedQuery.hintsSize()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java deleted file mode 100644 index 9fb4db30ab..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java +++ /dev/null @@ -1,1156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToManyRelationshipReference; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OrderByAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaOneToManyMappingTests extends ContextModelTestCase -{ - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Collection<Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithCollectionOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithNonCollectionOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Address addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map<String, Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidNonGenericMapOneToManyMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private java.util.Map addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private void createTestDepartment() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("import java.util.Map;"); - sb.append(CR); - sb.append("import ").append(JPA.ONE_TO_MANY).append(";"); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Department").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Map<Integer, Employee> employees;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Department.java", sourceWriter); - } - - private void createTestEmployee() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JPA.ENTITY).append(";"); - sb.append(CR); - sb.append("import ").append(JPA.ID).append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Employee").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int empId;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Employee.java", sourceWriter); - } - - public JavaOneToManyMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertNull(persistentAttribute.getSpecifiedMapping()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.getOrderable().setSpecifiedOrderBy("asdf"); - oneToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - - assertNull(oneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - oneToMany.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", oneToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToMany.getTargetEntity()); - - //set target entity to null in the resource model - oneToMany.setTargetEntity(null); - assertNull(oneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - - assertNull(oneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - oneToManyMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", oneToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToMany.getTargetEntity()); - - //set target entity to null in the context model - oneToManyMapping.setSpecifiedTargetEntity(null); - assertNull(oneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - - assertNull(oneToManyMapping.getSpecifiedFetch()); - assertNull(oneToMany.getFetch()); - - //set fetch in the resource model, verify context model updated - oneToMany.setFetch(org.eclipse.jpt.core.resource.java.FetchType.EAGER); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.EAGER, oneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, oneToMany.getFetch()); - - oneToMany.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.LAZY, oneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, oneToMany.getFetch()); - - - //set fetch to null in the resource model - oneToMany.setFetch(null); - getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getSpecifiedFetch()); - assertNull(oneToMany.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - - assertNull(oneToManyMapping.getSpecifiedFetch()); - assertNull(oneToMany.getFetch()); - - //set fetch in the context model, verify resource model updated - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(FetchType.EAGER, oneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, oneToMany.getFetch()); - - oneToManyMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, oneToMany.getFetch()); - - //set fetch to null in the context model - oneToManyMapping.setSpecifiedFetch(null); - assertNull(oneToManyMapping.getSpecifiedFetch()); - assertNull(oneToMany.getFetch()); - } - - public void testUpdateMappedBy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - - assertNull(oneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute()); - assertNull(oneToMany.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - oneToMany.setMappedBy("newMappedBy"); - getJpaProject().synchronizeContextModel(); - assertEquals("newMappedBy", oneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute()); - assertEquals("newMappedBy", oneToMany.getMappedBy()); - - //set mappedBy to null in the resource model - oneToMany.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute()); - assertNull(oneToMany.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME); - - assertNull(oneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute()); - assertNull(oneToMany.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - oneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().setMappedByAttribute("newTargetEntity"); - assertEquals("newTargetEntity", oneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute()); - assertEquals("newTargetEntity", oneToMany.getMappedBy()); - - //set mappedBy to null in the context model - oneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().setMappedByAttribute(null); - assertNull(oneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute()); - assertNull(oneToMany.getMappedBy()); - } - - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - oneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - //TODO this needs to return null for 1.0 mappings. we want the validation error for dot-notation since this is only supported in 2.0 - //TODO need to copy this to all the other mapped by tests. - AttributeMapping stateFooMapping = oneToManyMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertNull(stateFooMapping); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping mapping = (OneToManyMapping) contextAttribute.getMapping(); - OneToManyRelationshipReference relationshipReference = mapping.getRelationshipReference(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - - relationshipReference.setMappedByJoiningStrategy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); - assertTrue(relationshipReference.usesMappedByJoiningStrategy()); - - relationshipReference.setJoinTableJoiningStrategy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToManyAnnotation annotation = (OneToManyAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_MANY); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping mapping = (OneToManyMapping) contextAttribute.getMapping(); - OneToManyRelationshipReference relationshipReference = mapping.getRelationshipReference(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - - annotation.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); - assertTrue(relationshipReference.usesMappedByJoiningStrategy()); - - resourceAttribute.addAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNotNull(annotation.getMappedBy()); - assertFalse(relationshipReference.usesJoinTableJoiningStrategy()); - assertTrue(relationshipReference.usesMappedByJoiningStrategy()); - - annotation.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - - resourceAttribute.removeAnnotation(JPA.JOIN_TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_TABLE)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinTableJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - } - - public void testDefaultTargetEntity() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getDefaultTargetEntity()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getDefaultTargetEntity()); - - //test default still the same when specified target entity it set - oneToManyMapping.setSpecifiedTargetEntity("foo"); - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getDefaultTargetEntity()); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Entity, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityCollectionType() throws Exception { - createTestEntityWithCollectionOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityNonCollectionType() throws Exception { - createTestEntityWithNonCollectionOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getDefaultTargetEntity()); - } - - public void testTargetEntity() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getTargetEntity()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - assertEquals("foo", oneToManyMapping.getTargetEntity()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getTargetEntity()); - } - - public void testResolvedTargetEntity() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit - assertNull(oneToManyMapping.getResolvedTargetEntity()); - - //add targetEntity to the persistence unit, now target entity should resolve - createTestTargetEntityAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, oneToManyMapping.getResolvedTargetEntity()); - - //test default still the same when specified target entity it set - oneToManyMapping.setSpecifiedTargetEntity("foo"); - assertNull(oneToManyMapping.getResolvedTargetEntity()); - - - oneToManyMapping.setSpecifiedTargetEntity(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, oneToManyMapping.getResolvedTargetEntity()); - - - oneToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(addressTypeMapping, oneToManyMapping.getResolvedTargetEntity()); - } - - - public void testUpdateMapKey() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - getJpaProject().synchronizeContextModel(); - assertEquals("myMapKey", oneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - attributeResource.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - oneToManyMapping.setSpecifiedMapKey("myMapKey"); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", oneToManyMapping.getSpecifiedMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey to null in the context model - oneToManyMapping.setSpecifiedMapKey(null); - assertNull(oneToManyMapping.getSpecifiedMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testCandidateMapKeyNames() throws Exception { - createTestEntityWithValidMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator<String> mapKeyNames = - javaOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testCandidateMapKeyNames2() throws Exception { - createTestEntityWithValidNonGenericMapOneToManyMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - JavaOneToManyMapping javaOneToManyMapping = (JavaOneToManyMapping) getJavaPersistentType().getAttributeNamed("addresses").getMapping(); - - Iterator<String> mapKeyNames = javaOneToManyMapping.candidateMapKeyNames(); - assertEquals(false, mapKeyNames.hasNext()); - - javaOneToManyMapping.setSpecifiedTargetEntity("test.Address"); - mapKeyNames = javaOneToManyMapping.candidateMapKeyNames(); - assertEquals("id", mapKeyNames.next()); - assertEquals("city", mapKeyNames.next()); - assertEquals("state", mapKeyNames.next()); - assertEquals("zip", mapKeyNames.next()); - assertFalse(mapKeyNames.hasNext()); - } - - public void testUpdateOrderBy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertEquals("newOrderBy", oneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertEquals("newOrderBy", orderBy.getValue()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(oneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testModifyOrderBy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNull(oneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set mappedBy in the context model, verify resource model updated - oneToManyMapping.getOrderable().setSpecifiedOrderBy("newOrderBy"); - assertEquals("newOrderBy", oneToManyMapping.getOrderable().getSpecifiedOrderBy()); - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertEquals("newOrderBy", orderBy.getValue()); - - //set mappedBy to null in the context model - oneToManyMapping.getOrderable().setSpecifiedOrderBy(null); - assertNull(oneToManyMapping.getOrderable().getSpecifiedOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateNoOrdering() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertTrue(oneToManyMapping.getOrderable().isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertFalse(oneToManyMapping.getOrderable().isNoOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertFalse(oneToManyMapping.getOrderable().isNoOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertTrue(oneToManyMapping.getOrderable().isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdatePkOrdering() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertFalse(oneToManyMapping.getOrderable().isPkOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertTrue(oneToManyMapping.getOrderable().isPkOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertFalse(oneToManyMapping.getOrderable().isPkOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertFalse(oneToManyMapping.getOrderable().isPkOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateCustomOrdering() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertFalse(oneToManyMapping.getOrderable().isCustomOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.getOrderable().isCustomOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - getJpaProject().synchronizeContextModel(); - assertTrue(oneToManyMapping.getOrderable().isCustomOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertFalse(oneToManyMapping.getOrderable().isCustomOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultTargetEntityForMap() throws Exception { - createTestEmployee(); - createTestDepartment(); - addXmlClassRef(PACKAGE_NAME + ".Department"); - addXmlClassRef(PACKAGE_NAME + ".Employee"); - - JavaPersistentType departmentPersistentType = getJavaPersistentType(); - OneToManyMapping employeesMapping = (OneToManyMapping) departmentPersistentType.getAttributeNamed("employees").getSpecifiedMapping(); - assertEquals(PACKAGE_NAME + ".Employee", employeesMapping.getTargetEntity()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java deleted file mode 100644 index d58418b2bc..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java +++ /dev/null @@ -1,1512 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.MappedByJoiningStrategy; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.OneToOneRelationshipReference; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaOneToOneMappingTests extends ContextModelTestCase -{ - - private void createTestTargetEntityAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private State state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableState() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("State").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String foo;").append(CR); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithCollectionOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Collection address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericizedCollectionOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Collection<Address> address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - public JavaOneToOneMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertNull(persistentAttribute.getSpecifiedMapping()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - joinColumns.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(oneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - oneToOne.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", oneToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToOne.getTargetEntity()); - - //set target entity to null in the resource model - oneToOne.setTargetEntity(null); - assertNull(oneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(oneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - oneToOneMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", oneToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToOne.getTargetEntity()); - - //set target entity to null in the context model - oneToOneMapping.setSpecifiedTargetEntity(null); - assertNull(oneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - } - - public void testUpdateMappedBy() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - MappedByJoiningStrategy mappedBy = oneToOneMapping.getRelationshipReference().getMappedByJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(mappedBy.getMappedByAttribute()); - assertNull(oneToOne.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - oneToOne.setMappedBy("newMappedBy"); - getJpaProject().synchronizeContextModel(); - assertEquals("newMappedBy", mappedBy.getMappedByAttribute()); - assertEquals("newMappedBy", oneToOne.getMappedBy()); - - //set mappedBy to null in the resource model - oneToOne.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNull(mappedBy.getMappedByAttribute()); - assertNull(oneToOne.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - MappedByJoiningStrategy mappedBy = oneToOneMapping.getRelationshipReference().getMappedByJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(mappedBy.getMappedByAttribute()); - assertNull(oneToOne.getMappedBy()); - - //set mappedByJoiningStrategy in the context model, verify resource model updated - mappedBy.setMappedByAttribute("newTargetEntity"); - assertEquals("newTargetEntity", mappedBy.getMappedByAttribute()); - assertEquals("newTargetEntity", oneToOne.getMappedBy()); - - //set mappedByJoiningStrategy to null in the context model - mappedBy.setMappedByAttribute(null); - assertNull(mappedBy.getMappedByAttribute()); - assertNull(oneToOne.getMappedBy()); - } - - public void testUpdateSpecifiedOptional() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(oneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOne.getOptional()); - - //set optional in the resource model, verify context model updated - oneToOne.setOptional(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.TRUE, oneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - - oneToOne.setOptional(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - assertEquals(Boolean.FALSE, oneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, oneToOne.getOptional()); - - - //set optional to null in the resource model - oneToOne.setOptional(null); - getJpaProject().synchronizeContextModel(); - assertNull(oneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOne.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(oneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOne.getOptional()); - - //set optional in the context model, verify resource model updated - oneToOneMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, oneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - - oneToOneMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, oneToOne.getOptional()); - - - //set optional to null in the context model - oneToOneMapping.setSpecifiedOptional(null); - assertNull(oneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOne.getOptional()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(oneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOne.getFetch()); - - //set fetch in the resource model, verify context model updated - oneToOne.setFetch(org.eclipse.jpt.core.resource.java.FetchType.EAGER); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.EAGER, oneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, oneToOne.getFetch()); - - oneToOne.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - getJpaProject().synchronizeContextModel(); - assertEquals(FetchType.LAZY, oneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, oneToOne.getFetch()); - - //set fetch to null in the resource model - oneToOne.setFetch(null); - getJpaProject().synchronizeContextModel(); - assertNull(oneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOne.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - assertNull(oneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOne.getFetch()); - - //set fetch in the context model, verify resource model updated - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(FetchType.EAGER, oneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, oneToOne.getFetch()); - - oneToOneMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, oneToOne.getFetch()); - - //set fetch to null in the context model - oneToOneMapping.setSpecifiedFetch(null); - assertNull(oneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOne.getFetch()); - } - - public void testSpecifiedJoinColumns() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - ListIterator<? extends JoinColumn> specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - - assertFalse(specifiedJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - JoinColumnAnnotation joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedJoinColumns = joinColumns.specifiedJoinColumns(); - assertFalse(specifiedJoinColumns.hasNext()); - } - - public void testGetDefaultJoin() { - //TODO - } - - public void testSpecifiedJoinColumnsSize() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - - joinColumns.addSpecifiedJoinColumn(0); - assertEquals(1, joinColumns.specifiedJoinColumnsSize()); - - joinColumns.removeSpecifiedJoinColumn(0); - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - } - - public void testJoinColumnsSize() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - assertEquals(1, joinColumns.joinColumnsSize()); - - joinColumns.addSpecifiedJoinColumn(0); - assertEquals(1, joinColumns.joinColumnsSize()); - - joinColumns.addSpecifiedJoinColumn(0); - assertEquals(2, joinColumns.joinColumnsSize()); - - joinColumns.removeSpecifiedJoinColumn(0); - joinColumns.removeSpecifiedJoinColumn(0); - assertEquals(1, joinColumns.joinColumnsSize()); - - //if non-owning side of the relationship then no default join column - oneToOneMapping.getRelationshipReference().getMappedByJoiningStrategy().setMappedByAttribute("foo"); - assertEquals(0, joinColumns.joinColumnsSize()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> joinColumnsIterator = - attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testAddSpecifiedJoinColumn2() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> joinColumnsIterator = - attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnsIterator.next()).getName()); - assertFalse(joinColumnsIterator.hasNext()); - } - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertEquals(3, CollectionTools.size(attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME))); - - joinColumns.removeSpecifiedJoinColumn(1); - - Iterator<NestableAnnotation> joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - Iterator<? extends JoinColumn> joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - joinColumns.removeSpecifiedJoinColumn(1); - joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - - joinColumns.removeSpecifiedJoinColumn(0); - joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertFalse(joinColumnResources.hasNext()); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertFalse(joinColumnsIterator.hasNext()); - - assertNull(attributeResource.getAnnotation(JoinColumnsAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - joinColumns.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinColumns.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinColumns.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentAttribute attributeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - Iterator<NestableAnnotation> javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaJoinColumns)); - - - joinColumns.moveSpecifiedJoinColumn(2, 0); - ListIterator<? extends JoinColumn> primaryKeyJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - - - joinColumns.moveSpecifiedJoinColumn(0, 1); - primaryKeyJoinColumns = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) javaJoinColumns.next()).getName()); - } - - public void testUpdateSpecifiedJoinColumns() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - JavaResourcePersistentAttribute attributeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - ((JoinColumnAnnotation) attributeResource.addAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((JoinColumnAnnotation) attributeResource.addAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((JoinColumnAnnotation) attributeResource.addAnnotation(2, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<? extends JoinColumn> joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.moveAnnotation(2, 0, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.moveAnnotation(0, 1, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("BAR", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.removeAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertEquals("FOO", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.removeAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertEquals("BAZ", joinColumnsIterator.next().getName()); - assertFalse(joinColumnsIterator.hasNext()); - - attributeResource.removeAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumnsIterator = joinColumns.specifiedJoinColumns(); - assertFalse(joinColumnsIterator.hasNext()); - } - - public void testJoinColumnIsVirtual() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - assertTrue(joinColumns.getDefaultJoinColumn().isVirtual()); - - joinColumns.addSpecifiedJoinColumn(0); - JoinColumn specifiedJoinColumn = joinColumns.specifiedJoinColumns().next(); - assertFalse(specifiedJoinColumn.isVirtual()); - - assertNull(joinColumns.getDefaultJoinColumn()); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - createTestEmbeddableState(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".State"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = - oneToOneMapping.getRelationshipReference().getMappedByJoiningStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = - oneToOneMapping.getRelationshipReference().getMappedByJoiningStrategy().candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = - oneToOneMapping.getRelationshipReference().getMappedByJoiningStrategy().candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); - assertNull(stateFooMapping); - } - - public void testDefaultTargetEntity() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getDefaultTargetEntity()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getDefaultTargetEntity()); - - //test default still the same when specified target entity it set - oneToOneMapping.setSpecifiedTargetEntity("foo"); - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getDefaultTargetEntity()); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Entity, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityCollectionType() throws Exception { - createTestEntityWithCollectionOneToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - assertNull(oneToOneMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityGenericizedCollectionType() throws Exception { - createTestEntityWithGenericizedCollectionOneToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - assertNull(oneToOneMapping.getDefaultTargetEntity()); - } - - public void testTargetEntity() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getTargetEntity()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - assertEquals("foo", oneToOneMapping.getTargetEntity()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getTargetEntity()); - } - - public void testResolvedTargetEntity() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit - assertNull(oneToOneMapping.getResolvedTargetEntity()); - - //add targetEntity to the persistence unit, now target entity should resolve - createTestTargetEntityAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, oneToOneMapping.getResolvedTargetEntity()); - - //test default still the same when specified target entity it set - oneToOneMapping.setSpecifiedTargetEntity("foo"); - assertNull(oneToOneMapping.getResolvedTargetEntity()); - - - oneToOneMapping.setSpecifiedTargetEntity(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, oneToOneMapping.getResolvedTargetEntity()); - - - oneToOneMapping.setSpecifiedTargetEntity(null); - assertEquals(addressTypeMapping, oneToOneMapping.getResolvedTargetEntity()); - } - - public void testPrimaryKeyJoinColumns() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnJoiningStrategy strategy = - oneToOneMapping.getRelationshipReference().getPrimaryKeyJoinColumnJoiningStrategy(); - ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns = - strategy.primaryKeyJoinColumns(); - - assertFalse(primaryKeyJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - PrimaryKeyJoinColumnAnnotation joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - - joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = strategy.primaryKeyJoinColumns(); - assertFalse(primaryKeyJoinColumns.hasNext()); - } - - public void testPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnJoiningStrategy strategy = - oneToOneMapping.getRelationshipReference().getPrimaryKeyJoinColumnJoiningStrategy(); - - assertEquals(0, strategy.primaryKeyJoinColumnsSize()); - - strategy.addPrimaryKeyJoinColumn(0); - assertEquals(1, strategy.primaryKeyJoinColumnsSize()); - - strategy.removePrimaryKeyJoinColumn(0); - assertEquals(0, strategy.primaryKeyJoinColumnsSize()); - } - - public void testAddPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnJoiningStrategy strategy = - oneToOneMapping.getRelationshipReference().getPrimaryKeyJoinColumnJoiningStrategy(); - - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> joinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertFalse(joinColumns.hasNext()); - } - - public void testAddPrimaryKeyJoinColumn2() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnJoiningStrategy strategy = - oneToOneMapping.getRelationshipReference().getPrimaryKeyJoinColumnJoiningStrategy(); - - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - strategy.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - strategy.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> joinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertFalse(joinColumns.hasNext()); - } - - public void testRemovePrimaryKeyJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnJoiningStrategy strategy = - oneToOneMapping.getRelationshipReference().getPrimaryKeyJoinColumnJoiningStrategy(); - - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - strategy.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - strategy.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertEquals(3, CollectionTools.size(attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME))); - - strategy.removePrimaryKeyJoinColumn(1); - - Iterator<NestableAnnotation> joinColumnResources = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) joinColumnResources.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - Iterator<PrimaryKeyJoinColumn> joinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - - strategy.removePrimaryKeyJoinColumn(1); - joinColumnResources = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - joinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - - strategy.removePrimaryKeyJoinColumn(0); - joinColumnResources = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertFalse(joinColumnResources.hasNext()); - joinColumns = strategy.primaryKeyJoinColumns(); - assertFalse(joinColumns.hasNext()); - - assertNull(attributeResource.getAnnotation(PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)); - } - - public void testMovePrimaryKeyJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnJoiningStrategy strategy = - oneToOneMapping.getRelationshipReference().getPrimaryKeyJoinColumnJoiningStrategy(); - - strategy.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - strategy.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - strategy.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentAttribute attributeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - - Iterator<NestableAnnotation> javaJoinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaJoinColumns)); - - - strategy.movePrimaryKeyJoinColumn(2, 0); - ListIterator<PrimaryKeyJoinColumn> primaryKeyJoinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) javaJoinColumns.next()).getName()); - - - strategy.movePrimaryKeyJoinColumn(0, 1); - primaryKeyJoinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) javaJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) javaJoinColumns.next()).getName()); - } - - public void testUpdatePrimaryKeyJoinColumns() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute attributeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - PrimaryKeyJoinColumnJoiningStrategy strategy = - oneToOneMapping.getRelationshipReference().getPrimaryKeyJoinColumnJoiningStrategy(); - - ((PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(2, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<PrimaryKeyJoinColumn> joinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.moveAnnotation(2, 0, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.moveAnnotation(0, 1, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumns = strategy.primaryKeyJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - joinColumns = strategy.primaryKeyJoinColumns(); - assertFalse(joinColumns.hasNext()); - } - - public void testModifyPredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_ONE); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping mapping = (OneToOneMapping) contextAttribute.getMapping(); - OneToOneRelationshipReference relationshipReference = mapping.getRelationshipReference(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - - relationshipReference.setPrimaryKeyJoinColumnJoiningStrategy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); - assertTrue(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - - relationshipReference.setMappedByJoiningStrategy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); - assertTrue(relationshipReference.usesMappedByJoiningStrategy()); - - relationshipReference.setJoinColumnJoiningStrategy(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - } - - public void testUpdatePredominantJoiningStrategy() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentAttribute resourceAttribute = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME).persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) resourceAttribute.getAnnotation(JPA.ONE_TO_ONE); - PersistentAttribute contextAttribute = getJavaPersistentType().attributes().next(); - OneToOneMapping mapping = (OneToOneMapping) contextAttribute.getMapping(); - OneToOneRelationshipReference relationshipReference = mapping.getRelationshipReference(); - - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - - resourceAttribute.addAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); - assertTrue(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - - annotation.setMappedBy("foo"); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); - assertTrue(relationshipReference.usesMappedByJoiningStrategy()); - - resourceAttribute.addAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); - assertTrue(relationshipReference.usesMappedByJoiningStrategy()); - - resourceAttribute.removeAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(annotation.getMappedBy()); - assertFalse(relationshipReference.usesJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); - assertTrue(relationshipReference.usesMappedByJoiningStrategy()); - - annotation.setMappedBy(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - - resourceAttribute.removeAnnotation(JPA.JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - assertNull(resourceAttribute.getAnnotation(JPA.JOIN_COLUMN)); - assertNull(resourceAttribute.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNull(annotation.getMappedBy()); - assertTrue(relationshipReference.usesJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesPrimaryKeyJoinColumnJoiningStrategy()); - assertFalse(relationshipReference.usesMappedByJoiningStrategy()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java deleted file mode 100644 index c97875c543..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java +++ /dev/null @@ -1,301 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase -{ - private static final String PRIMARY_KEY_JOIN_COLUMN_NAME = "MY_PRIMARY_KEY_JOIN_COLUMN"; - private static final String COLUMN_DEFINITION = "MY_COLUMN_DEFINITION"; - - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithPrimaryKeyJoinColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@PrimaryKeyJoinColumn(name=\"" + PRIMARY_KEY_JOIN_COLUMN_NAME + "\")"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - - public JavaPrimaryKeyJoinColumnTests(String name) { - super(name); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals(PRIMARY_KEY_JOIN_COLUMN_NAME, specifiedPkJoinColumn.getSpecifiedName()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - pkJoinColumnResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("FOO", specifiedPkJoinColumn.getName()); - } - - public void testGetDefaultNameNoSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn pkJoinColumn = getJavaEntity().getDefaultPrimaryKeyJoinColumn(); - assertEquals("id", pkJoinColumn.getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("id", specifiedPkJoinColumn.getDefaultName()); - - //remove @Id annotation - PersistentAttribute idAttribute = getJavaPersistentType().getAttributeNamed("id"); - idAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNull(specifiedPkJoinColumn.getDefaultName()); - } - - public void testGetName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals(PRIMARY_KEY_JOIN_COLUMN_NAME, specifiedPkJoinColumn.getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - - specifiedPkJoinColumn.setSpecifiedName("foo"); - assertEquals("foo", specifiedPkJoinColumn.getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertEquals("foo", pkJoinColumn.getName()); - - specifiedPkJoinColumn.setSpecifiedName(null); - assertNull(specifiedPkJoinColumn.getSpecifiedName()); - pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertNull(pkJoinColumn); - } - - public void testGetColumnDefinition() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertNull(specifiedPkJoinColumn.getColumnDefinition()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - column.setColumnDefinition(COLUMN_DEFINITION); - getJpaProject().synchronizeContextModel(); - - assertEquals(COLUMN_DEFINITION, specifiedPkJoinColumn.getColumnDefinition()); - - column.setColumnDefinition(null); - getJpaProject().synchronizeContextModel(); - - assertNull(specifiedPkJoinColumn.getColumnDefinition()); - - typeResource.removeAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - getJpaProject().synchronizeContextModel(); - - assertEquals(0, getJavaEntity().specifiedPrimaryKeyJoinColumnsSize()); - } - - public void testSetColumnDefinition() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - specifiedPkJoinColumn.setColumnDefinition("foo"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertEquals("foo", column.getColumnDefinition()); - - specifiedPkJoinColumn.setColumnDefinition(null); - column = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertNull(column.getColumnDefinition()); - } - - public void testGetSpecifiedReferencedColumnName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertNull(specifiedPkJoinColumn.getSpecifiedReferencedColumnName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - pkJoinColumnResource.setReferencedColumnName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("FOO", specifiedPkJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testGetDefaultReferencedColumnNameNoSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn pkJoinColumn = getJavaEntity().getDefaultPrimaryKeyJoinColumn(); - assertEquals("id", pkJoinColumn.getDefaultReferencedColumnName()); - } - - public void testGetDefaultReferencedColumnName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("id", specifiedPkJoinColumn.getDefaultReferencedColumnName()); - - - //remove @Id annotation - PersistentAttribute idAttribute = getJavaPersistentType().getAttributeNamed("id"); - idAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNull(specifiedPkJoinColumn.getDefaultReferencedColumnName()); - } - - public void testGetReferencedColumnName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - pkJoinColumnResource.setReferencedColumnName("FOO"); - getJpaProject().synchronizeContextModel(); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("FOO", specifiedPkJoinColumn.getReferencedColumnName()); - } - - public void testSetSpecifiedReferencedColumnName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - - specifiedPkJoinColumn.setSpecifiedReferencedColumnName("foo"); - assertEquals("foo", specifiedPkJoinColumn.getSpecifiedReferencedColumnName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertEquals("foo", pkJoinColumn.getReferencedColumnName()); - - specifiedPkJoinColumn.setSpecifiedName(null); - specifiedPkJoinColumn.setSpecifiedReferencedColumnName(null); - assertNull(specifiedPkJoinColumn.getSpecifiedReferencedColumnName()); - pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertNull(pkJoinColumn); - } - - public void testIsVirtual() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertFalse(specifiedPkJoinColumn.isVirtual()); - - assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(0); - assertTrue(getJavaEntity().getDefaultPrimaryKeyJoinColumn().isVirtual()); - } - - public void testIsReferencedColumnResolved() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertFalse(specifiedPkJoinColumn.isReferencedColumnResolved()); - } - - public void testDbColumn() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertNull(specifiedPkJoinColumn.getDbColumn()); - } - - public void testDbReferencedColumn() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertNull(specifiedPkJoinColumn.getReferencedDbColumn()); - } - - public void testDbTable() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertNull(specifiedPkJoinColumn.getDbTable()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaQueryHintTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaQueryHintTests.java deleted file mode 100644 index 26db23a73d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaQueryHintTests.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaQueryHintTests extends ContextModelTestCase -{ - private static final String QUERY_NAME = "QUERY_NAME"; - - private ICompilationUnit createTestEntityWithNamedQuery() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.NAMED_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@NamedQuery(name=\"" + QUERY_NAME + "\", hints=@QueryHint())"); - } - }); - } - - - - public JavaQueryHintTests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - QueryHint queryHint = entity.getQueryContainer().namedQueries().next().hints().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - QueryHintAnnotation javaQueryHint = ((NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)).hints().next(); - - assertNull(javaQueryHint.getName()); - assertNull(queryHint.getName()); - - //set name in the resource model, verify context model updated - javaQueryHint.setName("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", javaQueryHint.getName()); - assertEquals("foo", queryHint.getName()); - - //set name to null in the resource model - javaQueryHint.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(javaQueryHint.getName()); - assertEquals(0, entity.getQueryContainer().namedQueries().next().hintsSize()); - } - - public void testModifyName() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - QueryHint queryHint = entity.getQueryContainer().namedQueries().next().hints().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - QueryHintAnnotation javaQueryhint = ((NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)).hints().next(); - - assertNull(javaQueryhint.getName()); - assertNull(queryHint.getName()); - - //set name in the context model, verify resource model updated - queryHint.setName("foo"); - assertEquals("foo", javaQueryhint.getName()); - assertEquals("foo", queryHint.getName()); - - //set name to null in the context model - queryHint.setName(null); - assertNull(javaQueryhint.getName()); - assertNull(queryHint.getName()); - } - - public void testUpdateValue() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - QueryHint queryHint = entity.getQueryContainer().namedQueries().next().hints().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - QueryHintAnnotation javaQueryhint = ((NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)).hints().next(); - - assertNull(javaQueryhint.getValue()); - assertNull(queryHint.getValue()); - - //set name in the resource model, verify context model updated - javaQueryhint.setValue("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", javaQueryhint.getValue()); - assertEquals("foo", queryHint.getValue()); - - //set name to null in the resource model - javaQueryhint.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNull(javaQueryhint.getValue()); - assertEquals(0, entity.getQueryContainer().namedQueries().next().hintsSize()); - } - - public void testModifyValue() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - QueryHint queryHint = entity.getQueryContainer().namedQueries().next().hints().next(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - QueryHintAnnotation javaQueryhint = ((NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)).hints().next(); - - assertNull(javaQueryhint.getValue()); - assertNull(queryHint.getValue()); - - //set name in the context model, verify resource model updated - queryHint.setValue("foo"); - assertEquals("foo", javaQueryhint.getValue()); - assertEquals("foo", queryHint.getValue()); - - //set name to null in the context model - queryHint.setValue(null); - assertNull(javaQueryhint.getValue()); - assertNull(queryHint.getValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSecondaryTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSecondaryTableTests.java deleted file mode 100644 index 1933de159b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSecondaryTableTests.java +++ /dev/null @@ -1,752 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaSecondaryTableTests extends ContextModelTestCase -{ - private static final String TABLE_NAME = "MY_TABLE"; - - private ICompilationUnit createTestEntityWithSecondaryTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@SecondaryTable(name=\"" + TABLE_NAME + "\")"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTables() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@SecondaryTables({@SecondaryTable(name=\"foo\"), @SecondaryTable(name=\"bar\")})"); - } - }); - } - - - - - public JavaSecondaryTableTests(String name) { - super(name); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().secondaryTables().next(); - assertEquals(TABLE_NAME, secondaryTable.getSpecifiedName()); - } - - public void testGetDefaultNameNull() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().secondaryTables().next(); - assertNull(secondaryTable.getDefaultName()); - } - - public void testGetName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().secondaryTables().next(); - assertEquals(TABLE_NAME, secondaryTable.getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().secondaryTables().next(); - secondaryTable.setSpecifiedName("foo"); - - assertEquals("foo", getJavaEntity().secondaryTables().next().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals("foo", table.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().secondaryTables().next(); - secondaryTable.setSpecifiedName(null); - - assertEquals(0, getJavaEntity().secondaryTablesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - } - - public void testUpdateFromSpecifiedNameChangeInResourceModel() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - table.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", getJavaEntity().secondaryTables().next().getSpecifiedName()); - } - - public void testUpdateFromSpecifiedCatalogChangeInResourceModel() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator<NestableAnnotation> secondaryTableResources = typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - ((SecondaryTableAnnotation) secondaryTableResources.next()).setCatalog("foo"); - ((SecondaryTableAnnotation) secondaryTableResources.next()).setCatalog("bar"); - getJpaProject().synchronizeContextModel(); - - ListIterator<JavaSecondaryTable> secondaryTsbles = getJavaEntity().secondaryTables(); - assertEquals("foo", secondaryTsbles.next().getSpecifiedCatalog()); - assertEquals("bar", secondaryTsbles.next().getSpecifiedCatalog()); - } - - public void testUpdateFromSpecifiedSchemaChangeInResourceModel() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator<NestableAnnotation> secondaryTableResources = typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - ((SecondaryTableAnnotation) secondaryTableResources.next()).setSchema("foo"); - ((SecondaryTableAnnotation) secondaryTableResources.next()).setSchema("bar"); - getJpaProject().synchronizeContextModel(); - - ListIterator<JavaSecondaryTable> secondaryTsbles = getJavaEntity().secondaryTables(); - assertEquals("foo", secondaryTsbles.next().getSpecifiedSchema()); - assertEquals("bar", secondaryTsbles.next().getSpecifiedSchema()); - } - - public void testGetCatalog() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - table.setCatalog("myCatalog"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myCatalog", getJavaEntity().secondaryTables().next().getSpecifiedCatalog()); - assertEquals("myCatalog", getJavaEntity().secondaryTables().next().getCatalog()); - } - - public void testGetDefaultCatalog() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().secondaryTables().next().getDefaultCatalog()); - - getJavaEntity().secondaryTables().next().setSpecifiedCatalog("myCatalog"); - - assertNull(getJavaEntity().secondaryTables().next().getDefaultCatalog()); - } - - public void testSetSpecifiedCatalog() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTable table = getJavaEntity().secondaryTables().next(); - table.setSpecifiedCatalog("myCatalog"); - table.setSpecifiedName(null); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals("myCatalog", tableResource.getCatalog()); - - table.setSpecifiedCatalog(null); - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - } - - public void testGetSchema() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - tableResource.setSchema("mySchema"); - getJpaProject().synchronizeContextModel(); - - assertEquals("mySchema", getJavaEntity().secondaryTables().next().getSpecifiedSchema()); - assertEquals("mySchema", getJavaEntity().secondaryTables().next().getSchema()); - } - - public void testGetDefaultSchema() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().secondaryTables().next().getDefaultSchema()); - - getJavaEntity().secondaryTables().next().setSpecifiedSchema("mySchema"); - - assertNull(getJavaEntity().secondaryTables().next().getDefaultSchema()); - } - - public void testSetSpecifiedSchema() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTable table = getJavaEntity().secondaryTables().next(); - table.setSpecifiedSchema("mySchema"); - table.setSpecifiedName(null); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals("mySchema", tableResource.getSchema()); - - table.setSpecifiedSchema(null); - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - } - - public void testSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - ListIterator<JavaPrimaryKeyJoinColumn> specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - - assertFalse(specifiedPkJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - //add an annotation to the resource model and verify the context model is updated - PrimaryKeyJoinColumnAnnotation pkJoinColumn = tableResource.addPkJoinColumn(0); - pkJoinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - pkJoinColumn = tableResource.addPkJoinColumn(0); - pkJoinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - - //move an annotation to the resource model and verify the context model is updated - tableResource.movePkJoinColumn(1, 0); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - tableResource.removePkJoinColumn(0); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - tableResource.removePkJoinColumn(0); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertFalse(specifiedPkJoinColumns.hasNext()); - } - - public void testSpecifiedPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - assertEquals(0, secondaryTable.specifiedPrimaryKeyJoinColumnsSize()); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertEquals(3, secondaryTable.specifiedPrimaryKeyJoinColumnsSize()); - } - - public void testPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - //just the default pkJoinColumn, so 1 - assertEquals(1, secondaryTable.primaryKeyJoinColumnsSize()); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - //only the specified pkJoinColumns, 3 - assertEquals(3, secondaryTable.primaryKeyJoinColumnsSize()); - } - - public void testGetDefaultPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - assertNotNull(secondaryTable.getDefaultPrimaryKeyJoinColumn()); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertNull(secondaryTable.getDefaultPrimaryKeyJoinColumn()); - } - - public void testPrimaryKeyJoinColumnDefaults() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - PrimaryKeyJoinColumn defaultPkJoinColumn = secondaryTable.getDefaultPrimaryKeyJoinColumn(); - assertNotNull(defaultPkJoinColumn); - assertEquals("id", defaultPkJoinColumn.getDefaultName()); - assertEquals("id", defaultPkJoinColumn.getDefaultReferencedColumnName()); - - - IdMapping idMapping = (IdMapping) getJavaEntity().getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - assertEquals("FOO", defaultPkJoinColumn.getDefaultName()); - assertEquals("FOO", defaultPkJoinColumn.getDefaultReferencedColumnName()); - - idMapping.getColumn().setSpecifiedName(null); - assertEquals("id", defaultPkJoinColumn.getDefaultName()); - assertEquals("id", defaultPkJoinColumn.getDefaultReferencedColumnName()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - Iterator<PrimaryKeyJoinColumn> specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - Iterator<PrimaryKeyJoinColumnAnnotation> pkJoinColumns = tableResource.pkJoinColumns(); - - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertEquals("BAR", pkJoinColumns.next().getName()); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn2() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - Iterator<PrimaryKeyJoinColumn> specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - Iterator<PrimaryKeyJoinColumnAnnotation> pkJoinColumns = tableResource.pkJoinColumns(); - - assertEquals("FOO", pkJoinColumns.next().getName()); - assertEquals("BAR", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - } - public void testRemoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, tableResource.pkJoinColumnsSize()); - - secondaryTable.removeSpecifiedPrimaryKeyJoinColumn(1); - - Iterator<PrimaryKeyJoinColumnAnnotation> pkJoinColumnResources = tableResource.pkJoinColumns(); - assertEquals("FOO", pkJoinColumnResources.next().getName()); - assertEquals("BAZ", pkJoinColumnResources.next().getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - Iterator<PrimaryKeyJoinColumn> pkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - secondaryTable.removeSpecifiedPrimaryKeyJoinColumn(1); - pkJoinColumnResources = tableResource.pkJoinColumns(); - assertEquals("FOO", pkJoinColumnResources.next().getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - pkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - secondaryTable.removeSpecifiedPrimaryKeyJoinColumn(0); - pkJoinColumnResources = tableResource.pkJoinColumns(); - assertFalse(pkJoinColumnResources.hasNext()); - pkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertFalse(pkJoinColumns.hasNext()); - - assertEquals(0, tableResource.pkJoinColumnsSize()); - } - - public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - Iterator<PrimaryKeyJoinColumn> specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - Iterator<PrimaryKeyJoinColumnAnnotation> pkJoinColumns = tableResource.pkJoinColumns(); - - assertEquals("FOO", pkJoinColumns.next().getName()); - assertEquals("BAR", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - - - secondaryTable.moveSpecifiedPrimaryKeyJoinColumn(2, 0); - pkJoinColumns = tableResource.pkJoinColumns(); - - assertEquals("BAR", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertEquals("FOO", pkJoinColumns.next().getName()); - } - - public void testPrimaryKeyJoinColumnGetDefaultName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - PrimaryKeyJoinColumn defaultPkJoinColumn = secondaryTable.getDefaultPrimaryKeyJoinColumn(); - assertEquals("id", defaultPkJoinColumn.getDefaultName()); - - - //remove @Id annotation - PersistentAttribute idAttribute = getJavaPersistentType().getAttributeNamed("id"); - idAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNull(defaultPkJoinColumn.getDefaultName()); - } - public void testPrimaryKeyJoinColumnGetDefaultReferencedColumnName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - PrimaryKeyJoinColumn defaultPkJoinColumn = secondaryTable.getDefaultPrimaryKeyJoinColumn(); - assertEquals("id", defaultPkJoinColumn.getDefaultReferencedColumnName()); - - //remove @Id annotation - PersistentAttribute idAttribute = getJavaPersistentType().getAttributeNamed("id"); - idAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNull(defaultPkJoinColumn.getDefaultReferencedColumnName()); - } - - public void testPrimaryKeyJoinColumnIsVirtual() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - - assertTrue(secondaryTable.getDefaultPrimaryKeyJoinColumn().isVirtual()); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); - PrimaryKeyJoinColumn specifiedPkJoinColumn = secondaryTable.specifiedPrimaryKeyJoinColumns().next(); - assertFalse(specifiedPkJoinColumn.isVirtual()); - - assertNull(secondaryTable.getDefaultPrimaryKeyJoinColumn()); - } - - - public void testUniqueConstraints() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - - ListIterator<JavaUniqueConstraint> uniqueConstraints = secondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - secondaryTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - secondaryTableAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - getJpaProject().synchronizeContextModel(); - - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - - assertEquals(0, secondaryTable.uniqueConstraintsSize()); - - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - secondaryTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - secondaryTableAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - getJpaProject().synchronizeContextModel(); - assertEquals(2, secondaryTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = secondaryTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - secondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = secondaryTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - secondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - secondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, secondaryTableAnnotation.uniqueConstraintsSize()); - - secondaryTable.removeUniqueConstraint(1); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator<UniqueConstraint> uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - secondaryTable.removeUniqueConstraint(1); - uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - secondaryTable.removeUniqueConstraint(0); - uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - secondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - secondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, secondaryTableAnnotation.uniqueConstraintsSize()); - - - secondaryTable.moveUniqueConstraint(2, 0); - ListIterator<UniqueConstraint> uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - secondaryTable.moveUniqueConstraint(0, 1); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = getJavaEntity().specifiedSecondaryTables().next(); - JavaResourcePersistentType resourcePersistentType = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - - secondaryTableAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - secondaryTableAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - secondaryTableAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - getJpaProject().synchronizeContextModel(); - - - ListIterator<UniqueConstraint> uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.moveUniqueConstraint(2, 0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.moveUniqueConstraint(0, 1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.removeUniqueConstraint(0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSequenceGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSequenceGeneratorTests.java deleted file mode 100644 index 6923317ade..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSequenceGeneratorTests.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.SequenceGenerator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaSequenceGeneratorTests extends ContextModelTestCase -{ - private static final String SEQUENCE_GENERATOR_NAME = "MY_SEQUENCE_GENERATOR"; - - - protected ICompilationUnit createTestEntityWithSequenceGenerator() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.SEQUENCE_GENERATOR, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@SequenceGenerator(name=\"" + SEQUENCE_GENERATOR_NAME + "\")"); - } - }); - } - - public JavaSequenceGeneratorTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(SEQUENCE_GENERATOR_NAME, idMapping.getGeneratorContainer().getSequenceGenerator().getName()); - - //change resource model sequenceGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - sequenceGenerator.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", idMapping.getGeneratorContainer().getSequenceGenerator().getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(SEQUENCE_GENERATOR_NAME, idMapping.getGeneratorContainer().getSequenceGenerator().getName()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setName("foo"); - - assertEquals("foo", idMapping.getGeneratorContainer().getSequenceGenerator().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertEquals("foo", sequenceGenerator.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(SEQUENCE_GENERATOR_NAME, idMapping.getGeneratorContainer().getSequenceGenerator().getName()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setName(null); - - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertNull(sequenceGenerator); - } - - public void testGetInitialValue() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(SequenceGenerator.DEFAULT_INITIAL_VALUE, idMapping.getGeneratorContainer().getSequenceGenerator().getInitialValue()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - sequenceGenerator.setInitialValue(Integer.valueOf(82)); - getJpaProject().synchronizeContextModel(); - - assertEquals(82, idMapping.getGeneratorContainer().getSequenceGenerator().getInitialValue()); - assertEquals(Integer.valueOf(82), idMapping.getGeneratorContainer().getSequenceGenerator().getSpecifiedInitialValue()); - } - - public void testGetDefaultInitialValue() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(SequenceGenerator.DEFAULT_INITIAL_VALUE, idMapping.getGeneratorContainer().getSequenceGenerator().getDefaultInitialValue()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedInitialValue(Integer.valueOf(82)); - - assertEquals(SequenceGenerator.DEFAULT_INITIAL_VALUE, idMapping.getGeneratorContainer().getSequenceGenerator().getDefaultInitialValue()); - assertEquals(Integer.valueOf(82), idMapping.getGeneratorContainer().getSequenceGenerator().getSpecifiedInitialValue()); - } - - public void testSetSpecifiedInitialValue() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedInitialValue(Integer.valueOf(20)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertEquals(Integer.valueOf(20), sequenceGenerator.getInitialValue()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setName(null); - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedInitialValue(null); - assertNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - } - - public void testGetAllocationSize() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getGeneratorContainer().getSequenceGenerator().getAllocationSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - sequenceGenerator.setAllocationSize(Integer.valueOf(20)); - getJpaProject().synchronizeContextModel(); - - assertEquals(20, idMapping.getGeneratorContainer().getSequenceGenerator().getAllocationSize()); - assertEquals(Integer.valueOf(20), idMapping.getGeneratorContainer().getSequenceGenerator().getSpecifiedAllocationSize()); - } - - public void testGetDefaultAllocationSize() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getGeneratorContainer().getSequenceGenerator().getDefaultAllocationSize()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedAllocationSize(Integer.valueOf(20)); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getGeneratorContainer().getSequenceGenerator().getDefaultAllocationSize()); - assertEquals(Integer.valueOf(20), idMapping.getGeneratorContainer().getSequenceGenerator().getSpecifiedAllocationSize()); - } - - public void testSetSpecifiedAllocationSize() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedAllocationSize(Integer.valueOf(25)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertEquals(Integer.valueOf(25), sequenceGenerator.getAllocationSize()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setName(null); - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedAllocationSize(null); - assertNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - } - - - - public void testGetSequenceName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator().getSequenceName()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - sequenceGenerator.setSequenceName("mySequenceName"); - getJpaProject().synchronizeContextModel(); - - assertEquals("mySequenceName", idMapping.getGeneratorContainer().getSequenceGenerator().getSequenceName()); - assertEquals("mySequenceName", idMapping.getGeneratorContainer().getSequenceGenerator().getSpecifiedSequenceName()); - } - - public void testGetDefaultSequenceName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator().getDefaultSequenceName()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedSequenceName("mySequenceName"); - - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator().getDefaultSequenceName()); - assertEquals("mySequenceName", idMapping.getGeneratorContainer().getSequenceGenerator().getSpecifiedSequenceName()); - } - - public void testSetSpecifiedSequenceName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedSequenceName("mySequenceName"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertEquals("mySequenceName", sequenceGenerator.getSequenceName()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setName(null); - idMapping.getGeneratorContainer().getSequenceGenerator().setSpecifiedSequenceName(null); - assertNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableGeneratorTests.java deleted file mode 100644 index 84961d2ced..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableGeneratorTests.java +++ /dev/null @@ -1,716 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Generator; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaTableGeneratorTests extends ContextModelTestCase -{ - private static final String TABLE_GENERATOR_NAME = "MY_TABLE_GENERATOR"; - - private ICompilationUnit createTestEntityWithTableGenerator() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.TABLE_GENERATOR, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@TableGenerator(name=\"" + TABLE_GENERATOR_NAME + "\")"); - } - }); - } - - public JavaTableGeneratorTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(TABLE_GENERATOR_NAME, idMapping.getGeneratorContainer().getTableGenerator().getName()); - - //change resource model tableGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", idMapping.getGeneratorContainer().getTableGenerator().getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(TABLE_GENERATOR_NAME, idMapping.getGeneratorContainer().getTableGenerator().getName()); - - idMapping.getGeneratorContainer().getTableGenerator().setName("foo"); - - assertEquals("foo", idMapping.getGeneratorContainer().getTableGenerator().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("foo", tableGenerator.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(TABLE_GENERATOR_NAME, idMapping.getGeneratorContainer().getTableGenerator().getName()); - - idMapping.getGeneratorContainer().getTableGenerator().setName(null); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertNull(tableGenerator); - } - - public void testGetCatalog() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getCatalog()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setCatalog("myCatalog"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myCatalog", idMapping.getGeneratorContainer().getTableGenerator().getCatalog()); - assertEquals("myCatalog", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedCatalog()); - } - - public void testGetDefaultCatalog() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultCatalog()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedCatalog("myCatalog"); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultCatalog()); - assertEquals("myCatalog", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedCatalog()); - } - - public void testSetSpecifiedCatalog() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedCatalog("myCatalog"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("myCatalog", tableGenerator.getCatalog()); - - idMapping.getGeneratorContainer().getTableGenerator().setName(null); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedCatalog(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - public void testGetSchema() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getSchema()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setSchema("mySchema"); - getJpaProject().synchronizeContextModel(); - - assertEquals("mySchema", idMapping.getGeneratorContainer().getTableGenerator().getSchema()); - assertEquals("mySchema", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedSchema()); - } - - public void testGetDefaultSchema() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultSchema()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedSchema("mySchema"); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultSchema()); - assertEquals("mySchema", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - createTestEntityWithTableGenerator(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - IdMapping idMapping = (IdMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultSchema()); - - getEntityMappings().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", idMapping.getGeneratorContainer().getTableGenerator().getDefaultSchema()); - - getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", idMapping.getGeneratorContainer().getTableGenerator().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedSchema("XML_SCHEMA"); - assertEquals("BAR", idMapping.getGeneratorContainer().getTableGenerator().getDefaultSchema()); - - getEntityMappings().removePersistentType(0); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //default schema taken from persistence-unit-defaults not entity-mappings since the entity is not in an orm.xml file - assertEquals("FOO", ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator().getDefaultSchema()); - } - - public void testSetSpecifiedSchema() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedSchema("mySchema"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("mySchema", tableGenerator.getSchema()); - - idMapping.getGeneratorContainer().getTableGenerator().setName(null); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedSchema(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - public void testGetPkColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getPkColumnName()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setPkColumnName("myPkColumnName"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myPkColumnName", idMapping.getGeneratorContainer().getTableGenerator().getPkColumnName()); - assertEquals("myPkColumnName", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedPkColumnName()); - } - - public void testGetDefaultPkColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultPkColumnName()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedPkColumnName("myPkColumnName"); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultPkColumnName()); - assertEquals("myPkColumnName", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedPkColumnName()); - } - - public void testSetSpecifiedPkColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedPkColumnName("myPkColumnName"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("myPkColumnName", tableGenerator.getPkColumnName()); - - idMapping.getGeneratorContainer().getTableGenerator().setName(null); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedPkColumnName(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - public void testGetValueColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getValueColumnName()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setValueColumnName("myValueColumnName"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myValueColumnName", idMapping.getGeneratorContainer().getTableGenerator().getValueColumnName()); - assertEquals("myValueColumnName", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedValueColumnName()); - } - - public void testGetDefaultValueColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultValueColumnName()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedValueColumnName("myValueColumnName"); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultValueColumnName()); - assertEquals("myValueColumnName", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedValueColumnName()); - } - - public void testSetSpecifiedValueColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedValueColumnName("myValueColumnName"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("myValueColumnName", tableGenerator.getValueColumnName()); - - idMapping.getGeneratorContainer().getTableGenerator().setName(null); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedValueColumnName(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - public void testGetPkColumnValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getPkColumnValue()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setPkColumnValue("myPkColumnValue"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myPkColumnValue", idMapping.getGeneratorContainer().getTableGenerator().getPkColumnValue()); - assertEquals("myPkColumnValue", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedPkColumnValue()); - } - - public void testGetDefaultPkColumnValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultPkColumnValue()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedPkColumnValue("myPkColumnValue"); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator().getDefaultPkColumnValue()); - assertEquals("myPkColumnValue", idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedPkColumnValue()); - } - - public void testSetSpecifiedPkColumnValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedPkColumnValue("myPkColumnValue"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("myPkColumnValue", tableGenerator.getPkColumnValue()); - - idMapping.getGeneratorContainer().getTableGenerator().setName(null); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedPkColumnValue(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - public void testGetInitialValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(TableGenerator.DEFAULT_INITIAL_VALUE, idMapping.getGeneratorContainer().getTableGenerator().getInitialValue()); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setInitialValue(Integer.valueOf(82)); - getJpaProject().synchronizeContextModel(); - - assertEquals(82, idMapping.getGeneratorContainer().getTableGenerator().getInitialValue()); - assertEquals(Integer.valueOf(82), idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedInitialValue()); - } - - public void testGetDefaultInitialValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(TableGenerator.DEFAULT_INITIAL_VALUE, idMapping.getGeneratorContainer().getTableGenerator().getDefaultInitialValue()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedInitialValue(Integer.valueOf(82)); - - assertEquals(TableGenerator.DEFAULT_INITIAL_VALUE, idMapping.getGeneratorContainer().getTableGenerator().getDefaultInitialValue()); - assertEquals(Integer.valueOf(82), idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedInitialValue()); - } - - public void testSetSpecifiedInitialValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedInitialValue(Integer.valueOf(20)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(Integer.valueOf(20), tableGenerator.getInitialValue()); - - idMapping.getGeneratorContainer().getTableGenerator().setName(null); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedInitialValue(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - public void testGetAllocationSize() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getGeneratorContainer().getTableGenerator().getAllocationSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setAllocationSize(Integer.valueOf(20)); - getJpaProject().synchronizeContextModel(); - - assertEquals(20, idMapping.getGeneratorContainer().getTableGenerator().getAllocationSize()); - assertEquals(Integer.valueOf(20), idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedAllocationSize()); - } - - public void testGetDefaultAllocationSize() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getGeneratorContainer().getTableGenerator().getDefaultAllocationSize()); - - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedAllocationSize(Integer.valueOf(20)); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getGeneratorContainer().getTableGenerator().getDefaultAllocationSize()); - assertEquals(Integer.valueOf(20), idMapping.getGeneratorContainer().getTableGenerator().getSpecifiedAllocationSize()); - } - - public void testSetSpecifiedAllocationSize() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedAllocationSize(Integer.valueOf(25)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(Integer.valueOf(25), tableGenerator.getAllocationSize()); - - idMapping.getGeneratorContainer().getTableGenerator().setName(null); - idMapping.getGeneratorContainer().getTableGenerator().setSpecifiedAllocationSize(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - - public void testUniqueConstraints() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - - ListIterator<JavaUniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - tableGeneratorAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - tableGeneratorAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - getJpaProject().synchronizeContextModel(); - - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - - assertEquals(0, tableGenerator.uniqueConstraintsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - tableGeneratorAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - tableGeneratorAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - getJpaProject().synchronizeContextModel(); - assertEquals(2, tableGenerator.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = tableGeneratorAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = tableGeneratorAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(3, tableGeneratorAnnotation.uniqueConstraintsSize()); - - tableGenerator.removeUniqueConstraint(1); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator<UniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - tableGenerator.removeUniqueConstraint(1); - uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - tableGenerator.removeUniqueConstraint(0); - uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(3, tableGeneratorAnnotation.uniqueConstraintsSize()); - - - tableGenerator.moveUniqueConstraint(2, 0); - ListIterator<UniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - tableGenerator.moveUniqueConstraint(0, 1); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getGeneratorContainer().getTableGenerator(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGeneratorAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - tableGeneratorAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - tableGeneratorAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<UniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.moveUniqueConstraint(2, 0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.moveUniqueConstraint(0, 1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.removeUniqueConstraint(0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableTests.java deleted file mode 100644 index 006c5a20b7..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableTests.java +++ /dev/null @@ -1,610 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaTableTests extends ContextModelTestCase -{ - private static final String TABLE_NAME = "MY_TABLE"; - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Table(name=\"" + TABLE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestSubType() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - }); - } - - private ICompilationUnit createAbstractTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)").append(CR); - sb.append("abstract"); - } - }); - } - - - public JavaTableTests(String name) { - super(name); - } - - public void testGetSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getTable().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TABLE_NAME, getJavaEntity().getTable().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getTable().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getTable().getDefaultName()); - - //test that setting the java entity name will change the table default name - getJavaEntity().setSpecifiedName("foo"); - assertEquals("foo", getJavaEntity().getTable().getDefaultName()); - } - - public void testGetDefaultNameSingleTableInheritance() throws Exception { - createTestEntity(); - createTestSubType(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - - assertNotSame(getJavaEntity(), rootEntity); - assertEquals(TYPE_NAME, childEntity.getTable().getDefaultName()); - assertEquals(TYPE_NAME, rootEntity.getTable().getDefaultName()); - - //test that setting the root java entity name will change the table default name of the child - rootEntity.setSpecifiedName("foo"); - assertEquals("foo", childEntity.getTable().getDefaultName()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - JavaEntity javaEntity = ormEntity.getJavaEntity(); - - assertNull(javaEntity.getTable().getDefaultSchema()); - - getEntityMappings().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", javaEntity.getTable().getDefaultSchema()); - - getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", javaEntity.getTable().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedSchema("XML_SCHEMA"); - assertEquals("BAR", javaEntity.getTable().getDefaultSchema()); - - getEntityMappings().removePersistentType(0); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //default schema taken from persistence-unit-defaults not entity-mappings since the entity is not in an orm.xml file - assertEquals("FOO", getJavaEntity().getTable().getDefaultSchema()); - - IFile file = getOrmXmlResource().getFile(); - //remove the mapping file reference from the persistence.xml. default schema - //should still come from persistence-unit-defaults because of implied mapped-file-ref - getXmlPersistenceUnit().getMappingFiles().remove(mappingFileRef); - assertEquals("FOO", getJavaEntity().getTable().getDefaultSchema()); - - file.delete(true, null); - assertNull(getJavaEntity().getTable().getDefaultSchema()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getTable().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TABLE_NAME, getJavaEntity().getTable().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().getTable().setSpecifiedName("foo"); - - assertEquals("foo", getJavaEntity().getTable().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals("foo", table.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().getTable().setSpecifiedName(null); - - assertNull(getJavaEntity().getTable().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertNull(table); - } - - public void testUpdateFromSpecifiedNameChangeInResourceModel() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - table.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", getJavaEntity().getTable().getSpecifiedName()); - - typeResource.removeAnnotation(JPA.TABLE); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getTable().getSpecifiedName()); - } - - public void testGetCatalog() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.setCatalog("myCatalog"); - getJpaProject().synchronizeContextModel(); - - assertEquals("myCatalog", getJavaEntity().getTable().getSpecifiedCatalog()); - assertEquals("myCatalog", getJavaEntity().getTable().getCatalog()); - } - - public void testGetDefaultCatalog() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getTable().getDefaultCatalog()); - - getJavaEntity().getTable().setSpecifiedCatalog("myCatalog"); - - assertNull(getJavaEntity().getTable().getDefaultCatalog()); - } - - public void testUpdateDefaultCatalogFromPersistenceUnitDefaults() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - createTestEntity(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - JavaEntity javaEntity = ormEntity.getJavaEntity(); - - assertNull(javaEntity.getTable().getDefaultCatalog()); - - getEntityMappings().getPersistenceUnitDefaults().setSpecifiedCatalog("FOO"); - assertEquals("FOO", javaEntity.getTable().getDefaultCatalog()); - - getEntityMappings().setSpecifiedCatalog("BAR"); - assertEquals("BAR", javaEntity.getTable().getDefaultCatalog()); - - ormEntity.getTable().setSpecifiedCatalog("XML_CATALOG"); - assertEquals("BAR", javaEntity.getTable().getDefaultCatalog()); - - getEntityMappings().removePersistentType(0); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //default catalog taken from persistence-unite-defaults not entity-mappings since the entity is not in an orm.xml file - assertEquals("FOO", getJavaEntity().getTable().getDefaultCatalog()); - - IFile file = getOrmXmlResource().getFile(); - //remove the mapping file reference from the persistence.xml. default schema - //should still come from persistence-unit-defaults because of implied mapped-file-ref - getXmlPersistenceUnit().getMappingFiles().remove(mappingFileRef); - assertEquals("FOO", getJavaEntity().getTable().getDefaultCatalog()); - - file.delete(true, null); - assertNull(getJavaEntity().getTable().getDefaultCatalog()); - } - - public void testSetSpecifiedCatalog() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Table table = getJavaEntity().getTable(); - table.setSpecifiedCatalog("myCatalog"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableResource = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals("myCatalog", tableResource.getCatalog()); - - table.setSpecifiedCatalog(null); - assertNull(typeResource.getAnnotation(JPA.TABLE)); - } - - public void testGetSchema() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.setSchema("mySchema"); - getJpaProject().synchronizeContextModel(); - - assertEquals("mySchema", getJavaEntity().getTable().getSpecifiedSchema()); - assertEquals("mySchema", getJavaEntity().getTable().getSchema()); - } - - public void testGetDefaultSchema() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getTable().getDefaultSchema()); - - getJavaEntity().getTable().setSpecifiedSchema("mySchema"); - - assertNull(getJavaEntity().getTable().getDefaultSchema()); - } - - public void testSetSpecifiedSchema() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Table table = getJavaEntity().getTable(); - table.setSpecifiedSchema("mySchema"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableResource = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals("mySchema", tableResource.getSchema()); - - table.setSpecifiedSchema(null); - assertNull(typeResource.getAnnotation(JPA.TABLE)); - } - - public void testUniqueConstraints() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<JavaUniqueConstraint> uniqueConstraints = getJavaEntity().getTable().uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - tableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - tableAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - getJpaProject().synchronizeContextModel(); - - uniqueConstraints = getJavaEntity().getTable().uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, getJavaEntity().getTable().uniqueConstraintsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - tableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - tableAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - getJpaProject().synchronizeContextModel(); - assertEquals(2, getJavaEntity().getTable().uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = getJavaEntity().getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(0).addColumnName(0, "BAR"); - table.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = tableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = getJavaEntity().getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = tableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = getJavaEntity().getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals(3, tableAnnotation.uniqueConstraintsSize()); - - table.removeUniqueConstraint(1); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator<UniqueConstraint> uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - table.removeUniqueConstraint(1); - uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - table.removeUniqueConstraint(0); - uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = getJavaEntity().getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals(3, tableAnnotation.uniqueConstraintsSize()); - - - table.moveUniqueConstraint(2, 0); - ListIterator<UniqueConstraint> uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - table.moveUniqueConstraint(0, 1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = getJavaEntity().getTable(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - tableAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - tableAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - tableAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<UniqueConstraint> uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.moveUniqueConstraint(2, 0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.moveUniqueConstraint(0, 1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.removeUniqueConstraint(1); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.removeUniqueConstraint(0); - getJpaProject().synchronizeContextModel(); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAbstractEntityGetDefaultNameTablePerClassInheritance() throws Exception { - createAbstractTestEntity(); - createTestSubType(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity concreteEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals("AnnotationTestTypeChild", concreteEntity.getName()); - - Entity abstractEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals(TYPE_NAME, abstractEntity.getName()); - - - assertEquals(InheritanceType.TABLE_PER_CLASS, abstractEntity.getSpecifiedInheritanceStrategy()); - assertEquals(null, concreteEntity.getSpecifiedInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, concreteEntity.getDefaultInheritanceStrategy()); - - - assertEquals(null, abstractEntity.getTable().getDefaultName()); - assertEquals(null, abstractEntity.getTable().getDefaultCatalog()); - assertEquals(null, abstractEntity.getTable().getDefaultSchema()); - - - assertEquals("AnnotationTestTypeChild", concreteEntity.getTable().getDefaultName()); - assertEquals(null, concreteEntity.getTable().getDefaultCatalog()); - assertEquals(null, concreteEntity.getTable().getDefaultSchema()); - } - -} 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 deleted file mode 100644 index 0757958c30..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java +++ /dev/null @@ -1,248 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaTransientMappingTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithTransientMapping() throws Exception { - 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); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - } - - public void testTransientMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getSpecifiedMapping(); - - assertNotNull(transientMapping); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaVersionMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaVersionMappingTests.java deleted file mode 100644 index a24b991dd1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaVersionMappingTests.java +++ /dev/null @@ -1,401 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaVersionMappingTests extends ContextModelTestCase -{ - private ICompilationUnit createTestEntityWithVersionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.VERSION); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithTemporal() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.VERSION, JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version").append(CR); - sb.append("@Temporal(TemporalType.TIMESTAMP)").append(CR); - } - }); - } - - public JavaVersionMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((IdMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((IdMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - - public void testGetTemporal() throws Exception { - createTestEntityWithTemporal(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) versionMapping.getConverter()).getTemporalType()); - } - - public void testSetTemporal() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getSpecifiedMapping(); - assertEquals(Converter.NO_CONVERTER, versionMapping.getConverter().getType()); - - versionMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getConverter()).setTemporalType(TemporalType.TIME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - versionMapping.setConverter(Converter.NO_CONVERTER); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(Converter.NO_CONVERTER, versionMapping.getConverter().getType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.core.resource.java.TemporalType.DATE); - getJpaProject().synchronizeContextModel(); - - assertEquals(TemporalType.DATE, ((TemporalConverter) versionMapping.getConverter()).getTemporalType()); - - attributeResource.removeAnnotation(TemporalAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertEquals(Converter.NO_CONVERTER, versionMapping.getConverter().getType()); - assertFalse(versionMapping.isDefault()); - assertSame(versionMapping, persistentAttribute.getSpecifiedMapping()); - } - - public void testGetColumn() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(versionMapping.getColumn().getSpecifiedName()); - assertEquals("id", versionMapping.getColumn().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", versionMapping.getColumn().getSpecifiedName()); - assertEquals("foo", versionMapping.getColumn().getName()); - assertEquals("id", versionMapping.getColumn().getDefaultName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JptCoreContextJavaModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JptCoreContextJavaModelTests.java deleted file mode 100644 index bf35f27aa8..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JptCoreContextJavaModelTests.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.core.tests.internal.context.java; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptCoreContextJavaModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptCoreContextJavaModelTests.class.getName()); - suite.addTestSuite(JavaAssociationOverrideTests.class); - suite.addTestSuite(JavaAttributeOverrideTests.class); - suite.addTestSuite(JavaBasicMappingTests.class); - suite.addTestSuite(JavaCascadeTests.class); - suite.addTestSuite(JavaColumnTests.class); - suite.addTestSuite(JavaDiscriminatorColumnTests.class); - suite.addTestSuite(JavaEmbeddableTests.class); - suite.addTestSuite(JavaEmbeddedIdMappingTests.class); - suite.addTestSuite(JavaEmbeddedMappingTests.class); - suite.addTestSuite(JavaEntityTests.class); - suite.addTestSuite(JavaGeneratedValueTests.class); - suite.addTestSuite(JavaIdMappingTests.class); - suite.addTestSuite(JavaJoinColumnTests.class); - suite.addTestSuite(JavaJoinTableTests.class); - suite.addTestSuite(JavaMappedSuperclassTests.class); - suite.addTestSuite(JavaManyToManyMappingTests.class); - suite.addTestSuite(JavaManyToOneMappingTests.class); - suite.addTestSuite(JavaNamedQueryTests.class); - suite.addTestSuite(JavaNamedNativeQueryTests.class); - suite.addTestSuite(JavaQueryHintTests.class); - suite.addTestSuite(JavaOneToManyMappingTests.class); - suite.addTestSuite(JavaOneToOneMappingTests.class); - suite.addTestSuite(GenericJavaPersistentTypeTests.class); - suite.addTestSuite(GenericJavaPersistentAttributeTests.class); - suite.addTestSuite(JavaPrimaryKeyJoinColumnTests.class); - suite.addTestSuite(JavaSecondaryTableTests.class); - suite.addTestSuite(JavaSequenceGeneratorTests.class); - suite.addTestSuite(JavaTableGeneratorTests.class); - suite.addTestSuite(JavaTableTests.class); - suite.addTestSuite(JavaTransientMappingTests.class); - suite.addTestSuite(JavaVersionMappingTests.class); - return suite; - } - - private JptCoreContextJavaModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} |