diff options
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm')
36 files changed, 0 insertions, 19039 deletions
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/EntityMappingsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/EntityMappingsTests.java deleted file mode 100644 index cc8b88427b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/EntityMappingsTests.java +++ /dev/null @@ -1,1067 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.ListIterator; -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.SequenceGenerator; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -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.CollectionTools; - -public class EntityMappingsTests extends ContextModelTestCase -{ - public EntityMappingsTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testGetVersion() throws Exception { - assertEquals("1.0", entityMappings().getVersion()); - } - - public void testUpdateDescription() throws Exception { - assertNull(entityMappings().getDescription()); - assertNull(ormResource().getEntityMappings().getDescription()); - - //set description in the resource model, verify context model updated - ormResource().getEntityMappings().setDescription("newDescription"); - assertEquals("newDescription", entityMappings().getDescription()); - assertEquals("newDescription", ormResource().getEntityMappings().getDescription()); - - //set description to null in the resource model - ormResource().getEntityMappings().setDescription(null); - assertNull(entityMappings().getDescription()); - assertNull(ormResource().getEntityMappings().getDescription()); - } - - public void testModifyDescription() throws Exception { - assertNull(entityMappings().getDescription()); - assertNull(ormResource().getEntityMappings().getDescription()); - - //set description in the context model, verify resource model modified - entityMappings().setDescription("newDescription"); - assertEquals("newDescription", entityMappings().getDescription()); - assertEquals("newDescription", ormResource().getEntityMappings().getDescription()); - - //set description to null in the context model - entityMappings().setDescription(null); - assertNull(entityMappings().getDescription()); - assertNull(ormResource().getEntityMappings().getDescription()); - } - - public void testUpdatePackage() throws Exception { - assertNull(entityMappings().getPackage()); - assertNull(ormResource().getEntityMappings().getPackage()); - - //set package in the resource model, verify context model updated - ormResource().getEntityMappings().setPackage("foo.model"); - assertEquals("foo.model", entityMappings().getPackage()); - assertEquals("foo.model", ormResource().getEntityMappings().getPackage()); - - //set package to null in the resource model - ormResource().getEntityMappings().setPackage(null); - assertNull(entityMappings().getPackage()); - assertNull(ormResource().getEntityMappings().getPackage()); - } - - public void testModifyPackage() throws Exception { - assertNull(entityMappings().getPackage()); - assertNull(ormResource().getEntityMappings().getPackage()); - - //set package in the context model, verify resource model modified - entityMappings().setPackage("foo.model"); - assertEquals("foo.model", entityMappings().getPackage()); - assertEquals("foo.model", ormResource().getEntityMappings().getPackage()); - - //set package to null in the context model - entityMappings().setPackage(null); - assertNull(entityMappings().getPackage()); - assertNull(ormResource().getEntityMappings().getPackage()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - - //set schema in the resource model, verify context model updated - ormResource().getEntityMappings().setSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", entityMappings().getSpecifiedSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getSchema()); - - //set schema to null in the resource model - ormResource().getEntityMappings().setSchema(null); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - } - - public void testModifySpecifiedSchema() throws Exception { - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - - //set schema in the context model, verify resource model modified - entityMappings().setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", entityMappings().getSpecifiedSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getSchema()); - - //set schema to null in the context model - entityMappings().setSpecifiedSchema(null); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - - //set catalog in the resource model, verify context model updated - ormResource().getEntityMappings().setCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", entityMappings().getSpecifiedCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getCatalog()); - - //set catalog to null in the resource model - ormResource().getEntityMappings().setCatalog(null); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - } - - public void testUpdateDefaultSchema() throws Exception { - assertNull(entityMappings().getDefaultSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults persistenceUnitDefaults = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(persistenceUnitDefaults); - persistenceUnitDefaults.setSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", entityMappings().getDefaultSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - persistenceUnitDefaults.setSchema(null); - assertNull(entityMappings().getDefaultSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - } - - public void testUpdateSchema() throws Exception { - assertNull(entityMappings().getDefaultSchema()); - assertNull(entityMappings().getSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - - ormResource().getEntityMappings().setSchema("MY_SCHEMA"); - assertNull(entityMappings().getDefaultSchema()); - assertEquals("MY_SCHEMA", entityMappings().getSchema()); - assertEquals("MY_SCHEMA", entityMappings().getSpecifiedSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getSchema()); - - ormResource().getEntityMappings().setSchema(null); - assertNull(entityMappings().getDefaultSchema()); - assertNull(entityMappings().getSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("DEFAULT_SCHEMA"); - assertEquals("DEFAULT_SCHEMA", entityMappings().getDefaultSchema()); - assertEquals("DEFAULT_SCHEMA", entityMappings().getSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema(null); - assertNull(entityMappings().getDefaultSchema()); - assertNull(entityMappings().getSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - } - - public void testModifySpecifiedCatalog() throws Exception { - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - - //set catalog in the context model, verify resource model modified - entityMappings().setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", entityMappings().getSpecifiedCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getCatalog()); - - //set catalog to null in the context model - entityMappings().setSpecifiedCatalog(null); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - } - - public void testUpdateDefaultCatalog() throws Exception { - assertNull(entityMappings().getDefaultCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults persistenceUnitDefaults = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(persistenceUnitDefaults); - persistenceUnitDefaults.setCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", entityMappings().getDefaultCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - persistenceUnitDefaults.setCatalog(null); - assertNull(entityMappings().getDefaultCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - } - - public void testUpdateCatalog() throws Exception { - assertNull(entityMappings().getDefaultCatalog()); - assertNull(entityMappings().getCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - - ormResource().getEntityMappings().setCatalog("MY_CATALOG"); - assertNull(entityMappings().getDefaultCatalog()); - assertEquals("MY_CATALOG", entityMappings().getCatalog()); - assertEquals("MY_CATALOG", entityMappings().getSpecifiedCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getCatalog()); - - ormResource().getEntityMappings().setCatalog(null); - assertNull(entityMappings().getDefaultCatalog()); - assertNull(entityMappings().getCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog("DEFAULT_CATALOG"); - assertEquals("DEFAULT_CATALOG", entityMappings().getDefaultCatalog()); - assertEquals("DEFAULT_CATALOG", entityMappings().getCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog(null); - assertNull(entityMappings().getDefaultCatalog()); - assertNull(entityMappings().getCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - } - - public void testUpdateSpecifiedAccess() throws Exception { - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - //set access in the resource model, verify context model updated - ormResource().getEntityMappings().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, entityMappings().getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, ormResource().getEntityMappings().getAccess()); - - //set access to null in the resource model - ormResource().getEntityMappings().setAccess(null); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - } - - public void testModifySpecifiedAccess() throws Exception { - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - //set access in the context model, verify resource model modified - entityMappings().setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, entityMappings().getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, ormResource().getEntityMappings().getAccess()); - - //set access to null in the context model - entityMappings().setSpecifiedAccess(null); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - } - - public void testUpdateDefaultAccess() throws Exception { - assertNull(entityMappings().getDefaultAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults persistenceUnitDefaults = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(persistenceUnitDefaults); - persistenceUnitDefaults.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, entityMappings().getDefaultAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - persistenceUnitDefaults.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, entityMappings().getDefaultAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - persistenceUnitDefaults.setAccess(null); - assertNull(entityMappings().getDefaultAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - } - - public void testUpdateAccess() throws Exception { - assertNull(entityMappings().getAccess()); - assertNull(entityMappings().getDefaultAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - ormResource().getEntityMappings().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertNull(entityMappings().getDefaultAccess()); - assertEquals(AccessType.FIELD, entityMappings().getAccess()); - assertEquals(AccessType.FIELD, entityMappings().getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, ormResource().getEntityMappings().getAccess()); - - ormResource().getEntityMappings().setAccess(null); - assertNull(entityMappings().getAccess()); - assertNull(entityMappings().getDefaultAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, entityMappings().getDefaultAccess()); - assertEquals(AccessType.FIELD, entityMappings().getAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertNull(entityMappings().getDefaultAccess()); - assertNull(entityMappings().getAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - } - - - public void testUpdateOrmPersistentTypes() throws Exception { - assertFalse(entityMappings().ormPersistentTypes().hasNext()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - - //add embeddable in the resource model, verify context model updated - XmlEmbeddable embeddable = OrmFactory.eINSTANCE.createXmlEmbeddable(); - ormResource().getEntityMappings().getEmbeddables().add(embeddable); - embeddable.setClassName("model.Foo"); - assertTrue(entityMappings().ormPersistentTypes().hasNext()); - assertEquals("model.Foo", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo", ormResource().getEntityMappings().getEmbeddables().get(0).getClassName()); - - //add entity in the resource model, verify context model updated - XmlEntity entity = OrmFactory.eINSTANCE.createXmlEntity(); - ormResource().getEntityMappings().getEntities().add(entity); - entity.setClassName("model.Foo2"); - assertTrue(entityMappings().ormPersistentTypes().hasNext()); - assertEquals("model.Foo2", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo2", ormResource().getEntityMappings().getEntities().get(0).getClassName()); - - //add mapped-superclass in the resource model, verify context model updated - XmlMappedSuperclass mappedSuperclass = OrmFactory.eINSTANCE.createXmlMappedSuperclass(); - ormResource().getEntityMappings().getMappedSuperclasses().add(mappedSuperclass); - mappedSuperclass.setClassName("model.Foo3"); - assertTrue(entityMappings().ormPersistentTypes().hasNext()); - assertEquals("model.Foo3", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); - assertFalse(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo3", ormResource().getEntityMappings().getMappedSuperclasses().get(0).getClassName()); - } - - - public void testAddOrmPersistentType() throws Exception { - assertFalse(entityMappings().ormPersistentTypes().hasNext()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - - //add embeddable in the context model, verify resource model modified - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - assertTrue(entityMappings().ormPersistentTypes().hasNext()); - assertEquals("model.Foo", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, entityMappings().ormPersistentTypes().next().getMapping().getKey()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo", ormResource().getEntityMappings().getEmbeddables().get(0).getClassName()); - - //add entity in the context model, verify resource model modified - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - assertTrue(entityMappings().ormPersistentTypes().hasNext()); - assertEquals("model.Foo2", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, entityMappings().ormPersistentTypes().next().getMapping().getKey()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo2", ormResource().getEntityMappings().getEntities().get(0).getClassName()); - - //add mapped-superclass in the context model, verify resource model modified - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo3"); - assertTrue(entityMappings().ormPersistentTypes().hasNext()); - assertEquals("model.Foo3", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, entityMappings().ormPersistentTypes().next().getMapping().getKey()); - assertFalse(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo3", ormResource().getEntityMappings().getMappedSuperclasses().get(0).getClassName()); - } - - public void testRemoveOrmPersistentType() throws Exception { - assertFalse(entityMappings().ormPersistentTypes().hasNext()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo3"); - - //remove ormPersistentType from the context model, verify resource model modified - entityMappings().removeOrmPersistentType(1); - assertFalse(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - - entityMappings().removeOrmPersistentType(1); - assertFalse(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - - entityMappings().removeOrmPersistentType(0); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - } - - public void testUpdateTableGenerators() throws Exception { - assertEquals(0, entityMappings().tableGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getTableGenerators().size()); - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - XmlTableGenerator tableGeneratorResource = OrmFactory.eINSTANCE.createXmlTableGeneratorImpl(); - ormResource().getEntityMappings().getTableGenerators().add(tableGeneratorResource); - tableGeneratorResource.setName("FOO"); - - TableGenerator tableGenerator = entityMappings().tableGenerators().next(); - assertEquals("FOO", tableGenerator.getName()); - assertEquals(1, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - XmlTableGenerator tableGeneratorResource2 = OrmFactory.eINSTANCE.createXmlTableGeneratorImpl(); - ormResource().getEntityMappings().getTableGenerators().add(0, tableGeneratorResource2); - tableGeneratorResource2.setName("BAR"); - - ListIterator<OrmTableGenerator> tableGenerators = entityMappings().tableGenerators(); - assertEquals("BAR", tableGenerators.next().getName()); - assertEquals("FOO", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(2, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - XmlTableGenerator tableGeneratorResource3 = OrmFactory.eINSTANCE.createXmlTableGeneratorImpl(); - ormResource().getEntityMappings().getTableGenerators().add(1, tableGeneratorResource3); - tableGeneratorResource3.setName("BAZ"); - - tableGenerators = entityMappings().tableGenerators(); - assertEquals("BAR", tableGenerators.next().getName()); - assertEquals("BAZ", tableGenerators.next().getName()); - assertEquals("FOO", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(3, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getTableGenerators().move(2, 0); - tableGenerators = entityMappings().tableGenerators(); - assertEquals("BAZ", tableGenerators.next().getName()); - assertEquals("FOO", tableGenerators.next().getName()); - assertEquals("BAR", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(3, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getTableGenerators().remove(0); - tableGenerators = entityMappings().tableGenerators(); - assertEquals("FOO", tableGenerators.next().getName()); - assertEquals("BAR", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(2, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getTableGenerators().remove(1); - tableGenerators = entityMappings().tableGenerators(); - assertEquals("FOO", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(1, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getTableGenerators().clear(); - tableGenerators = entityMappings().tableGenerators(); - assertFalse(tableGenerators.hasNext()); - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - } - - public void testAddTableGenerator() throws Exception { - assertEquals(0, entityMappings().tableGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getTableGenerators().size()); - entityMappings().addTableGenerator(0).setName("FOO"); - - assertEquals("FOO", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - - entityMappings().addTableGenerator(0).setName("BAR"); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getTableGenerators().get(1).getName()); - assertEquals(2, ormResource().getEntityMappings().getTableGenerators().size()); - - ListIterator<OrmTableGenerator> tableGenerators = entityMappings().tableGenerators(); - assertEquals("BAR", tableGenerators.next().getName()); - assertEquals("FOO", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - } - - public void testRemoveTableGenerator() throws Exception { - assertEquals(0, entityMappings().tableGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getTableGenerators().size()); - - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - tableGenerator.setName("FOO"); - TableGenerator tableGenerator2 = entityMappings().addTableGenerator(1); - tableGenerator2.setName("BAR"); - TableGenerator tableGenerator3 = entityMappings().addTableGenerator(2); - tableGenerator3.setName("BAZ"); - assertEquals("FOO", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(1).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getTableGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getTableGenerators().size()); - - entityMappings().removeTableGenerator(0); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getTableGenerators().get(1).getName()); - - ListIterator<OrmTableGenerator> tableGenerators = entityMappings().tableGenerators(); - OrmTableGenerator xmlTableGenerator = tableGenerators.next(); - assertEquals("BAR", xmlTableGenerator.getName()); - assertEquals(tableGenerator2, xmlTableGenerator); - xmlTableGenerator = tableGenerators.next(); - assertEquals("BAZ", xmlTableGenerator.getName()); - assertEquals(tableGenerator3, xmlTableGenerator); - assertFalse(tableGenerators.hasNext()); - - - entityMappings().removeTableGenerator(1); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - tableGenerators = entityMappings().tableGenerators(); - xmlTableGenerator = tableGenerators.next(); - assertEquals("BAR", xmlTableGenerator.getName()); - assertEquals(tableGenerator2, xmlTableGenerator); - assertFalse(tableGenerators.hasNext()); - - - entityMappings().removeTableGenerator(0); - assertEquals(0, ormResource().getEntityMappings().getTableGenerators().size()); - tableGenerators = entityMappings().tableGenerators(); - assertFalse(tableGenerators.hasNext()); - } - - public void testMoveTableGenerator() throws Exception { - assertEquals(0, entityMappings().tableGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getTableGenerators().size()); - - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - tableGenerator.setName("FOO"); - TableGenerator tableGenerator2 = entityMappings().addTableGenerator(1); - tableGenerator2.setName("BAR"); - TableGenerator tableGenerator3 = entityMappings().addTableGenerator(2); - tableGenerator3.setName("BAZ"); - assertEquals("FOO", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(1).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getTableGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getTableGenerators().size()); - - entityMappings().moveTableGenerator(2, 0); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getTableGenerators().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getTableGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getTableGenerators().size()); - - entityMappings().moveTableGenerator(0, 2); - assertEquals("FOO", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(1).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getTableGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getTableGenerators().size()); - } - - public void testTableGeneratorsSize() throws Exception { - assertEquals(0, entityMappings().tableGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getTableGenerators().size()); - - - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - tableGenerator.setName("FOO"); - TableGenerator tableGenerator2 = entityMappings().addTableGenerator(1); - tableGenerator2.setName("BAR"); - TableGenerator tableGenerator3 = entityMappings().addTableGenerator(2); - tableGenerator3.setName("BAZ"); - - assertEquals(3, entityMappings().tableGeneratorsSize()); - - ormResource().getEntityMappings().getTableGenerators().remove(0); - assertEquals(2, entityMappings().tableGeneratorsSize()); - } - - public void testUpdateSequenceGenerators() throws Exception { - assertEquals(0, entityMappings().sequenceGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getSequenceGenerators().size()); - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - XmlSequenceGenerator sequenceGeneratorResource = OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl(); - ormResource().getEntityMappings().getSequenceGenerators().add(sequenceGeneratorResource); - sequenceGeneratorResource.setName("FOO"); - - SequenceGenerator sequenceGenerator = entityMappings().sequenceGenerators().next(); - assertEquals("FOO", sequenceGenerator.getName()); - assertEquals(1, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - XmlSequenceGenerator sequenceGeneratorResource2 = OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl(); - ormResource().getEntityMappings().getSequenceGenerators().add(0, sequenceGeneratorResource2); - sequenceGeneratorResource2.setName("BAR"); - - ListIterator<OrmSequenceGenerator> sequenceGenerators = entityMappings().sequenceGenerators(); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(2, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - XmlSequenceGenerator sequenceGeneratorResource3 = OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl(); - ormResource().getEntityMappings().getSequenceGenerators().add(1, sequenceGeneratorResource3); - sequenceGeneratorResource3.setName("BAZ"); - - sequenceGenerators = entityMappings().sequenceGenerators(); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertEquals("BAZ", sequenceGenerators.next().getName()); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(3, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getSequenceGenerators().move(2, 0); - sequenceGenerators = entityMappings().sequenceGenerators(); - assertEquals("BAZ", sequenceGenerators.next().getName()); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - - ormResource().getEntityMappings().getSequenceGenerators().remove(0); - sequenceGenerators = entityMappings().sequenceGenerators(); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(2, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getSequenceGenerators().remove(1); - sequenceGenerators = entityMappings().sequenceGenerators(); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(1, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getSequenceGenerators().clear(); - sequenceGenerators = entityMappings().sequenceGenerators(); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - } - - public void testAddSequenceGenerator() throws Exception { - assertEquals(0, entityMappings().sequenceGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getSequenceGenerators().size()); - - entityMappings().addSequenceGenerator(0).setName("FOO"); - - assertEquals("FOO", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - - entityMappings().addSequenceGenerator(0).setName("BAR"); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals(2, ormResource().getEntityMappings().getSequenceGenerators().size()); - - ListIterator<OrmSequenceGenerator> sequenceGenerators = entityMappings().sequenceGenerators(); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - } - - public void testRemoveSequenceGenerator() throws Exception { - assertEquals(0, entityMappings().sequenceGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getSequenceGenerators().size()); - - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - sequenceGenerator.setName("FOO"); - SequenceGenerator sequenceGenerator2 = entityMappings().addSequenceGenerator(1); - sequenceGenerator2.setName("BAR"); - SequenceGenerator sequenceGenerator3 = entityMappings().addSequenceGenerator(2); - sequenceGenerator3.setName("BAZ"); - assertEquals("FOO", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getSequenceGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getSequenceGenerators().size()); - - entityMappings().removeSequenceGenerator(0); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getSequenceGenerators().get(1).getName()); - - ListIterator<OrmSequenceGenerator> sequenceGenerators = entityMappings().sequenceGenerators(); - SequenceGenerator xmlSequenceGenerator = sequenceGenerators.next(); - assertEquals("BAR", xmlSequenceGenerator.getName()); - assertEquals(sequenceGenerator2, xmlSequenceGenerator); - xmlSequenceGenerator = sequenceGenerators.next(); - assertEquals("BAZ", xmlSequenceGenerator.getName()); - assertEquals(sequenceGenerator3, xmlSequenceGenerator); - assertFalse(sequenceGenerators.hasNext()); - - - entityMappings().removeSequenceGenerator(1); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - sequenceGenerators = entityMappings().sequenceGenerators(); - xmlSequenceGenerator = sequenceGenerators.next(); - assertEquals("BAR", xmlSequenceGenerator.getName()); - assertEquals(sequenceGenerator2, xmlSequenceGenerator); - assertFalse(sequenceGenerators.hasNext()); - - - entityMappings().removeSequenceGenerator(0); - assertEquals(0, ormResource().getEntityMappings().getSequenceGenerators().size()); - sequenceGenerators = entityMappings().sequenceGenerators(); - assertFalse(sequenceGenerators.hasNext()); - } - - public void testMoveSequenceGenerator() throws Exception { - assertEquals(0, entityMappings().sequenceGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getSequenceGenerators().size()); - - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - sequenceGenerator.setName("FOO"); - SequenceGenerator sequenceGenerator2 = entityMappings().addSequenceGenerator(1); - sequenceGenerator2.setName("BAR"); - SequenceGenerator sequenceGenerator3 = entityMappings().addSequenceGenerator(2); - sequenceGenerator3.setName("BAZ"); - assertEquals("FOO", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getSequenceGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getSequenceGenerators().size()); - - entityMappings().moveSequenceGenerator(2, 0); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getSequenceGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getSequenceGenerators().size()); - - entityMappings().moveSequenceGenerator(0, 2); - assertEquals("FOO", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getSequenceGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getSequenceGenerators().size()); - - } - - public void testSequenceGeneratorsSize() throws Exception { - assertEquals(0, entityMappings().sequenceGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getSequenceGenerators().size()); - - - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - sequenceGenerator.setName("FOO"); - SequenceGenerator sequenceGenerator2 = entityMappings().addSequenceGenerator(1); - sequenceGenerator2.setName("BAR"); - SequenceGenerator sequenceGenerator3 = entityMappings().addSequenceGenerator(2); - sequenceGenerator3.setName("BAZ"); - - assertEquals(3, entityMappings().sequenceGeneratorsSize()); - - ormResource().getEntityMappings().getSequenceGenerators().remove(0); - assertEquals(2, entityMappings().sequenceGeneratorsSize()); - } - - - public void testAddNamedQuery() throws Exception { - OrmNamedQuery namedQuery = entityMappings().addNamedQuery(0); - namedQuery.setName("FOO"); - - assertEquals("FOO", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - - OrmNamedQuery namedQuery2 = entityMappings().addNamedQuery(0); - namedQuery2.setName("BAR"); - - assertEquals("BAR", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedQueries().get(1).getName()); - - OrmNamedQuery namedQuery3 = entityMappings().addNamedQuery(1); - namedQuery3.setName("BAZ"); - - assertEquals("BAR", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedQueries().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedQueries().get(2).getName()); - - ListIterator<OrmNamedQuery> namedQueries = entityMappings().namedQueries(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery, namedQueries.next()); - - namedQueries = entityMappings().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - } - - public void testRemoveNamedQuery() throws Exception { - entityMappings().addNamedQuery(0).setName("FOO"); - entityMappings().addNamedQuery(1).setName("BAR"); - entityMappings().addNamedQuery(2).setName("BAZ"); - - assertEquals(3, ormResource().getEntityMappings().getNamedQueries().size()); - - entityMappings().removeNamedQuery(0); - assertEquals(2, ormResource().getEntityMappings().getNamedQueries().size()); - assertEquals("BAR", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedQueries().get(1).getName()); - - entityMappings().removeNamedQuery(0); - assertEquals(1, ormResource().getEntityMappings().getNamedQueries().size()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - - entityMappings().removeNamedQuery(0); - assertEquals(0, ormResource().getEntityMappings().getNamedQueries().size()); - } - - public void testMoveNamedQuery() throws Exception { - entityMappings().addNamedQuery(0).setName("FOO"); - entityMappings().addNamedQuery(1).setName("BAR"); - entityMappings().addNamedQuery(2).setName("BAZ"); - - assertEquals(3, ormResource().getEntityMappings().getNamedQueries().size()); - - - entityMappings().moveNamedQuery(2, 0); - ListIterator<OrmNamedQuery> namedQueries = entityMappings().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAR", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedQueries().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedQueries().get(2).getName()); - - - entityMappings().moveNamedQuery(0, 1); - namedQueries = entityMappings().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAZ", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getNamedQueries().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedQueries().get(2).getName()); - } - - public void testUpdateNamedQueries() throws Exception { - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - ormResource().getEntityMappings().getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - ormResource().getEntityMappings().getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - - ormResource().getEntityMappings().getNamedQueries().get(0).setName("FOO"); - ormResource().getEntityMappings().getNamedQueries().get(1).setName("BAR"); - ormResource().getEntityMappings().getNamedQueries().get(2).setName("BAZ"); - - ListIterator<OrmNamedQuery> namedQueries = entityMappings().namedQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedQueries().move(2, 0); - namedQueries = entityMappings().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - ormResource().getEntityMappings().getNamedQueries().move(0, 1); - namedQueries = entityMappings().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - ormResource().getEntityMappings().getNamedQueries().remove(1); - namedQueries = entityMappings().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedQueries().remove(1); - namedQueries = entityMappings().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedQueries().remove(0); - assertFalse(entityMappings().namedQueries().hasNext()); - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - } - - public void testAddNamedNativeQuery() throws Exception { - OrmNamedNativeQuery namedNativeQuery = entityMappings().addNamedNativeQuery(0); - namedNativeQuery.setName("FOO"); - - assertEquals("FOO", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - - OrmNamedNativeQuery namedNativeQuery2 = entityMappings().addNamedNativeQuery(0); - namedNativeQuery2.setName("BAR"); - - assertEquals("BAR", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedNativeQueries().get(1).getName()); - - OrmNamedNativeQuery namedNativeQuery3 = entityMappings().addNamedNativeQuery(1); - namedNativeQuery3.setName("BAZ"); - - assertEquals("BAR", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedNativeQueries().get(2).getName()); - - ListIterator<OrmNamedNativeQuery> namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals(namedNativeQuery2, namedNativeQueries.next()); - assertEquals(namedNativeQuery3, namedNativeQueries.next()); - assertEquals(namedNativeQuery, namedNativeQueries.next()); - - namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - } - - public void testRemoveNamedNativeQuery() throws Exception { - entityMappings().addNamedNativeQuery(0).setName("FOO"); - entityMappings().addNamedNativeQuery(1).setName("BAR"); - entityMappings().addNamedNativeQuery(2).setName("BAZ"); - - assertEquals(3, ormResource().getEntityMappings().getNamedNativeQueries().size()); - - entityMappings().removeNamedNativeQuery(0); - assertEquals(2, ormResource().getEntityMappings().getNamedNativeQueries().size()); - assertEquals("BAR", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedNativeQueries().get(1).getName()); - - entityMappings().removeNamedNativeQuery(0); - assertEquals(1, ormResource().getEntityMappings().getNamedNativeQueries().size()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - - entityMappings().removeNamedNativeQuery(0); - assertEquals(0, ormResource().getEntityMappings().getNamedNativeQueries().size()); - } - - public void testMoveNamedNativeQuery() throws Exception { - entityMappings().addNamedNativeQuery(0).setName("FOO"); - entityMappings().addNamedNativeQuery(1).setName("BAR"); - entityMappings().addNamedNativeQuery(2).setName("BAZ"); - - assertEquals(3, ormResource().getEntityMappings().getNamedNativeQueries().size()); - - - entityMappings().moveNamedNativeQuery(2, 0); - ListIterator<OrmNamedNativeQuery> namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - - assertEquals("BAR", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedNativeQueries().get(2).getName()); - - - entityMappings().moveNamedNativeQuery(0, 1); - namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - - assertEquals("BAZ", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedNativeQueries().get(2).getName()); - } - - public void testUpdateNamedNativeQueries() throws Exception { - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - ormResource().getEntityMappings().getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - ormResource().getEntityMappings().getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - - ormResource().getEntityMappings().getNamedNativeQueries().get(0).setName("FOO"); - ormResource().getEntityMappings().getNamedNativeQueries().get(1).setName("BAR"); - ormResource().getEntityMappings().getNamedNativeQueries().get(2).setName("BAZ"); - - ListIterator<OrmNamedNativeQuery> namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(3, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedNativeQueries().move(2, 0); - namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - - ormResource().getEntityMappings().getNamedNativeQueries().move(0, 1); - namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - - ormResource().getEntityMappings().getNamedNativeQueries().remove(1); - namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(2, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedNativeQueries().remove(1); - namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(1, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedNativeQueries().remove(0); - assertFalse(entityMappings().namedNativeQueries().hasNext()); - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/JptCoreOrmContextModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/JptCoreOrmContextModelTests.java deleted file mode 100644 index 2c98ed8e0b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/JptCoreOrmContextModelTests.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptCoreOrmContextModelTests extends TestCase -{ - public static Test suite() { - return suite(true); - } - - public static Test suite(boolean all) { - TestSuite suite = new TestSuite(JptCoreOrmContextModelTests.class.getName()); - suite.addTestSuite(OrmXmlTests.class); - suite.addTestSuite(EntityMappingsTests.class); - suite.addTestSuite(PersistenceUnitMetadataTests.class); - suite.addTestSuite(PersistenceUnitDefaultsTests.class); - suite.addTestSuite(OrmPersistentAttributeTests.class); - suite.addTestSuite(OrmPersistentTypeTests.class); - suite.addTestSuite(OrmAssociationOverrideTests.class); - suite.addTestSuite(OrmAttributeOverrideTests.class); - suite.addTestSuite(OrmBasicMappingTests.class); - suite.addTestSuite(OrmCascadeTests.class); - suite.addTestSuite(OrmColumnTests.class); - suite.addTestSuite(OrmDiscriminatorColumnTests.class); - suite.addTestSuite(OrmIdMappingTests.class); - suite.addTestSuite(OrmEmbeddableTests.class); - suite.addTestSuite(OrmEmbeddedMappingTests.class); - suite.addTestSuite(OrmEmbeddedIdMappingTests.class); - suite.addTestSuite(OrmEntityTests.class); - suite.addTestSuite(OrmGeneratedValueTests.class); - suite.addTestSuite(OrmJoinColumnTests.class); - suite.addTestSuite(OrmJoinTableTests.class); - suite.addTestSuite(OrmMappedSuperclassTests.class); - suite.addTestSuite(OrmManyToManyMappingTests.class); - suite.addTestSuite(OrmManyToOneMappingTests.class); - suite.addTestSuite(OrmNamedQueryTests.class); - suite.addTestSuite(OrmNamedNativeQueryTests.class); - suite.addTestSuite(OrmOneToManyMappingTests.class); - suite.addTestSuite(OrmOneToOneMappingTests.class); - suite.addTestSuite(OrmPrimaryKeyJoinColumnTests.class); - suite.addTestSuite(OrmQueryHintTests.class); - suite.addTestSuite(OrmSecondaryTableTests.class); - suite.addTestSuite(OrmSequenceGeneratorTests.class); - suite.addTestSuite(OrmTableGeneratorTests.class); - suite.addTestSuite(OrmTableTests.class); - suite.addTestSuite(OrmTransientMappingTests.class); - suite.addTestSuite(OrmVersionMappingTests.class); - return suite; - } - - private JptCoreOrmContextModelTests() { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAssociationOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAssociationOverrideTests.java deleted file mode 100644 index 5ab76feb9a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAssociationOverrideTests.java +++ /dev/null @@ -1,255 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -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; - -public class OrmAssociationOverrideTests extends ContextModelTestCase -{ - public OrmAssociationOverrideTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - OrmAssociationOverride ormAssociationOverride = ormEntity.specifiedAssociationOverrides().next(); - - assertNull(ormAssociationOverride.getName()); - assertNull(xmlAssociationOverride.getName()); - assertTrue(ormEntity.associationOverrides().hasNext()); - assertFalse(entityResource.getAssociationOverrides().isEmpty()); - - //set name in the resource model, verify context model updated - xmlAssociationOverride.setName("FOO"); - assertEquals("FOO", ormAssociationOverride.getName()); - assertEquals("FOO", xmlAssociationOverride.getName()); - - //set name to null in the resource model - xmlAssociationOverride.setName(null); - assertNull(ormAssociationOverride.getName()); - assertNull(xmlAssociationOverride.getName()); - - xmlAssociationOverride.setName("FOO"); - assertEquals("FOO", ormAssociationOverride.getName()); - assertEquals("FOO", xmlAssociationOverride.getName()); - - entityResource.getAssociationOverrides().remove(0); - assertFalse(ormEntity.associationOverrides().hasNext()); - assertTrue(entityResource.getAssociationOverrides().isEmpty()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - OrmAssociationOverride ormAssociationOverride = ormEntity.specifiedAssociationOverrides().next(); - - assertNull(ormAssociationOverride.getName()); - assertNull(xmlAssociationOverride.getName()); - - //set name in the context model, verify resource model modified - ormAssociationOverride.setName("foo"); - assertEquals("foo", ormAssociationOverride.getName()); - assertEquals("foo", xmlAssociationOverride.getName()); - - //set name to null in the context model - ormAssociationOverride.setName(null); - assertNull(ormAssociationOverride.getName()); - assertNull(entityResource.getAssociationOverrides().get(0).getName()); - } - - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - OrmAssociationOverride ormAssociationOverride = ormEntity.specifiedAssociationOverrides().next(); - - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - OrmJoinColumn joinColumn = ormAssociationOverride.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormAssociationOverride.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormAssociationOverride.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - - ListIterator<OrmJoinColumn> joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - OrmAssociationOverride ormAssociationOverride = ormEntity.specifiedAssociationOverrides().next(); - - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - ormAssociationOverride.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormAssociationOverride.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormAssociationOverride.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, xmlAssociationOverride.getJoinColumns().size()); - - ormAssociationOverride.removeSpecifiedJoinColumn(0); - assertEquals(2, xmlAssociationOverride.getJoinColumns().size()); - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - - ormAssociationOverride.removeSpecifiedJoinColumn(0); - assertEquals(1, xmlAssociationOverride.getJoinColumns().size()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(0).getName()); - - ormAssociationOverride.removeSpecifiedJoinColumn(0); - assertEquals(0, xmlAssociationOverride.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - OrmAssociationOverride ormAssociationOverride = ormEntity.specifiedAssociationOverrides().next(); - - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - ormAssociationOverride.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormAssociationOverride.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormAssociationOverride.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, xmlAssociationOverride.getJoinColumns().size()); - - - ormAssociationOverride.moveSpecifiedJoinColumn(2, 0); - ListIterator<OrmJoinColumn> joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - - - ormAssociationOverride.moveSpecifiedJoinColumn(0, 1); - joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - OrmAssociationOverride ormAssociationOverride = ormEntity.specifiedAssociationOverrides().next(); - - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - xmlAssociationOverride.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - xmlAssociationOverride.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - xmlAssociationOverride.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - - xmlAssociationOverride.getJoinColumns().get(0).setName("FOO"); - xmlAssociationOverride.getJoinColumns().get(1).setName("BAR"); - xmlAssociationOverride.getJoinColumns().get(2).setName("BAZ"); - - ListIterator<OrmJoinColumn> joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().move(2, 0); - joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().move(0, 1); - joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(1); - joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(1); - joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(0); - assertFalse(ormAssociationOverride.specifiedJoinColumns().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/orm/OrmAttributeOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAttributeOverrideTests.java deleted file mode 100644 index f511d12f58..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAttributeOverrideTests.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -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; - -public class OrmAttributeOverrideTests extends ContextModelTestCase -{ - public OrmAttributeOverrideTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - XmlAttributeOverride attributeOverrideResource = entityResource.getAttributeOverrides().get(0); - OrmAttributeOverride ormAttributeOverride = ormEntity.specifiedAttributeOverrides().next(); - - assertNull(ormAttributeOverride.getName()); - assertNull(attributeOverrideResource.getName()); - assertTrue(ormEntity.attributeOverrides().hasNext()); - assertFalse(entityResource.getAttributeOverrides().isEmpty()); - - //set name in the resource model, verify context model updated - attributeOverrideResource.setName("FOO"); - assertEquals("FOO", ormAttributeOverride.getName()); - assertEquals("FOO", attributeOverrideResource.getName()); - - //set name to null in the resource model - attributeOverrideResource.setName(null); - assertNull(ormAttributeOverride.getName()); - assertNull(attributeOverrideResource.getName()); - - attributeOverrideResource.setName("FOO"); - assertEquals("FOO", ormAttributeOverride.getName()); - assertEquals("FOO", attributeOverrideResource.getName()); - - entityResource.getAttributeOverrides().remove(0); - assertFalse(ormEntity.attributeOverrides().hasNext()); - assertTrue(entityResource.getAttributeOverrides().isEmpty()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - XmlAttributeOverride attributeOverrideResource = entityResource.getAttributeOverrides().get(0); - OrmAttributeOverride ormAttributeOverride = ormEntity.specifiedAttributeOverrides().next(); - - assertNull(ormAttributeOverride.getName()); - assertNull(attributeOverrideResource.getName()); - - //set name in the context model, verify resource model modified - ormAttributeOverride.setName("foo"); - assertEquals("foo", ormAttributeOverride.getName()); - assertEquals("foo", attributeOverrideResource.getName()); - - //set name to null in the context model - ormAttributeOverride.setName(null); - assertNull(ormAttributeOverride.getName()); - assertNull(entityResource.getAttributeOverrides().get(0).getName()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmBasicMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmBasicMappingTests.java deleted file mode 100644 index a6d0ba55d9..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmBasicMappingTests.java +++ /dev/null @@ -1,708 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.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.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.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -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; - -public class OrmBasicMappingTests extends ContextModelTestCase -{ - public OrmBasicMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private ICompilationUnit createTestEntityBasicMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.FETCH_TYPE, JPA.COLUMN, JPA.LOB, JPA.TEMPORAL, JPA.TEMPORAL_TYPE, JPA.ENUMERATED, JPA.ENUM_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic(fetch=FetchType.LAZY, optional=false)"); - sb.append(CR); - sb.append(" @Column(name=\"MY_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\", length=5, precision=6, scale=7)"); - sb.append(CR); - sb.append(" @Lob"); - sb.append(CR); - sb.append(" @Temporal(TemporalType.TIMESTAMP)"); - sb.append(CR); - sb.append(" @Enumerated(EnumType.STRING)"); - } - }); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertEquals("basicMapping", ormBasicMapping.getName()); - assertEquals("basicMapping", basicResource.getName()); - - //set name in the resource model, verify context model updated - basicResource.setName("newName"); - assertEquals("newName", ormBasicMapping.getName()); - assertEquals("newName", basicResource.getName()); - - //set name to null in the resource model - basicResource.setName(null); - assertNull(ormBasicMapping.getName()); - assertNull(basicResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertEquals("basicMapping", ormBasicMapping.getName()); - assertEquals("basicMapping", basicResource.getName()); - - //set name in the context model, verify resource model updated - ormBasicMapping.setName("newName"); - assertEquals("newName", ormBasicMapping.getName()); - assertEquals("newName", basicResource.getName()); - - //set name to null in the context model - ormBasicMapping.setName(null); - assertNull(ormBasicMapping.getName()); - assertNull(basicResource.getName()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(basicResource.getFetch()); - - //set fetch in the resource model, verify context model updated - basicResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormBasicMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, basicResource.getFetch()); - - basicResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormBasicMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, basicResource.getFetch()); - - //set fetch to null in the resource model - basicResource.setFetch(null); - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(basicResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(basicResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormBasicMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, basicResource.getFetch()); - assertEquals(FetchType.EAGER, ormBasicMapping.getSpecifiedFetch()); - - ormBasicMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, basicResource.getFetch()); - assertEquals(FetchType.LAZY, ormBasicMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormBasicMapping.setSpecifiedFetch(null); - assertNull(basicResource.getFetch()); - assertNull(ormBasicMapping.getSpecifiedFetch()); - } - - public void testUpdateSpecifiedEnumerated() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedConverter()); - assertNull(basicResource.getEnumerated()); - - //set enumerated in the resource model, verify context model updated - basicResource.setEnumerated(org.eclipse.jpt.core.resource.orm.EnumType.ORDINAL); - assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormBasicMapping.getConverter()).getSpecifiedEnumType()); - assertEquals(org.eclipse.jpt.core.resource.orm.EnumType.ORDINAL, basicResource.getEnumerated()); - - basicResource.setEnumerated(org.eclipse.jpt.core.resource.orm.EnumType.STRING); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ormBasicMapping.getConverter()).getSpecifiedEnumType()); - assertEquals(org.eclipse.jpt.core.resource.orm.EnumType.STRING, basicResource.getEnumerated()); - - //set enumerated to null in the resource model - basicResource.setEnumerated(null); - assertNull(ormBasicMapping.getSpecifiedConverter()); - assertNull(basicResource.getEnumerated()); - } - - public void testModifySpecifiedEnumerated() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedConverter()); - assertNull(basicResource.getEnumerated()); - - //set enumerated in the context model, verify resource model updated - ormBasicMapping.setSpecifiedConverter(Converter.ENUMERATED_CONVERTER); - ((EnumeratedConverter) ormBasicMapping.getConverter()).setSpecifiedEnumType(EnumType.ORDINAL); - assertEquals(org.eclipse.jpt.core.resource.orm.EnumType.ORDINAL, basicResource.getEnumerated()); - assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) ormBasicMapping.getConverter()).getSpecifiedEnumType()); - - ((EnumeratedConverter) ormBasicMapping.getConverter()).setSpecifiedEnumType(EnumType.STRING); - assertEquals(org.eclipse.jpt.core.resource.orm.EnumType.STRING, basicResource.getEnumerated()); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ormBasicMapping.getConverter()).getSpecifiedEnumType()); - - //set enumerated to null in the context model - ormBasicMapping.setSpecifiedConverter(null); - assertNull(basicResource.getEnumerated()); - assertNull(ormBasicMapping.getSpecifiedConverter()); - } - - public void testUpdateSpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertNull(basicResource.getOptional()); - - //set enumerated in the resource model, verify context model updated - basicResource.setOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormBasicMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, basicResource.getOptional()); - - basicResource.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormBasicMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, basicResource.getOptional()); - - //set enumerated to null in the resource model - basicResource.setOptional(null); - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertNull(basicResource.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertNull(basicResource.getOptional()); - - //set enumerated in the context model, verify resource model updated - ormBasicMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, basicResource.getOptional()); - assertEquals(Boolean.TRUE, ormBasicMapping.getSpecifiedOptional()); - - ormBasicMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, basicResource.getOptional()); - assertEquals(Boolean.FALSE, ormBasicMapping.getSpecifiedOptional()); - - //set enumerated to null in the context model - ormBasicMapping.setSpecifiedOptional(null); - assertNull(basicResource.getOptional()); - assertNull(ormBasicMapping.getSpecifiedOptional()); - } - - public void testUpdateSpecifiedLob() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedConverter()); - assertFalse(basicResource.isLob()); - - //set lob in the resource model, verify context model updated - basicResource.setLob(true); - assertEquals(Converter.LOB_CONVERTER, ormBasicMapping.getConverter().getType()); - assertTrue(basicResource.isLob()); - - //set lob to null in the resource model - basicResource.setLob(false); - assertNull(ormBasicMapping.getSpecifiedConverter()); - assertFalse(basicResource.isLob()); - } - - public void testModifySpecifiedLob() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedConverter()); - assertFalse(basicResource.isLob()); - - //set lob in the context model, verify resource model updated - ormBasicMapping.setSpecifiedConverter(Converter.LOB_CONVERTER); - assertTrue(basicResource.isLob()); - assertEquals(Converter.LOB_CONVERTER, ormBasicMapping.getConverter().getType()); - - //set lob to false in the context model - ormBasicMapping.setSpecifiedConverter(null); - assertFalse(basicResource.isLob()); - assertNull(ormBasicMapping.getSpecifiedConverter()); - } - - public void testUpdateTemporal() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedConverter()); - assertNull(basicResource.getTemporal()); - - //set temporal in the resource model, verify context model updated - basicResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.DATE); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormBasicMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, basicResource.getTemporal()); - - basicResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIME); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormBasicMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, basicResource.getTemporal()); - - basicResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormBasicMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, basicResource.getTemporal()); - - //set temporal to null in the resource model - basicResource.setTemporal(null); - assertNull(ormBasicMapping.getSpecifiedConverter()); - assertNull(basicResource.getTemporal()); - } - - public void testModifyTemporal() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedConverter()); - assertNull(basicResource.getTemporal()); - - //set temporal in the context model, verify resource model updated - ormBasicMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) ormBasicMapping.getSpecifiedConverter()).setTemporalType(TemporalType.DATE); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, basicResource.getTemporal()); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormBasicMapping.getSpecifiedConverter()).getTemporalType()); - - ((TemporalConverter) ormBasicMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, basicResource.getTemporal()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormBasicMapping.getSpecifiedConverter()).getTemporalType()); - - ((TemporalConverter) ormBasicMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIMESTAMP); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, basicResource.getTemporal()); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormBasicMapping.getSpecifiedConverter()).getTemporalType()); - - //set temporal to null in the context model - ormBasicMapping.setSpecifiedConverter(null); - assertNull(basicResource.getTemporal()); - assertNull(ormBasicMapping.getSpecifiedConverter()); - } - - //TODO test defaults - //TODO test overriding java mapping with a different mapping type in xml - - - public void testBasicMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityBasicMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormBasicMapping.getName()); - assertNull(ormBasicMapping.getSpecifiedConverter()); - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertEquals(FetchType.EAGER, ormBasicMapping.getFetch()); - assertEquals(Boolean.TRUE, ormBasicMapping.getOptional()); - - - OrmColumn ormColumn = ormBasicMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("foo", ormColumn.getDefaultName()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Integer.valueOf(255), ormColumn.getDefaultLength()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultScale()); - } - - //@Basic(fetch=FetchType.LAZY, optional=false) - //@Column(name="MY_COLUMN", unique=true, nullable=false, insertable=false, updatable=false, - // columnDefinition="COLUMN_DEFINITION", table="MY_TABLE", length=5, precision=6, scale=7)"); - //@Column( - //@Lob - //@Temporal(TemporalType.TIMESTAMP) - //@Enumerated(EnumType.STRING) - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormBasicMapping.getName()); - assertEquals(Converter.ENUMERATED_CONVERTER, ormBasicMapping.getConverter().getType()); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ormBasicMapping.getConverter()).getEnumType()); - assertEquals(FetchType.LAZY, ormBasicMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, ormBasicMapping.getSpecifiedOptional()); - - OrmColumn ormColumn = ormBasicMapping.getColumn(); - assertEquals("MY_COLUMN", ormColumn.getSpecifiedName()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", ormColumn.getColumnDefinition()); - assertEquals("MY_TABLE", ormColumn.getSpecifiedTable()); - assertEquals(Integer.valueOf(5), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(6), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedScale()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormBasicMapping.getName()); - assertEquals(Converter.NO_CONVERTER, ormBasicMapping.getConverter().getType()); - assertEquals(FetchType.EAGER, ormBasicMapping.getSpecifiedFetch()); - assertEquals(Boolean.TRUE, ormBasicMapping.getSpecifiedOptional()); - - OrmColumn ormColumn = ormBasicMapping.getColumn(); - assertEquals("id", ormColumn.getSpecifiedName()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getSpecifiedTable()); - assertEquals(Integer.valueOf(255), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(0), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getSpecifiedScale()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityBasicMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - - assertEquals("id", ormBasicMapping.getName()); - assertEquals(Converter.NO_CONVERTER, ormBasicMapping.getConverter().getType()); - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertEquals(FetchType.EAGER, ormBasicMapping.getDefaultFetch()); - assertEquals(Boolean.TRUE, ormBasicMapping.getDefaultOptional()); - - OrmColumn ormColumn = ormBasicMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("id", ormColumn.getDefaultName()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Integer.valueOf(255), ormColumn.getDefaultLength()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultScale()); - - } - //3 things tested above - //1. virtual mapping metadata complete=false - defaults are taken from the java annotations - //2. virtual mapping metadata complete=true - defaults are taken from java defaults,annotations ignored - //3. specified mapping (metadata complete=true/false - defaults are taken from java annotations - - - public void testBasicMorphToIdMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - assertEquals("FOO", ((IdMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testBasicMorphToVersionMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - assertEquals("FOO", ((VersionMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testBasicMorphToTransientMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToEmbeddedMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToEmbeddedIdMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToOneToOneMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToOneToManyMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToManyToOneMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToManyToManyMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmCascadeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmCascadeTests.java deleted file mode 100644 index 88a74c4dd0..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmCascadeTests.java +++ /dev/null @@ -1,280 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -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; - -public class OrmCascadeTests extends ContextModelTestCase -{ - public OrmCascadeTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateCascadeAll() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isAll()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeTypeImpl()); - assertEquals(false, cascade.isAll()); - assertNotNull(oneToOne.getCascade()); - - //set all in the resource model, verify context model updated - oneToOne.getCascade().setCascadeAll(true); - assertEquals(true, cascade.isAll()); - assertEquals(true, oneToOne.getCascade().isCascadeAll()); - - //set all to false in the resource model - oneToOne.getCascade().setCascadeAll(false); - assertEquals(false, cascade.isAll()); - assertEquals(false, oneToOne.getCascade().isCascadeAll()); - } - - public void testModifyCascadeAll() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isAll()); - assertNull(oneToOne.getCascade()); - - //set all in the context model, verify resource model updated - cascade.setAll(true); - assertEquals(true, cascade.isAll()); - assertEquals(true, oneToOne.getCascade().isCascadeAll()); - - //set all to false in the context model - cascade.setAll(false); - assertEquals(false, cascade.isAll()); - assertNull(oneToOne.getCascade()); - } - - public void testUpdateCascadePersist() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isPersist()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeTypeImpl()); - assertEquals(false, cascade.isPersist()); - assertNotNull(oneToOne.getCascade()); - - //set Persist in the resource model, verify context model updated - oneToOne.getCascade().setCascadePersist(true); - assertEquals(true, cascade.isPersist()); - assertEquals(true, oneToOne.getCascade().isCascadePersist()); - - //set Persist to false in the resource model - oneToOne.getCascade().setCascadePersist(false); - assertEquals(false, cascade.isPersist()); - assertEquals(false, oneToOne.getCascade().isCascadePersist()); - } - - public void testModifyCascadePersist() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isPersist()); - assertNull(oneToOne.getCascade()); - - //set Persist in the context model, verify resource model updated - cascade.setPersist(true); - assertEquals(true, cascade.isPersist()); - assertEquals(true, oneToOne.getCascade().isCascadePersist()); - - //set Persist to false in the context model - cascade.setPersist(false); - assertEquals(false, cascade.isPersist()); - assertNull(oneToOne.getCascade()); - } - - public void testUpdateCascadeMerge() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isMerge()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeTypeImpl()); - assertEquals(false, cascade.isMerge()); - assertNotNull(oneToOne.getCascade()); - - //set Merge in the resource model, verify context model updated - oneToOne.getCascade().setCascadeMerge(true); - assertEquals(true, cascade.isMerge()); - assertEquals(true, oneToOne.getCascade().isCascadeMerge()); - - //set Merge to false in the resource model - oneToOne.getCascade().setCascadeMerge(false); - assertEquals(false, cascade.isMerge()); - assertEquals(false, oneToOne.getCascade().isCascadeMerge()); - } - - public void testModifyCascadeMerge() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isMerge()); - assertNull(oneToOne.getCascade()); - - //set Merge in the context model, verify resource model updated - cascade.setMerge(true); - assertEquals(true, cascade.isMerge()); - assertEquals(true, oneToOne.getCascade().isCascadeMerge()); - - //set Merge to false in the context model - cascade.setMerge(false); - assertEquals(false, cascade.isMerge()); - assertNull(oneToOne.getCascade()); - } - - public void testUpdateCascadeRemove() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isRemove()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeTypeImpl()); - assertEquals(false, cascade.isRemove()); - assertNotNull(oneToOne.getCascade()); - - //set Remove in the resource model, verify context model updated - oneToOne.getCascade().setCascadeRemove(true); - assertEquals(true, cascade.isRemove()); - assertEquals(true, oneToOne.getCascade().isCascadeRemove()); - - //set Remove to false in the resource model - oneToOne.getCascade().setCascadeRemove(false); - assertEquals(false, cascade.isRemove()); - assertEquals(false, oneToOne.getCascade().isCascadeRemove()); - } - - public void testModifyCascadeRemove() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isRemove()); - assertNull(oneToOne.getCascade()); - - //set Remove in the context model, verify resource model updated - cascade.setRemove(true); - assertEquals(true, cascade.isRemove()); - assertEquals(true, oneToOne.getCascade().isCascadeRemove()); - - //set Remove to false in the context model - cascade.setRemove(false); - assertEquals(false, cascade.isRemove()); - assertNull(oneToOne.getCascade()); - } - - public void testUpdateCascadeRefresh() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isRefresh()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeTypeImpl()); - assertEquals(false, cascade.isRefresh()); - assertNotNull(oneToOne.getCascade()); - - //set Refresh in the resource model, verify context model updated - oneToOne.getCascade().setCascadeRefresh(true); - assertEquals(true, cascade.isRefresh()); - assertEquals(true, oneToOne.getCascade().isCascadeRefresh()); - - //set Refresh to false in the resource model - oneToOne.getCascade().setCascadeRefresh(false); - assertEquals(false, cascade.isRefresh()); - assertEquals(false, oneToOne.getCascade().isCascadeRefresh()); - } - - public void testModifyCascadeRefresh() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isRefresh()); - assertNull(oneToOne.getCascade()); - - //set Refresh in the context model, verify resource model updated - cascade.setRefresh(true); - assertEquals(true, cascade.isRefresh()); - assertEquals(true, oneToOne.getCascade().isCascadeRefresh()); - - //set Refresh to false in the context model - cascade.setRefresh(false); - assertEquals(false, cascade.isRefresh()); - assertNull(oneToOne.getCascade()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmColumnTests.java deleted file mode 100644 index 17b9f99c91..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmColumnTests.java +++ /dev/null @@ -1,838 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.Column; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -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.iterators.ArrayIterator; - -public class OrmColumnTests extends ContextModelTestCase -{ - public OrmColumnTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - 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 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 void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setName("FOO"); - ormResource().save(null); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO", basic.getColumn().getName()); - - //set name to null in the resource model - basic.getColumn().setName(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn().getName()); - - basic.getColumn().setName("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO", basic.getColumn().getName()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedName("foo"); - assertEquals("foo", ormColumn.getSpecifiedName()); - assertEquals("foo", basic.getColumn().getName()); - - //set name to null in the context model - ormColumn.setSpecifiedName(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn()); - } - - public void testUpdateColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setColumnDefinition("FOO"); - assertEquals("FOO", ormColumn.getColumnDefinition()); - assertEquals("FOO", basic.getColumn().getColumnDefinition()); - - //set name to null in the resource model - basic.getColumn().setColumnDefinition(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn().getColumnDefinition()); - - basic.getColumn().setColumnDefinition("FOO"); - assertEquals("FOO", ormColumn.getColumnDefinition()); - assertEquals("FOO", basic.getColumn().getColumnDefinition()); - - basic.setColumn(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn()); - } - - public void testModifyColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setColumnDefinition("foo"); - assertEquals("foo", ormColumn.getColumnDefinition()); - assertEquals("foo", basic.getColumn().getColumnDefinition()); - - //set name to null in the context model - ormColumn.setColumnDefinition(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedTable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setTable("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedTable()); - assertEquals("FOO", basic.getColumn().getTable()); - - //set name to null in the resource model - basic.getColumn().setTable(null); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn().getTable()); - - basic.getColumn().setTable("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedTable()); - assertEquals("FOO", basic.getColumn().getTable()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedTable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedTable("foo"); - assertEquals("foo", ormColumn.getSpecifiedTable()); - assertEquals("foo", basic.getColumn().getTable()); - - //set name to null in the context model - ormColumn.setSpecifiedTable(null); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedNullable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setNullable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, basic.getColumn().getNullable()); - - //set name to null in the resource model - basic.getColumn().setNullable(null); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn().getNullable()); - - basic.getColumn().setNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, basic.getColumn().getNullable()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedNullable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, basic.getColumn().getNullable()); - - //set name to null in the context model - ormColumn.setSpecifiedNullable(null); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedUpdatable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setUpdatable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, basic.getColumn().getUpdatable()); - - //set name to null in the resource model - basic.getColumn().setUpdatable(null); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn().getUpdatable()); - - basic.getColumn().setUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, basic.getColumn().getUpdatable()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedUpdatable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, basic.getColumn().getUpdatable()); - - //set name to null in the context model - ormColumn.setSpecifiedUpdatable(null); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedInsertable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setInsertable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, basic.getColumn().getInsertable()); - - //set name to null in the resource model - basic.getColumn().setInsertable(null); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn().getInsertable()); - - basic.getColumn().setInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, basic.getColumn().getInsertable()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedInsertable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, basic.getColumn().getInsertable()); - - //set name to null in the context model - ormColumn.setSpecifiedInsertable(null); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedUnique() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setUnique(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, basic.getColumn().getUnique()); - - //set name to null in the resource model - basic.getColumn().setUnique(null); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn().getUnique()); - - basic.getColumn().setUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, basic.getColumn().getUnique()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedUnique() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, basic.getColumn().getUnique()); - - //set name to null in the context model - ormColumn.setSpecifiedUnique(null); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedLength() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setLength(Integer.valueOf(8)); - assertEquals(Integer.valueOf(8), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(8), basic.getColumn().getLength()); - - //set name to null in the resource model - basic.getColumn().setLength(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn().getLength()); - - basic.getColumn().setLength(Integer.valueOf(11)); - assertEquals(Integer.valueOf(11), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(11), basic.getColumn().getLength()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedLength() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedLength(Integer.valueOf(7)); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(7), basic.getColumn().getLength()); - - //set name to null in the context model - ormColumn.setSpecifiedLength(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedPrecision() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setPrecision(Integer.valueOf(8)); - assertEquals(Integer.valueOf(8), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(8), basic.getColumn().getPrecision()); - - //set name to null in the resource model - basic.getColumn().setPrecision(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn().getPrecision()); - - basic.getColumn().setPrecision(Integer.valueOf(11)); - assertEquals(Integer.valueOf(11), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(11), basic.getColumn().getPrecision()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedPrecision() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedPrecision(Integer.valueOf(7)); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(7), basic.getColumn().getPrecision()); - - //set name to null in the context model - ormColumn.setSpecifiedPrecision(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedScale() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setScale(Integer.valueOf(8)); - assertEquals(Integer.valueOf(8), ormColumn.getSpecifiedScale()); - assertEquals(Integer.valueOf(8), basic.getColumn().getScale()); - - //set name to null in the resource model - basic.getColumn().setScale(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn().getScale()); - - basic.getColumn().setScale(Integer.valueOf(11)); - assertEquals(Integer.valueOf(11), ormColumn.getSpecifiedScale()); - assertEquals(Integer.valueOf(11), basic.getColumn().getScale()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedScale() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedScale(Integer.valueOf(7)); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedScale()); - assertEquals(Integer.valueOf(7), basic.getColumn().getScale()); - - //set name to null in the context model - ormColumn.setSpecifiedScale(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testVirtualColumnDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ListIterator<OrmPersistentAttribute> attributes = ormPersistentType.virtualAttributes(); - attributes.next(); - - //virtual attrubte in orm.xml, java attribute has no Column annotation - OrmPersistentAttribute namePersistentAttribute = attributes.next(); - OrmBasicMapping nameVirtualMapping = (OrmBasicMapping) namePersistentAttribute.getMapping(); - OrmColumn ormColumn = nameVirtualMapping.getColumn(); - assertEquals("name", ormColumn.getSpecifiedName()); - assertEquals(TYPE_NAME, ormColumn.getSpecifiedTable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getSpecifiedLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getSpecifiedPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getSpecifiedScale()); - - //set Column annotation in Java - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("name").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("FOO"); - javaBasicMapping.getColumn().setSpecifiedTable("FOO_TABLE"); - javaBasicMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaBasicMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - javaBasicMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaBasicMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - javaBasicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - javaBasicMapping.getColumn().setSpecifiedLength(Integer.valueOf(45)); - javaBasicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaBasicMapping.getColumn().setSpecifiedScale(Integer.valueOf(47)); - - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", ormColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", ormColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), ormColumn.getSpecifiedScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals("name", ormColumn.getSpecifiedName()); - assertEquals(TYPE_NAME, ormColumn.getSpecifiedTable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getSpecifiedLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getSpecifiedPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getSpecifiedScale()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals("name", ormColumn.getSpecifiedName()); - assertEquals(TYPE_NAME, ormColumn.getSpecifiedTable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getSpecifiedLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getSpecifiedPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getSpecifiedScale()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - assertEquals("name", ormColumn.getSpecifiedName()); - assertEquals(TYPE_NAME, ormColumn.getSpecifiedTable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getSpecifiedLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getSpecifiedPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getSpecifiedScale()); - - //set metadata-complete false, orm.xml virtual column gets setting from java annotation - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", ormColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", ormColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), ormColumn.getSpecifiedScale()); - } - - public void testNullColumnDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute namePersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "name"); - - OrmBasicMapping nameVirtualMapping = (OrmBasicMapping) namePersistentAttribute.getMapping(); - OrmColumn ormColumn = nameVirtualMapping.getColumn(); - - //set Column annotation in Java - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("name").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("FOO"); - javaBasicMapping.getColumn().setSpecifiedTable("FOO_TABLE"); - javaBasicMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaBasicMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - javaBasicMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaBasicMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - javaBasicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - javaBasicMapping.getColumn().setSpecifiedLength(Integer.valueOf(45)); - javaBasicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(46)); - javaBasicMapping.getColumn().setSpecifiedScale(Integer.valueOf(47)); - - - assertEquals("name", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualColumnTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ListIterator<OrmPersistentAttribute> attributes = ormPersistentType.virtualAttributes(); - attributes.next(); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmPersistentAttribute namePersistentAttribute = attributes.next(); - OrmBasicMapping nameVirtualMapping = (OrmBasicMapping) namePersistentAttribute.getMapping(); - OrmColumn ormColumn = nameVirtualMapping.getColumn(); - - assertEquals(TYPE_NAME, ormColumn.getSpecifiedTable()); - - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals("ORM_TABLE", ormColumn.getSpecifiedTable()); - - //set Column table element in Java - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("name").getMapping(); - javaBasicMapping.getColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", ormColumn.getSpecifiedTable()); - - //make name persistent attribute not virtual - namePersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "name"); - nameVirtualMapping = (OrmBasicMapping) namePersistentAttribute.getMapping(); - ormColumn = nameVirtualMapping.getColumn(); - assertNull(ormColumn.getSpecifiedTable()); - assertEquals("ORM_TABLE", ormColumn.getDefaultTable()); - - } - -//public void testUpdateDefaultNameNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals("Foo", xmlEntity.getTable().getDefaultName()); -//} -// -//public void testUpdateDefaultNameFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals(TYPE_NAME, childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.getTable().setSpecifiedName("FOO"); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("AnnotationTestTypeChild", childXmlEntity.getTable().getDefaultName()); -//} - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmDiscriminatorColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmDiscriminatorColumnTests.java deleted file mode 100644 index 797ee87ffd..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmDiscriminatorColumnTests.java +++ /dev/null @@ -1,338 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.DiscriminatorType; -import org.eclipse.jpt.core.context.orm.OrmDiscriminatorColumn; -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.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -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.iterators.ArrayIterator; - -public class OrmDiscriminatorColumnTests extends ContextModelTestCase -{ - public OrmDiscriminatorColumnTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - 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 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 void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the resource model, verify context model updated - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setName("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getName()); - - //set name to null in the resource model - entityResource.getDiscriminatorColumn().setName(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn().getName()); - - entityResource.getDiscriminatorColumn().setName("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getName()); - - entityResource.setDiscriminatorColumn(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedName("foo"); - assertEquals("foo", ormColumn.getSpecifiedName()); - assertEquals("foo", entityResource.getDiscriminatorColumn().getName()); - - //set name to null in the context model - ormColumn.setSpecifiedName(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn()); - } - -// public void testUpdateDefaultNameFromJavaTable() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.javaEntity().getTable().setSpecifiedName("Foo"); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// -// ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); -// ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.setSpecifiedMetadataComplete(null); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// -// ormEntity.getTable().setSpecifiedName("Bar"); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// } -// -// public void testUpdateDefaultNameNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// } -// -// public void testUpdateDefaultNameFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals(TYPE_NAME, childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.getTable().setSpecifiedName("FOO"); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("AnnotationTestTypeChild", childXmlEntity.getTable().getDefaultName()); -// } - - public void testUpdateSpecifiedLength() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the resource model, verify context model updated - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setLength(Integer.valueOf(8)); - assertEquals(Integer.valueOf(8), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(8), entityResource.getDiscriminatorColumn().getLength()); - - //set name to null in the resource model - entityResource.getDiscriminatorColumn().setLength(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn().getLength()); - - entityResource.getDiscriminatorColumn().setLength(Integer.valueOf(11)); - assertEquals(Integer.valueOf(11), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(11), entityResource.getDiscriminatorColumn().getLength()); - - entityResource.setDiscriminatorColumn(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testModifySpecifiedLength() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedLength(Integer.valueOf(7)); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(7), entityResource.getDiscriminatorColumn().getLength()); - - //set name to null in the context model - ormColumn.setSpecifiedLength(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testUpdateSpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the resource model, verify context model updated - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setColumnDefinition("FOO"); - assertEquals("FOO", ormColumn.getColumnDefinition()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getColumnDefinition()); - - //set name to null in the resource model - entityResource.getDiscriminatorColumn().setColumnDefinition(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn().getColumnDefinition()); - - entityResource.getDiscriminatorColumn().setColumnDefinition("FOO"); - assertEquals("FOO", ormColumn.getColumnDefinition()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getColumnDefinition()); - - entityResource.setDiscriminatorColumn(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testModifySpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setColumnDefinition("foo"); - assertEquals("foo", ormColumn.getColumnDefinition()); - assertEquals("foo", entityResource.getDiscriminatorColumn().getColumnDefinition()); - - //set name to null in the context model - ormColumn.setColumnDefinition(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testUpdateSpecifiedDiscriminatorType() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set discriminator type in the resource model, verify context model updated - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setDiscriminatorType(org.eclipse.jpt.core.resource.orm.DiscriminatorType.STRING); - assertEquals(DiscriminatorType.STRING, ormColumn.getSpecifiedDiscriminatorType()); - assertEquals(org.eclipse.jpt.core.resource.orm.DiscriminatorType.STRING, entityResource.getDiscriminatorColumn().getDiscriminatorType()); - - //set discriminator type to null in the resource model - entityResource.getDiscriminatorColumn().setDiscriminatorType(null); - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn().getDiscriminatorType()); - - entityResource.getDiscriminatorColumn().setDiscriminatorType(org.eclipse.jpt.core.resource.orm.DiscriminatorType.CHAR); - assertEquals(DiscriminatorType.CHAR, ormColumn.getSpecifiedDiscriminatorType()); - assertEquals(org.eclipse.jpt.core.resource.orm.DiscriminatorType.CHAR, entityResource.getDiscriminatorColumn().getDiscriminatorType()); - - entityResource.setDiscriminatorColumn(null); - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testModifySpecifiedDiscriminatorType() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set discriminator type in the context model, verify resource model modified - ormColumn.setSpecifiedDiscriminatorType(DiscriminatorType.STRING); - assertEquals(DiscriminatorType.STRING, ormColumn.getSpecifiedDiscriminatorType()); - assertEquals(org.eclipse.jpt.core.resource.orm.DiscriminatorType.STRING, entityResource.getDiscriminatorColumn().getDiscriminatorType()); - - //set discriminator type to null in the context model - ormColumn.setSpecifiedDiscriminatorType(null); - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddableTests.java deleted file mode 100644 index c1f8207037..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddableTests.java +++ /dev/null @@ -1,297 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.ListIterator; -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.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -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; - -public class OrmEmbeddableTests extends ContextModelTestCase -{ - public OrmEmbeddableTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals("model.Foo", embeddableResource.getClassName()); - - //set class in the resource model, verify context model updated - embeddableResource.setClassName("com.Bar"); - assertEquals("com.Bar", ormEmbeddable.getClass_()); - assertEquals("com.Bar", embeddableResource.getClassName()); - - //set class to null in the resource model - embeddableResource.setClassName(null); - assertNull(ormEmbeddable.getClass_()); - assertNull(embeddableResource.getClassName()); - } - - public void testModifyClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals("model.Foo", embeddableResource.getClassName()); - - //set class in the context model, verify resource model modified - ormEmbeddable.setClass("com.Bar"); - assertEquals("com.Bar", ormEmbeddable.getClass_()); - assertEquals("com.Bar", embeddableResource.getClassName()); - - //set class to null in the context model - ormEmbeddable.setClass(null); - assertNull(ormEmbeddable.getClass_()); - assertNull(embeddableResource.getClassName()); - } - //TODO add tests for setting the className when the package is set on entity-mappings - - public void testUpdateSpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertNull(ormEmbeddable.getSpecifiedAccess()); - assertNull(embeddableResource.getAccess()); - - //set access in the resource model, verify context model updated - embeddableResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, ormEmbeddable.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, embeddableResource.getAccess()); - - //set access to null in the resource model - embeddableResource.setAccess(null); - assertNull(ormEmbeddable.getSpecifiedAccess()); - assertNull(embeddableResource.getAccess()); - } - - public void testModifySpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertNull(ormEmbeddable.getSpecifiedAccess()); - assertNull(embeddableResource.getAccess()); - - //set access in the context model, verify resource model modified - ormEmbeddable.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormEmbeddable.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddableResource.getAccess()); - - //set access to null in the context model - ormEmbeddable.setSpecifiedAccess(null); - assertNull(ormEmbeddable.getSpecifiedAccess()); - assertNull(embeddableResource.getAccess()); - } - //TODO test default access from - //underlying java - //persistence-unit-defaults - //entity-mappings - //with xml-mapping-metadata-complete set - - public void testUpdateSpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertNull(embeddableResource.getMetadataComplete()); - - //set metadata-complete in the resource model, verify context model updated - embeddableResource.setMetadataComplete(true); - assertTrue(ormEmbeddable.getSpecifiedMetadataComplete()); - assertTrue(embeddableResource.getMetadataComplete()); - - //set access to false in the resource model - embeddableResource.setMetadataComplete(false); - assertFalse(ormEmbeddable.getSpecifiedMetadataComplete()); - assertFalse(embeddableResource.getMetadataComplete()); - - embeddableResource.setMetadataComplete(null); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - } - - public void testModifySpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertNull(embeddableResource.getMetadataComplete()); - - //set access in the context model, verify resource model modified - ormEmbeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - assertTrue(ormEmbeddable.getSpecifiedMetadataComplete()); - assertTrue(embeddableResource.getMetadataComplete()); - - //set access to null in the context model - ormEmbeddable.setSpecifiedMetadataComplete(Boolean.FALSE); - assertFalse(ormEmbeddable.getSpecifiedMetadataComplete()); - assertFalse(embeddableResource.getMetadataComplete()); - - ormEmbeddable.setSpecifiedMetadataComplete(null); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - } - - public void testUpdateDefaultMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertFalse(ormEmbeddable.isDefaultMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormEmbeddable.isDefaultMetadataComplete()); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertFalse(ormEmbeddable.isDefaultMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - } - - public void testUpdateMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertFalse(ormEmbeddable.isMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormEmbeddable.isMetadataComplete()); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertFalse(ormEmbeddable.isMetadataComplete()); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - } - - public void testMakeEmbeddableEntity() throws Exception { - OrmPersistentType embeddablePersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable embeddable = (OrmEmbeddable) embeddablePersistentType.getMapping(); - embeddable.setSpecifiedAccess(AccessType.PROPERTY); - embeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - embeddablePersistentType.setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("model.Foo", entity.getClassName()); - assertEquals(Boolean.TRUE, entity.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entity.getAccess()); - assertNull(entity.getDiscriminatorValue()); - assertNull(entity.getName()); - - OrmEntity ormEntity = (OrmEntity) embeddablePersistentType.getMapping(); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEntity.getSpecifiedAccess()); - } - - //test with 2 Embeddables, make the second one an Entity so it has to move to the front of the list - public void testMakeEmbeddableEntity2() throws Exception { - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo2"); - OrmPersistentType embeddablePersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable embeddable = (OrmEmbeddable) embeddablePersistentType.getMapping(); - embeddable.setSpecifiedAccess(AccessType.PROPERTY); - embeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - embeddablePersistentType.setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("model.Foo", entity.getClassName()); - assertEquals(Boolean.TRUE, entity.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entity.getAccess()); - assertNull(entity.getDiscriminatorValue()); - assertNull(entity.getName()); - - OrmEntity ormEntity = (OrmEntity) embeddablePersistentType.getMapping(); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEntity.getSpecifiedAccess()); - - ListIterator<OrmPersistentType> persistentTypes = entityMappings().ormPersistentTypes(); - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - } - - public void testMakeEmbeddableMappedSuperclass() throws Exception { - OrmPersistentType embeddablePersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable embeddable = (OrmEmbeddable) embeddablePersistentType.getMapping(); - embeddable.setSpecifiedAccess(AccessType.PROPERTY); - embeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - embeddablePersistentType.setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - - XmlMappedSuperclass mappedSuperclass = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", mappedSuperclass.getClassName()); - assertEquals(Boolean.TRUE, mappedSuperclass.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclass.getAccess()); - - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) embeddablePersistentType.getMapping(); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormMappedSuperclass.getSpecifiedAccess()); - } - - //test with 2 Embeddables, make the second one a MappedSuperclass so it has to move to the front of the list - public void testMakeEmbeddableMappedSuperclass2() throws Exception { - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo2"); - OrmPersistentType embeddablePersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable embeddable = (OrmEmbeddable) embeddablePersistentType.getMapping(); - embeddable.setSpecifiedAccess(AccessType.PROPERTY); - embeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - embeddablePersistentType.setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - - XmlMappedSuperclass mappedSuperclass = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", mappedSuperclass.getClassName()); - assertEquals(Boolean.TRUE, mappedSuperclass.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclass.getAccess()); - - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) embeddablePersistentType.getMapping(); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormMappedSuperclass.getSpecifiedAccess()); - - ListIterator<OrmPersistentType> persistentTypes = entityMappings().ormPersistentTypes(); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedIdMappingTests.java deleted file mode 100644 index bb9a105277..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedIdMappingTests.java +++ /dev/null @@ -1,874 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.AttributeOverride; -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.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -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.iterators.ArrayIterator; - -public class OrmEmbeddedIdMappingTests extends ContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "city"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "E_CITY"; - - public OrmEmbeddedIdMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private ICompilationUnit createTestEntityEmbeddedIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED_ID, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @EmbeddedId"); - sb.append(CR); - sb.append(" @AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - 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.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.COLUMN); - sb.append(";"); - sb.append(CR); - 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(" @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(" @Column(name=\"A_STATE\")").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); - } - -// public void testUpdateName() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// assertEquals("embeddedIdMapping", xmlEmbeddedIdMapping.getName()); -// assertEquals("embeddedIdMapping", embeddedIdResource.getName()); -// -// //set name in the resource model, verify context model updated -// embeddedIdResource.setName("newName"); -// assertEquals("newName", xmlEmbeddedIdMapping.getName()); -// assertEquals("newName", embeddedIdResource.getName()); -// -// //set name to null in the resource model -// embeddedIdResource.setName(null); -// assertNull(xmlEmbeddedIdMapping.getName()); -// assertNull(embeddedIdResource.getName()); -// } -// -// public void testModifyName() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// assertEquals("embeddedIdMapping", xmlEmbeddedIdMapping.getName()); -// assertEquals("embeddedIdMapping", embeddedIdResource.getName()); -// -// //set name in the context model, verify resource model updated -// xmlEmbeddedIdMapping.setName("newName"); -// assertEquals("newName", xmlEmbeddedIdMapping.getName()); -// assertEquals("newName", embeddedIdResource.getName()); -// -// //set name to null in the context model -// xmlEmbeddedIdMapping.setName(null); -// assertNull(xmlEmbeddedIdMapping.getName()); -// assertNull(embeddedIdResource.getName()); -// } -// -// public void testAddSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// XmlAttributeOverride attributeOverride = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0); -// ormResource().save(null); -// attributeOverride.setName("FOO"); -// ormResource().save(null); -// -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// -// XmlAttributeOverride attributeOverride2 = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0); -// ormResource().save(null); -// attributeOverride2.setName("BAR"); -// ormResource().save(null); -// -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// -// XmlAttributeOverride attributeOverride3 = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1); -// ormResource().save(null); -// attributeOverride3.setName("BAZ"); -// ormResource().save(null); -// -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); -// -// ListIterator<XmlAttributeOverride> attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals(attributeOverride2, attributeOverrides.next()); -// assertEquals(attributeOverride3, attributeOverrides.next()); -// assertEquals(attributeOverride, attributeOverrides.next()); -// -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// } -// -// public void testRemoveSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0).setName("FOO"); -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1).setName("BAR"); -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(2).setName("BAZ"); -// -// assertEquals(3, embeddedIdResource.getAttributeOverrides().size()); -// -// xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(2, embeddedIdResource.getAttributeOverrides().size()); -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// -// xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(1, embeddedIdResource.getAttributeOverrides().size()); -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// -// xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(0, embeddedIdResource.getAttributeOverrides().size()); -// } -// -// public void testMoveSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0).setName("FOO"); -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1).setName("BAR"); -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(2).setName("BAZ"); -// -// assertEquals(3, embeddedIdResource.getAttributeOverrides().size()); -// -// -// xmlEmbeddedIdMapping.moveSpecifiedAttributeOverride(2, 0); -// ListIterator<XmlAttributeOverride> attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); -// -// -// xmlEmbeddedIdMapping.moveSpecifiedAttributeOverride(0, 1); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); -// } -// -// public void testUpdateAttributeOverrides() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverrideImpl()); -// embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverrideImpl()); -// embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverrideImpl()); -// -// embeddedIdResource.getAttributeOverrides().get(0).setName("FOO"); -// embeddedIdResource.getAttributeOverrides().get(1).setName("BAR"); -// embeddedIdResource.getAttributeOverrides().get(2).setName("BAZ"); -// -// ListIterator<XmlAttributeOverride> attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("FOO", attributeOverrides.next().getName()); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().move(2, 0); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().move(0, 1); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().remove(1); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().remove(1); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().remove(0); -// assertFalse(xmlEmbeddedIdMapping.specifiedAttributeOverrides().hasNext()); -// } - - public void testEmbeddedIdMorphToIdMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToVersionMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToTransientMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToBasicMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToEmbeddedMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - attributeOverride = ((EmbeddedMapping) ormPersistentAttribute.getMapping()).specifiedAttributeOverrides().next(); - assertEquals("override", attributeOverride.getName()); - assertEquals("OVERRIDE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - } - - public void testEmbeddedIdMorphToOneToOneMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToOneToManyMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToManyToOneMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToManyToManyMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedIdMapping ormEmbeddedMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - XmlEmbeddedId embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the resource model, verify context model updated - embeddedResource.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the resource model - embeddedResource.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedIdMapping ormEmbeddedMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - XmlEmbeddedId embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the context model, verify resource model updated - ormEmbeddedMapping.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the context model - ormEmbeddedMapping.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - - embeddedIdResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedIdResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedIdResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, embeddedIdResource.getAttributeOverrides().size()); - - ormEmbeddedIdMapping.moveSpecifiedAttributeOverride(2, 0); - ListIterator<OrmAttributeOverride> attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); - - - ormEmbeddedIdMapping.moveSpecifiedAttributeOverride(0, 1); - attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - - embeddedIdResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedIdResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedIdResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator<OrmAttributeOverride> attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().move(2, 0); - attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().move(0, 1); - attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().remove(1); - attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().remove(1); - attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().remove(0); - assertFalse(ormEmbeddedIdMapping.specifiedAttributeOverrides().hasNext()); - } - - - public void testEmbeddedMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormEmbeddedIdMapping.getName()); - - - assertFalse(ormEmbeddedIdMapping.specifiedAttributeOverrides().hasNext()); - assertFalse(ormEmbeddedIdMapping.virtualAttributeOverrides().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType persistentType2 = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //embedded mapping is virtual, specified attribute overrides should exist - OrmEmbeddedIdMapping embeddedIdMapping = (OrmEmbeddedIdMapping) persistentType.getAttributeNamed("address").getMapping(); - assertEquals(4, embeddedIdMapping.attributeOverridesSize()); - assertEquals(0, embeddedIdMapping.virtualAttributeOverridesSize()); - assertEquals(4, embeddedIdMapping.specifiedAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> specifiedAttributeOverrides = embeddedIdMapping.specifiedAttributeOverrides(); - OrmAttributeOverride attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - JavaEmbeddedIdMapping javaEmbeddedIdMapping = (JavaEmbeddedIdMapping) embeddedIdMapping.getJavaPersistentAttribute().getMapping(); - javaEmbeddedIdMapping.virtualAttributeOverrides().next().setVirtual(false); - javaEmbeddedIdMapping.specifiedAttributeOverrides().next().getColumn().setSpecifiedName("FOO_COLUMN"); - javaEmbeddedIdMapping.specifiedAttributeOverrides().next().getColumn().setSpecifiedTable("FOO_TABLE"); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) persistentType2.getJavaPersistentType().getAttributeNamed("state").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("MY_STATE_COLUMN"); - assertEquals(4, embeddedIdMapping.attributeOverridesSize()); - assertEquals(0, embeddedIdMapping.virtualAttributeOverridesSize()); - assertEquals(4, embeddedIdMapping.specifiedAttributeOverridesSize()); - specifiedAttributeOverrides = embeddedIdMapping.specifiedAttributeOverrides(); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("FOO_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - assertEquals("FOO_TABLE", attributeOverride.getColumn().getSpecifiedTable()); - - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - - - //embedded mapping is specified, virtual attribute overrides should exist - persistentType.getAttributeNamed("address").makeSpecified(); - embeddedIdMapping = (OrmEmbeddedIdMapping) persistentType.getAttributeNamed("address").getMapping(); - assertEquals(4, embeddedIdMapping.attributeOverridesSize()); - assertEquals(4, embeddedIdMapping.virtualAttributeOverridesSize()); - assertEquals(0, embeddedIdMapping.specifiedAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> virtualAttributeOverrides = embeddedIdMapping.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("city", attributeOverride.getColumn().getDefaultName()); - assertEquals(TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", attributeOverride.getColumn().getDefaultName()); - assertEquals(TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - //set one of the virtual attribute overrides to specified, verify others are still virtual - embeddedIdMapping.virtualAttributeOverrides().next().setVirtual(false); - - assertEquals(4, embeddedIdMapping.attributeOverridesSize()); - assertEquals(1, embeddedIdMapping.specifiedAttributeOverridesSize()); - assertEquals(3, embeddedIdMapping.virtualAttributeOverridesSize()); - assertEquals("id", embeddedIdMapping.specifiedAttributeOverrides().next().getName()); - virtualAttributeOverrides = embeddedIdMapping.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormEmbeddedIdMapping.getName()); - - assertEquals(4, ormEmbeddedIdMapping.specifiedAttributeOverridesSize()); - assertEquals(0, ormEmbeddedIdMapping.virtualAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> ormAttributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - - OrmAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); - OrmColumn ormColumn = ormAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, ormColumn.getSpecifiedName()); - - - ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals("id", ormAttributeOverride.getName()); - ormColumn = ormAttributeOverride.getColumn(); - assertEquals("id", ormColumn.getSpecifiedName()); - - ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals("state", ormAttributeOverride.getName()); - ormColumn = ormAttributeOverride.getColumn(); - assertEquals("A_STATE", ormColumn.getSpecifiedName()); - - ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals("zip", ormAttributeOverride.getName()); - ormColumn = ormAttributeOverride.getColumn(); - assertEquals("zip", ormColumn.getSpecifiedName()); - - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - //will be an OrmEmbeddedMapping instead of OrmEmbeddedIdMapping since that is the default - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormEmbeddedMapping.getName()); - - //TODO -// assertEquals(4, ormEmbeddedIdMapping.specifiedAttributeOverridesSize()); -// assertEquals(0, CollectionTools.size(ormEmbeddedIdMapping.defaultAttributeOverrides())); -// ListIterator<XmlAttributeOverride> ormAttributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getSpecifiedName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getSpecifiedName()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormEmbeddedIdMapping.getName()); - - assertEquals(0, ormEmbeddedIdMapping.specifiedAttributeOverridesSize()); - //TODO -// assertEquals(4, CollectionTools.size(ormEmbeddedIdMapping.defaultAttributeOverrides())); -// ListIterator<XmlAttributeOverride> ormAttributeOverrides = ormEmbeddedIdMapping.defaultAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getDefaultName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getDefaultName()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedMappingTests.java deleted file mode 100644 index 7083bc3b88..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedMappingTests.java +++ /dev/null @@ -1,743 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.AttributeOverride; -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.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -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.iterators.ArrayIterator; - -public class OrmEmbeddedMappingTests extends ContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "city"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "E_CITY"; - - public OrmEmbeddedMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private ICompilationUnit createTestEntityEmbeddedMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @Embedded"); - sb.append(CR); - sb.append(" @AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - 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.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.COLUMN); - sb.append(";"); - sb.append(CR); - 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(" @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(" @Column(name=\"A_STATE\")").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); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the resource model, verify context model updated - embeddedResource.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the resource model - embeddedResource.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the context model, verify resource model updated - ormEmbeddedMapping.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the context model - ormEmbeddedMapping.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - -// public void testAddSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); -// OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); -// XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); -// -// OrmAttributeOverride attributeOverride = ormEmbeddedMapping.addSpecifiedAttributeOverride(0); -// attributeOverride.setName("FOO"); -// -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(0).getName()); -// -// OrmAttributeOverride attributeOverride2 = ormEmbeddedMapping.addSpecifiedAttributeOverride(0); -// attributeOverride2.setName("BAR"); -// -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(1).getName()); -// -// OrmAttributeOverride attributeOverride3 = ormEmbeddedMapping.addSpecifiedAttributeOverride(1); -// attributeOverride3.setName("BAZ"); -// -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); -// -// ListIterator<OrmAttributeOverride> attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// assertEquals(attributeOverride2, attributeOverrides.next()); -// assertEquals(attributeOverride3, attributeOverrides.next()); -// assertEquals(attributeOverride, attributeOverrides.next()); -// -// attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// } -// -// public void testRemoveSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); -// OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); -// XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); -// -// ormEmbeddedMapping.addSpecifiedAttributeOverride(0).setName("FOO"); -// ormEmbeddedMapping.addSpecifiedAttributeOverride(1).setName("BAR"); -// ormEmbeddedMapping.addSpecifiedAttributeOverride(2).setName("BAZ"); -// -// assertEquals(3, embeddedResource.getAttributeOverrides().size()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(2, embeddedResource.getAttributeOverrides().size()); -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(1, embeddedResource.getAttributeOverrides().size()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(0).getName()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(0, embeddedResource.getAttributeOverrides().size()); -// } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - - embeddedResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, embeddedResource.getAttributeOverrides().size()); - - ormEmbeddedMapping.moveSpecifiedAttributeOverride(2, 0); - ListIterator<OrmAttributeOverride> attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); - - - ormEmbeddedMapping.moveSpecifiedAttributeOverride(0, 1); - attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", embeddedResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - - embeddedResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator<OrmAttributeOverride> attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().move(2, 0); - attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().move(0, 1); - attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(1); - attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(1); - attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(0); - assertFalse(ormEmbeddedMapping.specifiedAttributeOverrides().hasNext()); - } - - - public void testEmbeddedMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormEmbeddedMapping.getName()); - - - assertFalse(ormEmbeddedMapping.specifiedAttributeOverrides().hasNext()); - assertFalse(ormEmbeddedMapping.virtualAttributeOverrides().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType persistentType2 = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //embedded mapping is virtual, specified attribute overrides should exist - OrmEmbeddedMapping embeddedMapping = (OrmEmbeddedMapping) persistentType.getAttributeNamed("address").getMapping(); - assertEquals(4, embeddedMapping.attributeOverridesSize()); - assertEquals(0, embeddedMapping.virtualAttributeOverridesSize()); - assertEquals(4, embeddedMapping.specifiedAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> specifiedAttributeOverrides = embeddedMapping.specifiedAttributeOverrides(); - OrmAttributeOverride attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - JavaEmbeddedMapping javaEmbeddedMapping = (JavaEmbeddedMapping) embeddedMapping.getJavaPersistentAttribute().getMapping(); - javaEmbeddedMapping.specifiedAttributeOverrides().next().getColumn().setSpecifiedName("FOO_COLUMN"); - javaEmbeddedMapping.specifiedAttributeOverrides().next().getColumn().setSpecifiedTable("FOO_TABLE"); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) persistentType2.getJavaPersistentType().getAttributeNamed("state").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("MY_STATE_COLUMN"); - assertEquals(4, embeddedMapping.attributeOverridesSize()); - assertEquals(0, embeddedMapping.virtualAttributeOverridesSize()); - assertEquals(4, embeddedMapping.specifiedAttributeOverridesSize()); - specifiedAttributeOverrides = embeddedMapping.specifiedAttributeOverrides(); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("FOO_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - assertEquals("FOO_TABLE", attributeOverride.getColumn().getSpecifiedTable()); - - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - - - //embedded mapping is specified, virtual attribute overrides should exist - persistentType.getAttributeNamed("address").makeSpecified(); - ormResource().save(null); - embeddedMapping = (OrmEmbeddedMapping) persistentType.getAttributeNamed("address").getMapping(); - assertEquals(4, embeddedMapping.attributeOverridesSize()); - assertEquals(4, embeddedMapping.virtualAttributeOverridesSize()); - assertEquals(0, embeddedMapping.specifiedAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> virtualAttributeOverrides = embeddedMapping.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("city", attributeOverride.getColumn().getDefaultName()); - assertEquals(TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", attributeOverride.getColumn().getDefaultName()); - assertEquals(TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - //set one of the virtual attribute overrides to specified, verify others are still virtual - embeddedMapping.virtualAttributeOverrides().next().setVirtual(false); - - assertEquals(4, embeddedMapping.attributeOverridesSize()); - assertEquals(1, embeddedMapping.specifiedAttributeOverridesSize()); - assertEquals(3, embeddedMapping.virtualAttributeOverridesSize()); - assertEquals("id", embeddedMapping.specifiedAttributeOverrides().next().getName()); - virtualAttributeOverrides = embeddedMapping.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormEmbeddedMapping.getName()); - - assertEquals(4, ormEmbeddedMapping.specifiedAttributeOverridesSize()); - assertEquals(0, ormEmbeddedMapping.virtualAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> ormAttributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - - OrmAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); - OrmColumn ormColumn = ormAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, ormColumn.getSpecifiedName()); - - - ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals("id", ormAttributeOverride.getName()); - ormColumn = ormAttributeOverride.getColumn(); - assertEquals("id", ormColumn.getSpecifiedName()); - - ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals("state", ormAttributeOverride.getName()); - ormColumn = ormAttributeOverride.getColumn(); - assertEquals("A_STATE", ormColumn.getSpecifiedName()); - - ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals("zip", ormAttributeOverride.getName()); - ormColumn = ormAttributeOverride.getColumn(); - assertEquals("zip", ormColumn.getSpecifiedName()); - - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormEmbeddedMapping.getName()); - - //TODO -// assertEquals(4, ormEmbeddedMapping.specifiedAttributeOverridesSize()); -// assertEquals(0, CollectionTools.size(ormEmbeddedMapping.defaultAttributeOverrides())); -// ListIterator<XmlAttributeOverride> ormAttributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getSpecifiedName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getSpecifiedName()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormEmbeddedMapping.getName()); - - assertEquals(0, ormEmbeddedMapping.specifiedAttributeOverridesSize()); - //TODO -// assertEquals(4, CollectionTools.size(ormEmbeddedMapping.defaultAttributeOverrides())); -// ListIterator<XmlAttributeOverride> ormAttributeOverrides = ormEmbeddedMapping.defaultAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getDefaultName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getDefaultName()); - } - - - public void testEmbeddedMorphToIdMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToVersionMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToTransientMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToBasicMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToEmbeddedIdMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - attributeOverride = ((EmbeddedIdMapping) ormPersistentAttribute.getMapping()).specifiedAttributeOverrides().next(); - assertEquals("override", attributeOverride.getName()); - assertEquals("OVERRIDE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - } - - public void testEmbeddedMorphToOneToOneMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToOneToManyMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToManyToOneMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToManyToManyMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEntityTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEntityTests.java deleted file mode 100644 index 2ec0ffca80..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEntityTests.java +++ /dev/null @@ -1,2224 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.InheritanceType; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -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; - -public class OrmEntityTests extends ContextModelTestCase -{ - - protected static final String CHILD_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_CHILD_TYPE_NAME = PACKAGE_NAME + "." + CHILD_TYPE_NAME; - - public OrmEntityTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private ICompilationUnit createTestEntityDefaultFieldAccess() 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 createTestEntityFieldAccess() 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 createTestEntityPropertyAccess() 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 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(CHILD_TYPE_NAME).append(" "); - sb.append("extends ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private void createTestSubTypeUnmapped() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append(CHILD_TYPE_NAME).append(" "); - sb.append("extends ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - - 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); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @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 void createTestAbstractType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public abstract class ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, sourceWriter); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedName()); - assertNull(entityResource.getName()); - - //set name in the resource model, verify context model updated - entityResource.setName("foo"); - assertEquals("foo", ormEntity.getSpecifiedName()); - assertEquals("foo", entityResource.getName()); - - //set name to null in the resource model - entityResource.setName(null); - assertNull(ormEntity.getSpecifiedName()); - assertNull(entityResource.getName()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedName()); - assertNull(entityResource.getName()); - - //set name in the context model, verify resource model modified - ormEntity.setSpecifiedName("foo"); - assertEquals("foo", ormEntity.getSpecifiedName()); - assertEquals("foo", entityResource.getName()); - - //set name to null in the context model - ormEntity.setSpecifiedName(null); - assertNull(ormEntity.getSpecifiedName()); - assertNull(entityResource.getName()); - } - - public void testUpdateDefaultName() throws Exception { - createTestEntityFieldAccess(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(TYPE_NAME, ormEntity.getDefaultName()); - - ormEntity.getJavaEntity().setSpecifiedName("Foo"); - //xml default entity name comes from java - assertEquals("Foo", ormEntity.getDefaultName()); - - //set class in the resource model, verify context model updated - entityResource.setClassName("com.Bar"); - assertEquals("Bar", ormEntity.getDefaultName()); - - //set class to null in the resource model - entityResource.setClassName(null); - assertNull(ormEntity.getDefaultName()); - - entityResource.setClassName(FULLY_QUALIFIED_TYPE_NAME); - assertEquals("Foo", ormEntity.getDefaultName()); - entityResource.setMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME, ormEntity.getDefaultName()); - - ormEntity.getJavaEntity().setSpecifiedName("Foo1"); - assertEquals(TYPE_NAME, ormEntity.getDefaultName()); - - entityResource.setMetadataComplete(null); - assertEquals("Foo1", ormEntity.getDefaultName()); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("Foo", ormEntity.getName()); - - //set class in the resource model, verify context model updated - entityResource.setClassName("com.Bar"); - assertEquals("Bar", ormEntity.getName()); - - entityResource.setName("Baz"); - assertEquals("Baz", ormEntity.getName()); - - //set class to null in the resource model - entityResource.setClassName(null); - assertEquals("Baz", ormEntity.getName()); - - entityResource.setName(null); - assertNull(ormEntity.getName()); - } - - public void testUpdateClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals("model.Foo", entityResource.getClassName()); - - //set class in the resource model, verify context model updated - entityResource.setClassName("com.Bar"); - assertEquals("com.Bar", ormEntity.getClass_()); - assertEquals("com.Bar", entityResource.getClassName()); - - //set class to null in the resource model - entityResource.setClassName(null); - assertNull(ormEntity.getClass_()); - assertNull(entityResource.getClassName()); - } - - public void testModifyClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals("model.Foo", entityResource.getClassName()); - - //set class in the context model, verify resource model modified - ormEntity.setClass("com.Bar"); - assertEquals("com.Bar", ormEntity.getClass_()); - assertEquals("com.Bar", entityResource.getClassName()); - - //set class to null in the context model - ormEntity.setClass(null); - assertNull(ormEntity.getClass_()); - assertNull(entityResource.getClassName()); - } - //TODO add tests for setting the className when the package is set on entity-mappings - - public void testUpdateSpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - - //set access in the resource model, verify context model updated - entityResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, ormEntity.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, entityResource.getAccess()); - - //set access to null in the resource model - entityResource.setAccess(null); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - } - - public void testModifySpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - - //set access in the context model, verify resource model modified - ormEntity.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormEntity.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entityResource.getAccess()); - - //set access to null in the context model - ormEntity.setSpecifiedAccess(null); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - } - - public void testUpdateDefaultAccessFromPersistenceUnitDefaults() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(ormEntity.getDefaultAccess()); - assertNull(entityResource.getAccess()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormEntity.getDefaultAccess()); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(ormEntity.getDefaultAccess()); - assertNull(entityResource.getAccess()); - } - - public void testUpdateDefaultAccessFromJava() throws Exception { - createTestEntityDefaultFieldAccess(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - //java has no annotations, so defaultAccess in xml is null - assertNull(ormEntity.getDefaultAccess()); - - entityMappings().setSpecifiedAccess(AccessType.FIELD); - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - //entityMappings access wins over persistence-unit-defaults access - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - - entityMappings().setSpecifiedAccess(null); - //persistence-unit-defaults access used now - assertEquals(AccessType.PROPERTY, ormEntity.getDefaultAccess()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertNull(ormEntity.getDefaultAccess()); - - ormPersistentType.getJavaPersistentType().getAttributeNamed("id").setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - //java has annotations on fields now, that should win in all cases - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - - entityMappings().setSpecifiedAccess(AccessType.PROPERTY); - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - - ormPersistentType.getJavaPersistentType().getAttributeNamed("id").setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals(AccessType.PROPERTY, ormEntity.getDefaultAccess()); - } - - public void testUpdateDefaultAccessFromJavaFieldAccess() throws Exception { - createTestEntityFieldAccess(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertNull(ormEntity.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertNull(ormEntity.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertNull(ormEntity.getDefaultAccess()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - } - - public void testUpdateDefaultAccessFromJavaPropertyAccess() throws Exception { - createTestEntityPropertyAccess(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(AccessType.PROPERTY, ormEntity.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertNull(ormEntity.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(AccessType.PROPERTY, ormEntity.getDefaultAccess()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertNull(ormEntity.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertNull(ormEntity.getDefaultAccess()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals(AccessType.PROPERTY, ormEntity.getDefaultAccess()); - } - - public void testUpdateDefaultAccessNoUnderlyingJava() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getDefaultAccess()); - } - - public void testUpdateSpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - //set metadata-complete in the resource model, verify context model updated - entityResource.setMetadataComplete(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(Boolean.TRUE, entityResource.getMetadataComplete()); - - //set access to false in the resource model - entityResource.setMetadataComplete(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(Boolean.FALSE, entityResource.getMetadataComplete()); - - entityResource.setMetadataComplete(null); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - } - - public void testModifySpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - //set access in the context model, verify resource model modified - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertTrue(ormEntity.getSpecifiedMetadataComplete().booleanValue()); - assertTrue(entityResource.getMetadataComplete().booleanValue()); - - //set access to null in the context model - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertFalse(ormEntity.getSpecifiedMetadataComplete().booleanValue()); - assertFalse(entityResource.getMetadataComplete().booleanValue()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - } - - public void testUpdateDefaultMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertFalse(ormEntity.isDefaultMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormEntity.isDefaultMetadataComplete()); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertFalse(ormEntity.isDefaultMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormEntity.getSpecifiedMetadataComplete()); - assertTrue(ormEntity.isDefaultMetadataComplete()); - assertTrue(ormEntity.isMetadataComplete()); - } - - public void testUpdateMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertFalse(ormEntity.isMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormEntity.isMetadataComplete()); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertFalse(ormEntity.isMetadataComplete()); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - } - - - public void testUpdateInheritanceStrategy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - - //set inheritance strategy in the resource model, verify context model updated - entityResource.setInheritance(OrmFactory.eINSTANCE.createInheritance()); - entityResource.getInheritance().setStrategy(org.eclipse.jpt.core.resource.orm.InheritanceType.TABLE_PER_CLASS); - - assertEquals(InheritanceType.TABLE_PER_CLASS, ormEntity.getInheritanceStrategy()); - assertEquals(org.eclipse.jpt.core.resource.orm.InheritanceType.TABLE_PER_CLASS, entityResource.getInheritance().getStrategy()); - } - - public void testUpdateDefaultInheritanceStrategyFromJava() throws Exception { - createTestEntityDefaultFieldAccess(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - //no inheritance strategy specified in java so single-table is default - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertEquals(InheritanceType.JOINED, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - //inheritance tag exists in xml, so it overrides anything in java - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.setSpecifiedInheritanceStrategy(null); - assertEquals(InheritanceType.JOINED, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(InheritanceType.JOINED, ormEntity.getDefaultInheritanceStrategy()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - //this setting overrides the false meta-data complete found on ormEntity - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getDefaultInheritanceStrategy()); - } - - public void testUpdateDefaultInheritanceStrategyFromParent() throws Exception { - createTestEntityDefaultFieldAccess(); - createTestSubType(); - - OrmPersistentType parentPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentXmlEntity = (OrmEntity) parentPersistentType.getMapping(); - OrmEntity childXmlEntity = (OrmEntity) childPersistentType.getMapping(); - - assertEquals(parentXmlEntity, childXmlEntity.getParentEntity()); - assertEquals(InheritanceType.SINGLE_TABLE, childXmlEntity.getDefaultInheritanceStrategy()); - - //change root inheritance strategy, verify default is changed for child entity - parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - assertEquals(InheritanceType.SINGLE_TABLE, parentXmlEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, childXmlEntity.getDefaultInheritanceStrategy()); - assertNull(childXmlEntity.getSpecifiedInheritanceStrategy()); - - //set specified inheritance strategy in java and verify defaults in xml are correct - parentXmlEntity.setSpecifiedInheritanceStrategy(null); - parentXmlEntity.getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertEquals(InheritanceType.JOINED, parentXmlEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.JOINED, childXmlEntity.getDefaultInheritanceStrategy()); - assertNull(parentXmlEntity.getSpecifiedInheritanceStrategy()); - assertNull(childXmlEntity.getSpecifiedInheritanceStrategy()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(InheritanceType.SINGLE_TABLE, parentXmlEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.SINGLE_TABLE, childXmlEntity.getDefaultInheritanceStrategy()); - } - - public void testUpdateSpecifiedInheritanceStrategy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - - //set strategy in the resource model, verify context model updated - entityResource.setInheritance(OrmFactory.eINSTANCE.createInheritance()); - entityResource.getInheritance().setStrategy(org.eclipse.jpt.core.resource.orm.InheritanceType.JOINED); - assertEquals(InheritanceType.JOINED, ormEntity.getSpecifiedInheritanceStrategy()); - assertEquals(org.eclipse.jpt.core.resource.orm.InheritanceType.JOINED, entityResource.getInheritance().getStrategy()); - - //set strategy to null in the resource model - entityResource.getInheritance().setStrategy(null); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance().getStrategy()); - - entityResource.getInheritance().setStrategy(org.eclipse.jpt.core.resource.orm.InheritanceType.SINGLE_TABLE); - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getSpecifiedInheritanceStrategy()); - assertEquals(org.eclipse.jpt.core.resource.orm.InheritanceType.SINGLE_TABLE, entityResource.getInheritance().getStrategy()); - - entityResource.setInheritance(null); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - } - - public void testModifySpecifiedInheritanceStrategy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - - //set strategy in the context model, verify resource model modified - ormEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - assertEquals(InheritanceType.TABLE_PER_CLASS, ormEntity.getSpecifiedInheritanceStrategy()); - assertEquals(org.eclipse.jpt.core.resource.orm.InheritanceType.TABLE_PER_CLASS, entityResource.getInheritance().getStrategy()); - - //set strategy to null in the context model - ormEntity.setSpecifiedInheritanceStrategy(null); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - } - - public void testAddSpecifiedSecondaryTable() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - OrmSecondaryTable secondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable.setSpecifiedName("FOO"); - - assertEquals("FOO", entityResource.getSecondaryTables().get(0).getName()); - - OrmSecondaryTable secondaryTable2 = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable2.setSpecifiedName("BAR"); - - assertEquals("BAR", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(1).getName()); - - OrmSecondaryTable secondaryTable3 = ormEntity.addSpecifiedSecondaryTable(1); - secondaryTable3.setSpecifiedName("BAZ"); - - assertEquals("BAR", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("BAZ", entityResource.getSecondaryTables().get(1).getName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(2).getName()); - - ListIterator<OrmSecondaryTable> secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals(secondaryTable2, secondaryTables.next()); - assertEquals(secondaryTable3, secondaryTables.next()); - assertEquals(secondaryTable, secondaryTables.next()); - - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - } - - public void testRemoveSpecifiedSecondaryTable() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - ormEntity.addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - ormEntity.addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getSecondaryTables().size()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertEquals(2, entityResource.getSecondaryTables().size()); - assertEquals("BAR", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("BAZ", entityResource.getSecondaryTables().get(1).getName()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertEquals(1, entityResource.getSecondaryTables().size()); - assertEquals("BAZ", entityResource.getSecondaryTables().get(0).getName()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testMoveSpecifiedSecondaryTable() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - ormEntity.addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - ormEntity.addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getSecondaryTables().size()); - - - ormEntity.moveSpecifiedSecondaryTable(2, 0); - ListIterator<OrmSecondaryTable> secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - - assertEquals("BAR", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("BAZ", entityResource.getSecondaryTables().get(1).getName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(2).getName()); - - - ormEntity.moveSpecifiedSecondaryTable(0, 1); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - - assertEquals("BAZ", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("BAR", entityResource.getSecondaryTables().get(1).getName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(2).getName()); - } - - public void testUpdateSecondaryTables() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTableImpl()); - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTableImpl()); - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTableImpl()); - - entityResource.getSecondaryTables().get(0).setName("FOO"); - entityResource.getSecondaryTables().get(1).setName("BAR"); - entityResource.getSecondaryTables().get(2).setName("BAZ"); - - ListIterator<OrmSecondaryTable> secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().move(2, 0); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().move(0, 1); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().remove(1); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().remove(1); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().remove(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - } - - public void testVirtualSecondaryTables() throws Exception { - createTestEntityFieldAccess(); - createTestSubType(); - - OrmPersistentType parentPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentOrmEntity = (OrmEntity) parentPersistentType.getMapping(); - OrmEntity childOrmEntity = (OrmEntity) childPersistentType.getMapping(); - JavaEntity javaEntity = childOrmEntity.getJavaEntity(); - - JavaSecondaryTable javaSecondaryTableFoo = javaEntity.addSpecifiedSecondaryTable(0); - javaSecondaryTableFoo.setSpecifiedName("FOO"); - OrmSecondaryTable virtualSecondaryTableFoo = childOrmEntity.virtualSecondaryTables().next(); - assertEquals("FOO", childOrmEntity.secondaryTables().next().getName()); - assertEquals("FOO", virtualSecondaryTableFoo.getName()); - assertEquals(0, virtualSecondaryTableFoo.specifiedPrimaryKeyJoinColumnsSize()); - assertEquals("id", virtualSecondaryTableFoo.getDefaultPrimaryKeyJoinColumn().getDefaultName()); - assertEquals("id", virtualSecondaryTableFoo.getDefaultPrimaryKeyJoinColumn().getDefaultReferencedColumnName()); - - assertEquals(0, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(1, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(1, childOrmEntity.secondaryTablesSize()); - - javaEntity.addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - ListIterator<OrmSecondaryTable> virtualSecondaryTables = childOrmEntity.virtualSecondaryTables(); - ListIterator<OrmSecondaryTable> secondaryTables = childOrmEntity.secondaryTables(); - assertEquals("BAR", virtualSecondaryTables.next().getName()); - assertEquals("FOO", virtualSecondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals(0, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(2, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(2, childOrmEntity.secondaryTablesSize()); - - childOrmEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(0, childOrmEntity.virtualSecondaryTablesSize()); - - childOrmEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(2, childOrmEntity.virtualSecondaryTablesSize()); - - - childOrmEntity.setSecondaryTablesDefinedInXml(true); - assertEquals(0, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(2, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(2, childOrmEntity.secondaryTablesSize()); - ListIterator<OrmSecondaryTable> specifiedSecondaryTables = childOrmEntity.specifiedSecondaryTables(); - assertEquals("BAR", specifiedSecondaryTables.next().getName()); - OrmSecondaryTable specifiedSecondaryTableFoo = specifiedSecondaryTables.next(); - assertEquals("FOO", specifiedSecondaryTableFoo.getName()); - assertEquals(0, specifiedSecondaryTableFoo.specifiedPrimaryKeyJoinColumnsSize()); - assertEquals("id", specifiedSecondaryTableFoo.getDefaultPrimaryKeyJoinColumn().getDefaultName()); - assertEquals("id", specifiedSecondaryTableFoo.getDefaultPrimaryKeyJoinColumn().getDefaultReferencedColumnName()); - - - childOrmEntity.removeSpecifiedSecondaryTable(0); - assertEquals(0, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(1, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(1, childOrmEntity.secondaryTablesSize()); - assertEquals("FOO", childOrmEntity.specifiedSecondaryTables().next().getName()); - - - childOrmEntity.removeSpecifiedSecondaryTable(0); - assertEquals(0, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(2, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(2, childOrmEntity.secondaryTablesSize()); - virtualSecondaryTables = childOrmEntity.virtualSecondaryTables(); - assertEquals("BAR", virtualSecondaryTables.next().getName()); - assertEquals("FOO", virtualSecondaryTables.next().getName()); - - - //add a specified secondary table to the parent, this will not affect virtual secondaryTables in child - parentOrmEntity.addSpecifiedSecondaryTable(0).setSpecifiedName("PARENT_TABLE"); - assertEquals(2, childOrmEntity.virtualSecondaryTablesSize()); - } - - public void testAssociatedTables() throws Exception { - createTestEntityFieldAccess(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - assertEquals(1, CollectionTools.size(entity.associatedTables())); - - entity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - assertEquals(2, CollectionTools.size(entity.associatedTables())); - - entity.addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - assertEquals(3, CollectionTools.size(entity.associatedTables())); - } - - public void testAssociatedTableNamesIncludingInherited() throws Exception { - - } - - public void testTableNameIsInvalid() throws Exception { - - } - - public void testMakeEntityEmbeddable() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity entity = (OrmEntity) entityPersistentType.getMapping(); - entity.setSpecifiedAccess(AccessType.PROPERTY); - entity.setSpecifiedDiscriminatorValue("DISC_VALUE"); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - entity.setSpecifiedName("ENTITY_NAME"); - - entityPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - XmlEmbeddable embeddable = ormResource().getEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", embeddable.getClassName()); - assertEquals(Boolean.TRUE, embeddable.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddable.getAccess()); - - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) entityPersistentType.getMapping(); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEmbeddable.getSpecifiedAccess()); - } - - //TODO test that attribute mappings are not removed when changing type mapping. - public void testMakeEntityEmbeddable2() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - OrmEntity entity = (OrmEntity) entityPersistentType.getMapping(); - entity.setSpecifiedAccess(AccessType.PROPERTY); - entity.setSpecifiedDiscriminatorValue("DISC_VALUE"); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - entity.setSpecifiedName("ENTITY_NAME"); -// entityPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - - entityPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - XmlEmbeddable embeddable = ormResource().getEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", embeddable.getClassName()); - assertEquals(Boolean.TRUE, embeddable.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddable.getAccess()); -// assertEquals("basicMapping", embeddable.getAttributes().getBasics().get(0).getName()); - - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) entityPersistentType.getMapping(); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEmbeddable.getSpecifiedAccess()); -// assertEquals("basicMapping", ormEmbeddable.persistentType().attributes().next().getName()); - } - - public void testMakeEntityMappedSuperclass() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity entity = (OrmEntity) entityPersistentType.getMapping(); - entity.setSpecifiedAccess(AccessType.PROPERTY); - entity.setSpecifiedDiscriminatorValue("DISC_VALUE"); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - entity.setSpecifiedName("ENTITY_NAME"); - - entityPersistentType.setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - - XmlMappedSuperclass mappedSuperclass = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", mappedSuperclass.getClassName()); - assertEquals(Boolean.TRUE, mappedSuperclass.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclass.getAccess()); - - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) entityPersistentType.getMapping(); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormMappedSuperclass.getSpecifiedAccess()); - } - - public void testMakeEntityMappedSuperclass2() throws Exception { - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity entity = (OrmEntity) entityPersistentType.getMapping(); - entity.setSpecifiedAccess(AccessType.PROPERTY); - entity.setSpecifiedDiscriminatorValue("DISC_VALUE"); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - entity.setSpecifiedName("ENTITY_NAME"); - - entityPersistentType.setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - - XmlMappedSuperclass mappedSuperclass = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", mappedSuperclass.getClassName()); - assertEquals(Boolean.TRUE, mappedSuperclass.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclass.getAccess()); - - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) entityPersistentType.getMapping(); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormMappedSuperclass.getSpecifiedAccess()); - } - - - public void testAddSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - - ormEntity.addSequenceGenerator(); - - assertNotNull(entityResource.getSequenceGenerator()); - assertNotNull(ormEntity.getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - ormEntity.addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - - ormEntity.addSequenceGenerator(); - assertNotNull(entityResource.getSequenceGenerator()); - assertNotNull(ormEntity.getSequenceGenerator()); - - ormEntity.removeSequenceGenerator(); - - assertNull(ormEntity.getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - - //try removing the sequence generator again, should get an IllegalStateException - try { - ormEntity.removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - - entityResource.setSequenceGenerator(OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl()); - - assertNotNull(ormEntity.getSequenceGenerator()); - assertNotNull(entityResource.getSequenceGenerator()); - assertEquals(1, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - - ormEntity.getSequenceGenerator().setName("foo"); - assertEquals(1, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - - entityResource.setSequenceGenerator(null); - assertNull(ormEntity.getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - } - - public void testAddTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - - ormEntity.addTableGenerator(); - - assertNotNull(entityResource.getTableGenerator()); - assertNotNull(ormEntity.getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - ormEntity.addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - - ormEntity.addTableGenerator(); - assertNotNull(entityResource.getTableGenerator()); - assertNotNull(ormEntity.getTableGenerator()); - - ormEntity.removeTableGenerator(); - - assertNull(ormEntity.getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - - //try removing the table generator again, should get an IllegalStateException - try { - ormEntity.removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - - entityResource.setTableGenerator(OrmFactory.eINSTANCE.createXmlTableGeneratorImpl()); - - assertNotNull(ormEntity.getTableGenerator()); - assertNotNull(entityResource.getTableGenerator()); - assertEquals(1, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - - ormEntity.getTableGenerator().setName("foo"); - assertEquals(1, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - - entityResource.setTableGenerator(null); - assertNull(ormEntity.getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - } - - public void testUpdateDiscriminatorColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNotNull(ormEntity.getDiscriminatorColumn()); - - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setName("FOO"); - - assertEquals("FOO", ormEntity.getDiscriminatorColumn().getSpecifiedName()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getName()); - - entityResource.getDiscriminatorColumn().setName(null); - - assertNull(ormEntity.getDiscriminatorColumn().getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn().getName()); - - entityResource.setDiscriminatorColumn(null); - - assertNotNull(ormEntity.getDiscriminatorColumn()); - } - - public void testUpdateDiscriminatorValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getSpecifiedDiscriminatorValue()); - assertNull(entityResource.getDiscriminatorValue()); - - entityResource.setDiscriminatorValue("FOO"); - - assertEquals("FOO", ormEntity.getSpecifiedDiscriminatorValue()); - assertEquals("FOO", entityResource.getDiscriminatorValue()); - - entityResource.setDiscriminatorValue(null); - - assertNull(ormEntity.getSpecifiedDiscriminatorValue()); - assertNull(entityResource.getDiscriminatorValue()); - } - - public void testModifyDiscriminatorValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getSpecifiedDiscriminatorValue()); - assertNull(entityResource.getDiscriminatorValue()); - - ormEntity.setSpecifiedDiscriminatorValue("FOO"); - - assertEquals("FOO", ormEntity.getSpecifiedDiscriminatorValue()); - assertEquals("FOO", entityResource.getDiscriminatorValue()); - - ormEntity.setSpecifiedDiscriminatorValue(null); - - assertNull(ormEntity.getSpecifiedDiscriminatorValue()); - assertNull(entityResource.getDiscriminatorValue()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - primaryKeyJoinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn2 = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - primaryKeyJoinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn3 = ormEntity.addSpecifiedPrimaryKeyJoinColumn(1); - primaryKeyJoinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(2).getName()); - - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals(primaryKeyJoinColumn2, primaryKeyJoinColumns.next()); - assertEquals(primaryKeyJoinColumn3, primaryKeyJoinColumns.next()); - assertEquals(primaryKeyJoinColumn, primaryKeyJoinColumns.next()); - - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - } - - public void testRemoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormEntity.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormEntity.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getPrimaryKeyJoinColumns().size()); - - ormEntity.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(2, entityResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - - ormEntity.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(1, entityResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - - ormEntity.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(0, entityResource.getPrimaryKeyJoinColumns().size()); - } - - public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormEntity.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormEntity.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getPrimaryKeyJoinColumns().size()); - - - ormEntity.moveSpecifiedPrimaryKeyJoinColumn(2, 0); - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(2).getName()); - - - ormEntity.moveSpecifiedPrimaryKeyJoinColumn(0, 1); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(2).getName()); - } - - public void testUpdatePrimaryKeyJoinColumns() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl()); - entityResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl()); - entityResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl()); - - entityResource.getPrimaryKeyJoinColumns().get(0).setName("FOO"); - entityResource.getPrimaryKeyJoinColumns().get(1).setName("BAR"); - entityResource.getPrimaryKeyJoinColumns().get(2).setName("BAZ"); - - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().move(2, 0); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().move(0, 1); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().remove(1); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().remove(1); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormEntity.specifiedPrimaryKeyJoinColumns().hasNext()); - } - - public void testDefaultPrimaryKeyJoinColumns() throws Exception { - createTestType(); - createTestSubTypeUnmapped(); - - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - childPersistentType.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - persistentType.getAttributeNamed("id").makeSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - ((OrmEntity) persistentType.getMapping()).setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - - OrmEntity childEntity = (OrmEntity) childPersistentType.getMapping(); - - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - - childPersistentType.getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - persistentType.getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - - OrmPrimaryKeyJoinColumn specifiedPkJoinColumn = childEntity.addSpecifiedPrimaryKeyJoinColumn(0); - specifiedPkJoinColumn.setSpecifiedName("FOO"); - specifiedPkJoinColumn.setSpecifiedReferencedColumnName("BAR"); - - assertFalse(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - - //remove the pkJoinColumn from the context mode, verify context model has a default pkJoinColumn - childEntity.removeSpecifiedPrimaryKeyJoinColumn(0); - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - - - childPersistentType.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - persistentType.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - specifiedPkJoinColumn = childEntity.addSpecifiedPrimaryKeyJoinColumn(0); - specifiedPkJoinColumn.setSpecifiedName("FOO"); - specifiedPkJoinColumn.setSpecifiedReferencedColumnName("BAR"); - assertFalse(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - //now remove the pkJoinColumn from the resource model, verify context model updates and has a default pkJoinColumn - ((XmlEntity)childEntity.getResourceTypeMapping()).getPrimaryKeyJoinColumns().remove(0); - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - } - - public void testDefaultPrimaryKeyJoinColumnsFromJava() throws Exception { - createTestEntityFieldAccess(); - createTestSubType(); - - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - - - ((JavaEntity) persistentType.getJavaPersistentType().getMapping()).setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - - OrmEntity childEntity = (OrmEntity) childPersistentType.getMapping(); - - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - - JavaEntity javaEntity = (JavaEntity) childPersistentType.getJavaPersistentType().getMapping(); - JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn = javaEntity.addSpecifiedPrimaryKeyJoinColumn(0); - javaPrimaryKeyJoinColumn.setSpecifiedName("FOO"); - javaPrimaryKeyJoinColumn.setSpecifiedReferencedColumnName("BAR"); - - JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn2 = javaEntity.addSpecifiedPrimaryKeyJoinColumn(1); - javaPrimaryKeyJoinColumn2.setSpecifiedName("FOO2"); - javaPrimaryKeyJoinColumn2.setSpecifiedReferencedColumnName("BAR2"); - - childPersistentType.getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - persistentType.getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - ListIterator<OrmPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns = childEntity.defaultPrimaryKeyJoinColumns(); - OrmPrimaryKeyJoinColumn defaultPrimaryKeyJoinColumn = defaultPrimaryKeyJoinColumns.next(); - assertEquals("FOO", defaultPrimaryKeyJoinColumn.getName()); - assertEquals("BAR", defaultPrimaryKeyJoinColumn.getReferencedColumnName()); - - defaultPrimaryKeyJoinColumn = defaultPrimaryKeyJoinColumns.next(); - assertEquals("FOO2", defaultPrimaryKeyJoinColumn.getName()); - assertEquals("BAR2", defaultPrimaryKeyJoinColumn.getReferencedColumnName()); - assertFalse(defaultPrimaryKeyJoinColumns.hasNext()); - - childEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - defaultPrimaryKeyJoinColumns = childEntity.defaultPrimaryKeyJoinColumns(); - defaultPrimaryKeyJoinColumn = defaultPrimaryKeyJoinColumns.next(); - assertEquals("id", defaultPrimaryKeyJoinColumn.getDefaultName()); - assertEquals("id", defaultPrimaryKeyJoinColumn.getDefaultReferencedColumnName()); - - assertFalse(defaultPrimaryKeyJoinColumns.hasNext()); - - } - -// public void testAddSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); -// XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// -// OrmAttributeOverride attributeOverride = ormEntity.addSpecifiedAttributeOverride(0); -// attributeOverride.setName("FOO"); -// -// assertEquals("FOO", entityResource.getAttributeOverrides().get(0).getName()); -// -// OrmAttributeOverride attributeOverride2 = ormEntity.addSpecifiedAttributeOverride(0); -// attributeOverride2.setName("BAR"); -// -// assertEquals("BAR", entityResource.getAttributeOverrides().get(0).getName()); -// assertEquals("FOO", entityResource.getAttributeOverrides().get(1).getName()); -// -// OrmAttributeOverride attributeOverride3 = ormEntity.addSpecifiedAttributeOverride(1); -// attributeOverride3.setName("BAZ"); -// -// assertEquals("BAR", entityResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", entityResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", entityResource.getAttributeOverrides().get(2).getName()); -// -// ListIterator<OrmAttributeOverride> attributeOverrides = ormEntity.specifiedAttributeOverrides(); -// assertEquals(attributeOverride2, attributeOverrides.next()); -// assertEquals(attributeOverride3, attributeOverrides.next()); -// assertEquals(attributeOverride, attributeOverrides.next()); -// -// attributeOverrides = ormEntity.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// } -// -// public void testRemoveSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); -// -// ormEntity.addSpecifiedAttributeOverride(0).setName("FOO"); -// ormEntity.addSpecifiedAttributeOverride(1).setName("BAR"); -// ormEntity.addSpecifiedAttributeOverride(2).setName("BAZ"); -// -// XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// assertEquals(3, entityResource.getAttributeOverrides().size()); -// -// ormEntity.removeSpecifiedAttributeOverride(0); -// assertEquals(2, entityResource.getAttributeOverrides().size()); -// assertEquals("BAR", entityResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", entityResource.getAttributeOverrides().get(1).getName()); -// -// ormEntity.removeSpecifiedAttributeOverride(0); -// assertEquals(1, entityResource.getAttributeOverrides().size()); -// assertEquals("BAZ", entityResource.getAttributeOverrides().get(0).getName()); -// -// ormEntity.removeSpecifiedAttributeOverride(0); -// assertEquals(0, entityResource.getAttributeOverrides().size()); -// } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - - entityResource.getAttributeOverrides().get(0).setName("FOO"); - entityResource.getAttributeOverrides().get(1).setName("BAR"); - entityResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, entityResource.getAttributeOverrides().size()); - - - ormEntity.moveSpecifiedAttributeOverride(2, 0); - ListIterator<OrmAttributeOverride> attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", entityResource.getAttributeOverrides().get(2).getName()); - - - ormEntity.moveSpecifiedAttributeOverride(0, 1); - attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", entityResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - - entityResource.getAttributeOverrides().get(0).setName("FOO"); - entityResource.getAttributeOverrides().get(1).setName("BAR"); - entityResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator<OrmAttributeOverride> attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().move(2, 0); - attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().move(0, 1); - attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(1); - attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(1); - attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - assertFalse(ormEntity.specifiedAttributeOverrides().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - OrmPersistentType persistentType2 = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - - assertEquals(3, entity.virtualAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> virtualAttributeOverrides = entity.virtualAttributeOverrides(); - OrmAttributeOverride attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", attributeOverride.getName()); - - entity.virtualAttributeOverrides().next().setVirtual(false); - - assertEquals(2, entity.virtualAttributeOverridesSize()); - virtualAttributeOverrides = entity.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", attributeOverride.getName()); - - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, entity.virtualAttributeOverridesSize()); - virtualAttributeOverrides = entity.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", attributeOverride.getName()); - - entity.specifiedAttributeOverrides().next().setVirtual(true); - entity.setSpecifiedMetadataComplete(Boolean.FALSE); - entity.getJavaEntity().virtualAttributeOverrides().next().setVirtual(false); - entity.getJavaEntity().specifiedAttributeOverrides().next().getColumn().setSpecifiedName("FOO"); - assertEquals(3, entity.virtualAttributeOverridesSize()); - virtualAttributeOverrides = entity.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - assertEquals("FOO", attributeOverride.getColumn().getSpecifiedName());//TODO specified or default? - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", attributeOverride.getName()); - assertEquals("name", attributeOverride.getColumn().getSpecifiedName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", attributeOverride.getName()); - - persistentType2.getAttributeNamed("name").makeSpecified(); - OrmBasicMapping basicMapping = (OrmBasicMapping) persistentType2.getAttributeNamed("name").getMapping(); - basicMapping.getColumn().setSpecifiedName("MY_NAME"); - - assertEquals(3, entity.virtualAttributeOverridesSize()); - virtualAttributeOverrides = entity.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", attributeOverride.getName()); - assertEquals("MY_NAME", attributeOverride.getColumn().getSpecifiedName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - assertEquals("FOO", attributeOverride.getColumn().getSpecifiedName());//TODO specified or default? - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", attributeOverride.getName()); - } - - public void testVirtualAttributeOverridesNoJavaEntity() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - - persistentType.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(3, entity.virtualAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> virtualAttributeOverrides = entity.virtualAttributeOverrides(); - OrmAttributeOverride attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", attributeOverride.getName()); - } - - public void testAttributeOverrideColumnDefaults() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - - entity.virtualAttributeOverrides().next().setVirtual(false); - - OrmAttributeOverride attributeOverride = entity.specifiedAttributeOverrides().next(); - assertEquals("id", attributeOverride.getColumn().getDefaultName()); - assertEquals(CHILD_TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - - ((JavaEntity) persistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("FOO"); - assertEquals("id", attributeOverride.getColumn().getDefaultName()); - assertEquals("FOO", attributeOverride.getColumn().getDefaultTable()); - - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals("id", attributeOverride.getColumn().getDefaultName()); - assertEquals(CHILD_TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - - entity.setSpecifiedMetadataComplete(Boolean.FALSE); - entity.getTable().setSpecifiedName("BAR"); - assertEquals("id", attributeOverride.getColumn().getDefaultName()); - assertEquals("BAR", attributeOverride.getColumn().getDefaultTable()); - } - -// public void testAddSpecifiedAssociationOverride() throws Exception { -// OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); -// XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// -// OrmAssociationOverride associationOverride = ormEntity.addSpecifiedAssociationOverride(0); -// associationOverride.setName("FOO"); -// -// assertEquals("FOO", entityResource.getAssociationOverrides().get(0).getName()); -// -// OrmAssociationOverride associationOverride2 = ormEntity.addSpecifiedAssociationOverride(0); -// associationOverride2.setName("BAR"); -// -// assertEquals("BAR", entityResource.getAssociationOverrides().get(0).getName()); -// assertEquals("FOO", entityResource.getAssociationOverrides().get(1).getName()); -// -// OrmAssociationOverride associationOverride3 = ormEntity.addSpecifiedAssociationOverride(1); -// associationOverride3.setName("BAZ"); -// -// assertEquals("BAR", entityResource.getAssociationOverrides().get(0).getName()); -// assertEquals("BAZ", entityResource.getAssociationOverrides().get(1).getName()); -// assertEquals("FOO", entityResource.getAssociationOverrides().get(2).getName()); -// -// ListIterator<OrmAssociationOverride> associationOverrides = ormEntity.specifiedAssociationOverrides(); -// assertEquals(associationOverride2, associationOverrides.next()); -// assertEquals(associationOverride3, associationOverrides.next()); -// assertEquals(associationOverride, associationOverrides.next()); -// -// associationOverrides = ormEntity.specifiedAssociationOverrides(); -// assertEquals("BAR", associationOverrides.next().getName()); -// assertEquals("BAZ", associationOverrides.next().getName()); -// assertEquals("FOO", associationOverrides.next().getName()); -// } -// -// public void testRemoveSpecifiedAssociationOverride() throws Exception { -// OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); -// -// ormEntity.addSpecifiedAssociationOverride(0).setName("FOO"); -// ormEntity.addSpecifiedAssociationOverride(1).setName("BAR"); -// ormEntity.addSpecifiedAssociationOverride(2).setName("BAZ"); -// -// XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// assertEquals(3, entityResource.getAssociationOverrides().size()); -// -// ormEntity.removeSpecifiedAssociationOverride(0); -// assertEquals(2, entityResource.getAssociationOverrides().size()); -// assertEquals("BAR", entityResource.getAssociationOverrides().get(0).getName()); -// assertEquals("BAZ", entityResource.getAssociationOverrides().get(1).getName()); -// -// ormEntity.removeSpecifiedAssociationOverride(0); -// assertEquals(1, entityResource.getAssociationOverrides().size()); -// assertEquals("BAZ", entityResource.getAssociationOverrides().get(0).getName()); -// -// ormEntity.removeSpecifiedAssociationOverride(0); -// assertEquals(0, entityResource.getAssociationOverrides().size()); -// } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - - entityResource.getAssociationOverrides().get(0).setName("FOO"); - entityResource.getAssociationOverrides().get(1).setName("BAR"); - entityResource.getAssociationOverrides().get(2).setName("BAZ"); - - assertEquals(3, entityResource.getAssociationOverrides().size()); - - - ormEntity.moveSpecifiedAssociationOverride(2, 0); - ListIterator<OrmAssociationOverride> associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - - assertEquals("BAR", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("BAZ", entityResource.getAssociationOverrides().get(1).getName()); - assertEquals("FOO", entityResource.getAssociationOverrides().get(2).getName()); - - - ormEntity.moveSpecifiedAssociationOverride(0, 1); - associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - - assertEquals("BAZ", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("BAR", entityResource.getAssociationOverrides().get(1).getName()); - assertEquals("FOO", entityResource.getAssociationOverrides().get(2).getName()); - } - - public void testUpdateAssociationOverrides() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - - entityResource.getAssociationOverrides().get(0).setName("FOO"); - entityResource.getAssociationOverrides().get(1).setName("BAR"); - entityResource.getAssociationOverrides().get(2).setName("BAZ"); - - ListIterator<OrmAssociationOverride> associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().move(2, 0); - associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().move(0, 1); - associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(1); - associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(1); - associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(0); - assertFalse(ormEntity.specifiedAssociationOverrides().hasNext()); - } - - - public void testAddNamedQuery() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - OrmNamedQuery namedQuery = ormEntity.addNamedQuery(0); - namedQuery.setName("FOO"); - - assertEquals("FOO", entityResource.getNamedQueries().get(0).getName()); - - OrmNamedQuery namedQuery2 = ormEntity.addNamedQuery(0); - namedQuery2.setName("BAR"); - - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(1).getName()); - - OrmNamedQuery namedQuery3 = ormEntity.addNamedQuery(1); - namedQuery3.setName("BAZ"); - - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - - ListIterator<OrmNamedQuery> namedQueries = ormEntity.namedQueries(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery, namedQueries.next()); - - namedQueries = ormEntity.namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - } - - public void testRemoveNamedQuery() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addNamedQuery(0).setName("FOO"); - ormEntity.addNamedQuery(1).setName("BAR"); - ormEntity.addNamedQuery(2).setName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedQueries().size()); - - ormEntity.removeNamedQuery(0); - assertEquals(2, entityResource.getNamedQueries().size()); - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedQueries().get(1).getName()); - - ormEntity.removeNamedQuery(0); - assertEquals(1, entityResource.getNamedQueries().size()); - assertEquals("BAZ", entityResource.getNamedQueries().get(0).getName()); - - ormEntity.removeNamedQuery(0); - assertEquals(0, entityResource.getNamedQueries().size()); - } - - public void testMoveNamedQuery() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addNamedQuery(0).setName("FOO"); - ormEntity.addNamedQuery(1).setName("BAR"); - ormEntity.addNamedQuery(2).setName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedQueries().size()); - - - ormEntity.moveNamedQuery(2, 0); - ListIterator<OrmNamedQuery> namedQueries = ormEntity.namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - - - ormEntity.moveNamedQuery(0, 1); - namedQueries = ormEntity.namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAZ", entityResource.getNamedQueries().get(0).getName()); - assertEquals("BAR", entityResource.getNamedQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - } - - public void testUpdateNamedQueries() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().get(0).setName("FOO"); - entityResource.getNamedQueries().get(1).setName("BAR"); - entityResource.getNamedQueries().get(2).setName("BAZ"); - - ListIterator<OrmNamedQuery> namedQueries = ormEntity.namedQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - entityResource.getNamedQueries().move(2, 0); - namedQueries = ormEntity.namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - entityResource.getNamedQueries().move(0, 1); - namedQueries = ormEntity.namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - entityResource.getNamedQueries().remove(1); - namedQueries = ormEntity.namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - entityResource.getNamedQueries().remove(1); - namedQueries = ormEntity.namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - entityResource.getNamedQueries().remove(0); - assertFalse(ormEntity.namedQueries().hasNext()); - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - } - - public void testAddNamedNativeQuery() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - OrmNamedNativeQuery namedNativeQuery = ormEntity.addNamedNativeQuery(0); - namedNativeQuery.setName("FOO"); - - assertEquals("FOO", entityResource.getNamedNativeQueries().get(0).getName()); - - OrmNamedNativeQuery namedNativeQuery2 = ormEntity.addNamedNativeQuery(0); - namedNativeQuery2.setName("BAR"); - - assertEquals("BAR", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("FOO", entityResource.getNamedNativeQueries().get(1).getName()); - - OrmNamedNativeQuery namedNativeQuery3 = ormEntity.addNamedNativeQuery(1); - namedNativeQuery3.setName("BAZ"); - - assertEquals("BAR", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedNativeQueries().get(2).getName()); - - ListIterator<OrmNamedNativeQuery> namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals(namedNativeQuery2, namedNativeQueries.next()); - assertEquals(namedNativeQuery3, namedNativeQueries.next()); - assertEquals(namedNativeQuery, namedNativeQueries.next()); - - namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - } - - public void testRemoveNamedNativeQuery() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addNamedNativeQuery(0).setName("FOO"); - ormEntity.addNamedNativeQuery(1).setName("BAR"); - ormEntity.addNamedNativeQuery(2).setName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedNativeQueries().size()); - - ormEntity.removeNamedNativeQuery(0); - assertEquals(2, entityResource.getNamedNativeQueries().size()); - assertEquals("BAR", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(1).getName()); - - ormEntity.removeNamedNativeQuery(0); - assertEquals(1, entityResource.getNamedNativeQueries().size()); - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(0).getName()); - - ormEntity.removeNamedNativeQuery(0); - assertEquals(0, entityResource.getNamedNativeQueries().size()); - } - - public void testMoveNamedNativeQuery() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addNamedNativeQuery(0).setName("FOO"); - ormEntity.addNamedNativeQuery(1).setName("BAR"); - ormEntity.addNamedNativeQuery(2).setName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedNativeQueries().size()); - - - ormEntity.moveNamedNativeQuery(2, 0); - ListIterator<OrmNamedNativeQuery> namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - - assertEquals("BAR", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedNativeQueries().get(2).getName()); - - - ormEntity.moveNamedNativeQuery(0, 1); - namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("BAR", entityResource.getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedNativeQueries().get(2).getName()); - } - - public void testUpdateNamedNativeQueries() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - entityResource.getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - entityResource.getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - entityResource.getNamedNativeQueries().get(0).setName("FOO"); - entityResource.getNamedNativeQueries().get(1).setName("BAR"); - entityResource.getNamedNativeQueries().get(2).setName("BAZ"); - ListIterator<OrmNamedNativeQuery> namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(3, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - entityResource.getNamedNativeQueries().move(2, 0); - namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - - entityResource.getNamedNativeQueries().move(0, 1); - namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - - entityResource.getNamedNativeQueries().remove(1); - namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(2, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - entityResource.getNamedNativeQueries().remove(1); - namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(1, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - entityResource.getNamedNativeQueries().remove(0); - assertFalse(ormEntity.namedNativeQueries().hasNext()); - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - } - - public void testUpdateIdClass() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getIdClass()); - assertNull(entityResource.getIdClass()); - - entityResource.setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - - assertNull(ormEntity.getIdClass()); - assertNotNull(entityResource.getIdClass()); - - entityResource.getIdClass().setClassName("model.Foo"); - assertEquals("model.Foo", ormEntity.getIdClass()); - assertEquals("model.Foo", entityResource.getIdClass().getClassName()); - - //test setting @IdClass value to null, id-class tag is not removed - entityResource.getIdClass().setClassName(null); - assertNull(ormEntity.getIdClass()); - assertNotNull(entityResource.getIdClass()); - - //reset @IdClass value and then remove id-class tag - entityResource.setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - entityResource.getIdClass().setClassName("model.Foo"); - entityResource.setIdClass(null); - - assertNull(ormEntity.getIdClass()); - assertNull(entityResource.getIdClass()); - } - - public void testModifyIdClass() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getIdClass()); - assertNull(entityResource.getIdClass()); - - ormEntity.setIdClass("model.Foo"); - assertEquals("model.Foo", entityResource.getIdClass().getClassName()); - assertEquals("model.Foo", ormEntity.getIdClass()); - - ormEntity.setIdClass(null); - assertNull(ormEntity.getIdClass()); - assertNull(entityResource.getIdClass()); - } - - - public void testGetPrimaryKeyColumnNameWithAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType parentPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity childXmlEntity = (OrmEntity) childPersistentType.getMapping(); - - assertNull(childXmlEntity.getPrimaryKeyColumnName()); - - parentPersistentType.getAttributeNamed("id").makeSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("id", childXmlEntity.getPrimaryKeyColumnName()); - - ((OrmIdMapping) parentPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID"); - assertEquals("MY_ID", childXmlEntity.getPrimaryKeyColumnName()); - - //TODO once bug 228718 is fixed -// OrmAttributeOverride ormAttributeOverride = childXmlEntity.virtualAttributeOverrides().next(); -// assertEquals("id", ormAttributeOverride.getName()); -// -// ormAttributeOverride = (OrmAttributeOverride) ormAttributeOverride.setVirtual(false); -// ormAttributeOverride.getColumn().setSpecifiedName("ID"); -// assertEquals("ID", childXmlEntity.getPrimaryKeyColumnName()); - } - - - public void testDiscriminatorValueIsAllowedConcreteClass() throws Exception { - createTestType(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - assertTrue(entity.isDiscriminatorValueAllowed()); - } - - public void testDiscriminatorValueIsAllowedAbstractClass() throws Exception { - createTestAbstractType(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - assertFalse(entity.isDiscriminatorValueAllowed()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmGeneratedValueTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmGeneratedValueTests.java deleted file mode 100644 index c1d0ccada3..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmGeneratedValueTests.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.GeneratedValue; -import org.eclipse.jpt.core.context.GenerationType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.orm.OrmGeneratedValue; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.resource.orm.XmlId; -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.iterators.ArrayIterator; - -public class OrmGeneratedValueTests extends ContextModelTestCase -{ - public OrmGeneratedValueTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - 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 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 void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - OrmGeneratedValue ormGeneratedValue = ormIdMapping.addGeneratedValue(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - XmlGeneratedValue generatedValueResource = idResource.getGeneratedValue(); - - //set generator in the resource model, verify context model updated - generatedValueResource.setGenerator("FOO"); - assertEquals("FOO", ormGeneratedValue.getSpecifiedGenerator()); - assertEquals("FOO", generatedValueResource.getGenerator()); - - //set name to null in the resource model - generatedValueResource.setGenerator(null); - assertNull(ormGeneratedValue.getSpecifiedGenerator()); - assertNull(generatedValueResource.getGenerator()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - OrmGeneratedValue ormGeneratedValue = ormIdMapping.addGeneratedValue(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - XmlGeneratedValue generatedValueResource = idResource.getGeneratedValue(); - - //set name in the context model, verify resource model modified - ormGeneratedValue.setSpecifiedGenerator("FOO"); - assertEquals("FOO", generatedValueResource.getGenerator()); - assertEquals("FOO", ormGeneratedValue.getSpecifiedGenerator()); - - //set name to null in the context model - ormGeneratedValue.setSpecifiedGenerator(null); - assertNull(generatedValueResource.getGenerator()); - assertNull(ormGeneratedValue.getSpecifiedGenerator()); - } - - public void testDefaultsFromJava() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormIdAttribute = ormPersistentType.virtualAttributes().next(); - IdMapping ormIdMapping = (IdMapping) ormIdAttribute.getMapping(); - assertEquals(null, ormIdMapping.getGeneratedValue()); - - IdMapping javaIdMapping = (IdMapping) ormPersistentType.getJavaPersistentType().attributes().next().getMapping(); - GeneratedValue javaGeneratedValue = javaIdMapping.addGeneratedValue(); - javaGeneratedValue.setSpecifiedGenerator("Foo"); - javaGeneratedValue.setSpecifiedStrategy(GenerationType.SEQUENCE); - - assertEquals("Foo", ormIdMapping.getGeneratedValue().getSpecifiedGenerator()); - assertEquals(GenerationType.SEQUENCE, ormIdMapping.getGeneratedValue().getSpecifiedStrategy()); - assertEquals("Foo", javaGeneratedValue.getSpecifiedGenerator()); - assertEquals(GenerationType.SEQUENCE, javaGeneratedValue.getSpecifiedStrategy()); - - ormIdAttribute.makeSpecified(); - ormIdAttribute = ormPersistentType.specifiedAttributes().next(); - ormIdMapping = (IdMapping) ormIdAttribute.getMapping(); - assertEquals(null, ormIdMapping.getGeneratedValue()); - assertEquals("Foo", javaGeneratedValue.getSpecifiedGenerator()); - assertEquals(GenerationType.SEQUENCE, javaGeneratedValue.getSpecifiedStrategy()); - - ormIdAttribute.makeVirtual(); - ormIdAttribute = ormPersistentType.virtualAttributes().next(); - ormIdMapping = (IdMapping) ormIdAttribute.getMapping(); - assertEquals("Foo", ormIdMapping.getGeneratedValue().getSpecifiedGenerator()); - assertEquals(GenerationType.SEQUENCE, ormIdMapping.getGeneratedValue().getSpecifiedStrategy()); - assertEquals("Foo", javaGeneratedValue.getSpecifiedGenerator()); - assertEquals(GenerationType.SEQUENCE, javaGeneratedValue.getSpecifiedStrategy()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmIdMappingTests.java deleted file mode 100644 index 0dc6c8e6c9..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmIdMappingTests.java +++ /dev/null @@ -1,744 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.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.GenerationType; -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.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.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmGeneratedValue; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlId; -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.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class OrmIdMappingTests extends ContextModelTestCase -{ - public OrmIdMappingTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private ICompilationUnit createTestEntityIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.COLUMN, JPA.TEMPORAL, JPA.TEMPORAL_TYPE, JPA.GENERATED_VALUE, JPA.GENERATION_TYPE, JPA.TABLE_GENERATOR, JPA.SEQUENCE_GENERATOR); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append(CR); - sb.append(" @Column(name=\"MY_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\", length=5, precision=6, scale=7)"); - sb.append(CR); - sb.append(" @Temporal(TemporalType.TIMESTAMP)"); - sb.append(CR); - sb.append(" @GeneratedValue(strategy=GenerationType.TABLE, generator=\"myTableGenerator\")"); - sb.append(CR); - sb.append(" @TableGenerator(name=\"myTableGenerator\", table=\"myTable\", catalog=\"myCatalog\", schema=\"mySchema\", pkColumnName=\"myPkColumnName\", valueColumnName=\"myValueColumnName\", pkColumnValue=\"myPkColumnValue\", initialValue=1, allocationSize=1)"); - sb.append(CR); - sb.append(" @SequenceGenerator(name=\"mySequenceGenerator\")"); - } - }); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertEquals("idMapping", ormIdMapping.getName()); - assertEquals("idMapping", idResource.getName()); - - //set name in the resource model, verify context model updated - idResource.setName("newName"); - assertEquals("newName", ormIdMapping.getName()); - assertEquals("newName", idResource.getName()); - - //set name to null in the resource model - idResource.setName(null); - assertNull(ormIdMapping.getName()); - assertNull(idResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertEquals("idMapping", ormIdMapping.getName()); - assertEquals("idMapping", idResource.getName()); - - //set name in the context model, verify resource model updated - ormIdMapping.setName("newName"); - assertEquals("newName", ormIdMapping.getName()); - assertEquals("newName", idResource.getName()); - - //set name to null in the context model - ormIdMapping.setName(null); - assertNull(ormIdMapping.getName()); - assertNull(idResource.getName()); - } - - public void testUpdateTemporal() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getSpecifiedConverter()); - assertNull(idResource.getTemporal()); - - //set temporal in the resource model, verify context model updated - idResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.DATE); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormIdMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, idResource.getTemporal()); - - idResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIME); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormIdMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, idResource.getTemporal()); - - idResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormIdMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, idResource.getTemporal()); - - //set temporal to null in the resource model - idResource.setTemporal(null); - assertNull(ormIdMapping.getSpecifiedConverter()); - assertNull(idResource.getTemporal()); - } - - public void testModifyTemporal() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getSpecifiedConverter()); - assertNull(idResource.getTemporal()); - - //set temporal in the context model, verify resource model updated - ormIdMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) ormIdMapping.getSpecifiedConverter()).setTemporalType(TemporalType.DATE); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, idResource.getTemporal()); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormIdMapping.getSpecifiedConverter()).getTemporalType()); - - ((TemporalConverter) ormIdMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, idResource.getTemporal()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormIdMapping.getSpecifiedConverter()).getTemporalType()); - - ((TemporalConverter) ormIdMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIMESTAMP); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, idResource.getTemporal()); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormIdMapping.getSpecifiedConverter()).getTemporalType()); - - //set temporal to null in the context model - ormIdMapping.setSpecifiedConverter(null); - assertNull(idResource.getTemporal()); - assertNull(ormIdMapping.getSpecifiedConverter()); - } - - //TODO test defaults - //TODO test overriding java mapping with a different mapping type in xml - - - public void testAddSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - - ormIdMapping.addSequenceGenerator(); - - assertNotNull(idResource.getSequenceGenerator()); - assertNotNull(ormIdMapping.getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - ormIdMapping.addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - - ormIdMapping.addSequenceGenerator(); - assertNotNull(idResource.getSequenceGenerator()); - assertNotNull(ormIdMapping.getSequenceGenerator()); - - ormIdMapping.removeSequenceGenerator(); - - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - - //try removing the sequence generator again, should get an IllegalStateException - try { - ormIdMapping.removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - assertEquals(0, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - - idResource.setSequenceGenerator(OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl()); - assertNotNull(ormIdMapping.getSequenceGenerator()); - assertNotNull(idResource.getSequenceGenerator()); - assertEquals(1, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - - ormIdMapping.getSequenceGenerator().setName("foo"); - assertEquals(1, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - - idResource.setSequenceGenerator(null); - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - assertEquals(0, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - } - - public void testAddTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getTableGenerator()); - assertNull(idResource.getTableGenerator()); - - ormIdMapping.addTableGenerator(); - - assertNotNull(idResource.getTableGenerator()); - assertNotNull(ormIdMapping.getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - ormIdMapping.addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getTableGenerator()); - assertNull(idResource.getTableGenerator()); - - ormIdMapping.addTableGenerator(); - assertNotNull(idResource.getTableGenerator()); - assertNotNull(ormIdMapping.getTableGenerator()); - - ormIdMapping.removeTableGenerator(); - - assertNull(ormIdMapping.getTableGenerator()); - assertNull(idResource.getTableGenerator()); - - //try removing the table generator again, should get an IllegalStateException - try { - ormIdMapping.removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getTableGenerator()); - assertNull(idResource.getTableGenerator()); - assertEquals(0, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - - idResource.setTableGenerator(OrmFactory.eINSTANCE.createXmlTableGeneratorImpl()); - assertNotNull(ormIdMapping.getTableGenerator()); - assertNotNull(idResource.getTableGenerator()); - assertEquals(1, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - - ormIdMapping.getTableGenerator().setName("foo"); - assertEquals(1, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - - idResource.setTableGenerator(null); - assertNull(ormIdMapping.getTableGenerator()); - assertNull(idResource.getTableGenerator()); - assertEquals(0, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - } - - public void testAddGeneratedValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - - ormIdMapping.addGeneratedValue(); - - assertNotNull(idResource.getGeneratedValue()); - assertNotNull(ormIdMapping.getGeneratedValue()); - - //try adding another sequence generator, should get an IllegalStateException - try { - ormIdMapping.addGeneratedValue(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveGeneratedValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - - ormIdMapping.addGeneratedValue(); - assertNotNull(idResource.getGeneratedValue()); - assertNotNull(ormIdMapping.getGeneratedValue()); - - ormIdMapping.removeGeneratedValue(); - - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - - //try removing the sequence generator again, should get an IllegalStateException - try { - ormIdMapping.removeGeneratedValue(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateGeneratedValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - - idResource.setGeneratedValue(OrmFactory.eINSTANCE.createXmlGeneratedValueImpl()); - - assertNotNull(ormIdMapping.getGeneratedValue()); - assertNotNull(idResource.getGeneratedValue()); - - idResource.setGeneratedValue(null); - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - } - - - public void testIdMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityIdMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormIdMapping.getName()); - assertNull(ormIdMapping.getSpecifiedConverter()); - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(ormIdMapping.getTableGenerator()); - - - OrmColumn ormColumn = ormIdMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("foo", ormColumn.getDefaultName()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Integer.valueOf(255), ormColumn.getDefaultLength()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultScale()); - } - - //@Basic(fetch=FetchType.LAZY, optional=false) - //@Column(name="MY_COLUMN", unique=true, nullable=false, insertable=false, updatable=false, - // columnDefinition="COLUMN_DEFINITION", table="MY_TABLE", length=5, precision=6, scale=7)"); - //@Column( - //@Lob - //@Temporal(TemporalType.TIMESTAMP) - //@Enumerated(EnumType.STRING) - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormIdMapping.getName()); - assertEquals(Converter.TEMPORAL_CONVERTER, ormIdMapping.getConverter().getType()); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormIdMapping.getConverter()).getTemporalType()); - - OrmColumn ormColumn = ormIdMapping.getColumn(); - assertEquals("MY_COLUMN", ormColumn.getSpecifiedName()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", ormColumn.getColumnDefinition()); - assertEquals("MY_TABLE", ormColumn.getSpecifiedTable()); - assertEquals(Integer.valueOf(5), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(6), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedScale()); - - OrmGeneratedValue ormGeneratedValue = ormIdMapping.getGeneratedValue(); - assertEquals("myTableGenerator", ormGeneratedValue.getSpecifiedGenerator()); - assertEquals(GenerationType.TABLE, ormGeneratedValue.getSpecifiedStrategy()); - - OrmTableGenerator ormTableGenerator = ormIdMapping.getTableGenerator(); - assertEquals("myTableGenerator", ormTableGenerator.getName()); - assertEquals("myTable", ormTableGenerator.getSpecifiedTable()); - assertEquals("myCatalog", ormTableGenerator.getSpecifiedCatalog()); - assertEquals("mySchema", ormTableGenerator.getSpecifiedSchema()); - assertEquals("myPkColumnName", ormTableGenerator.getSpecifiedPkColumnName()); - assertEquals("myPkColumnValue", ormTableGenerator.getSpecifiedPkColumnValue()); - assertEquals("myValueColumnName", ormTableGenerator.getSpecifiedValueColumnName()); - assertEquals(Integer.valueOf(1), ormTableGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(1), ormTableGenerator.getSpecifiedAllocationSize()); - - OrmSequenceGenerator ormSequenceGenerator = ormIdMapping.getSequenceGenerator(); - assertEquals("mySequenceGenerator", ormSequenceGenerator.getName()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.makeSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormIdMapping.getName()); - assertNull(ormIdMapping.getSpecifiedConverter()); - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(ormIdMapping.getTableGenerator()); - - OrmColumn ormColumn = ormIdMapping.getColumn(); - assertEquals("id", ormColumn.getName()); - assertEquals(Boolean.FALSE, ormColumn.getUnique()); - assertEquals(Boolean.TRUE, ormColumn.getNullable()); - assertEquals(Boolean.TRUE, ormColumn.getInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getTable()); - assertEquals(Integer.valueOf(255), ormColumn.getLength()); - assertEquals(Integer.valueOf(0), ormColumn.getPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getScale()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityIdMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - - assertEquals("id", ormIdMapping.getName()); - assertNull(ormIdMapping.getSpecifiedConverter()); - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(ormIdMapping.getTableGenerator()); - - OrmColumn ormColumn = ormIdMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("id", ormColumn.getDefaultName()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Integer.valueOf(255), ormColumn.getDefaultLength()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultScale()); - } - - //3 things tested above - //1. virtual mapping metadata complete=false - defaults are taken from the java annotations - //2. virtual mapping metadata complete=true - defaults are taken from java defaults,annotations ignored - //3. specified mapping (metadata complete=true/false - defaults are taken from java annotations - - public void testIdMorphToBasicMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - assertEquals("FOO", ((BasicMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testIdMorphToVersionMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - assertEquals("FOO", ((VersionMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testIdMorphToTransientMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToEmbeddedMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToEmbeddedIdMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToOneToOneMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToOneToManyMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToManyToOneMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToManyToManyMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinColumnTests.java deleted file mode 100644 index 24a19dba28..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinColumnTests.java +++ /dev/null @@ -1,506 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -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; - -public class OrmJoinColumnTests extends ContextModelTestCase -{ - public OrmJoinColumnTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getSpecifiedName()); - assertNull(joinColumnResource.getName()); - - //set name in the resource model, verify context model updated - joinColumnResource.setName("FOO"); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("FOO", joinColumnResource.getName()); - - //set name to null in the resource model - joinColumnResource.setName(null); - assertNull(joinColumn.getSpecifiedName()); - assertNull(joinColumnResource.getName()); - - joinColumnResource.setName("FOO"); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("FOO", joinColumnResource.getName()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getSpecifiedName()); - assertNull(joinColumnResource.getName()); - - //set name in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - assertEquals("foo", joinColumn.getSpecifiedName()); - assertEquals("foo", joinColumnResource.getName()); - - //set name to null in the context model - joinColumn.setSpecifiedName(null); - assertNull(joinColumn.getSpecifiedName()); - assertNull(joinTableResource.getJoinColumns().get(0).getName()); - } - - public void testUpdateSpecifiedReferencedColumnName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(joinColumnResource.getReferencedColumnName()); - - //set name in the resource model, verify context model updated - joinColumnResource.setReferencedColumnName("FOO"); - assertEquals("FOO", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("FOO", joinColumnResource.getReferencedColumnName()); - - //set name to null in the resource model - joinColumnResource.setReferencedColumnName(null); - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(joinColumnResource.getReferencedColumnName()); - - joinColumnResource.setReferencedColumnName("FOO"); - assertEquals("FOO", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("FOO", joinColumnResource.getReferencedColumnName()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedReferencedColumnName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(joinColumnResource.getReferencedColumnName()); - - //set name in the context model, verify resource model modified - joinColumn.setSpecifiedReferencedColumnName("foo"); - assertEquals("foo", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("foo", joinColumnResource.getReferencedColumnName()); - - //set name to null in the context model - joinColumn.setSpecifiedReferencedColumnName(null); - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(joinTableResource.getJoinColumns().get(0).getReferencedColumnName()); - } - - public void testUpdateSpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getColumnDefinition()); - assertNull(joinColumnResource.getColumnDefinition()); - - //set name in the resource model, verify context model updated - joinColumnResource.setColumnDefinition("FOO"); - assertEquals("FOO", joinColumn.getColumnDefinition()); - assertEquals("FOO", joinColumnResource.getColumnDefinition()); - - //set name to null in the resource model - joinColumnResource.setColumnDefinition(null); - assertNull(joinColumn.getColumnDefinition()); - assertNull(joinColumnResource.getColumnDefinition()); - - joinColumnResource.setColumnDefinition("FOO"); - assertEquals("FOO", joinColumn.getColumnDefinition()); - assertEquals("FOO", joinColumnResource.getColumnDefinition()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getColumnDefinition()); - assertNull(joinColumnResource.getColumnDefinition()); - - //set name in the context model, verify resource model modified - joinColumn.setColumnDefinition("foo"); - assertEquals("foo", joinColumn.getColumnDefinition()); - assertEquals("foo", joinColumnResource.getColumnDefinition()); - - //set name to null in the context model - joinColumn.setColumnDefinition(null); - assertNull(joinColumn.getColumnDefinition()); - assertNull(joinTableResource.getJoinColumns().get(0).getColumnDefinition()); - } - - public void testUpdateSpecifiedTable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedTable()); - assertNull(joinColumnResource.getTable()); - - //set table in the resource model, verify context model updated - joinColumnResource.setTable("FOO"); - assertEquals("FOO", ormJoinColumn.getSpecifiedTable()); - assertEquals("FOO", joinColumnResource.getTable()); - - //set table to null in the resource model - joinColumnResource.setTable(null); - assertNull(ormJoinColumn.getSpecifiedTable()); - assertNull(joinColumnResource.getTable()); - - joinColumnResource.setTable("FOO"); - assertEquals("FOO", ormJoinColumn.getSpecifiedTable()); - assertEquals("FOO", joinColumnResource.getTable()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedTable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedTable()); - assertNull(joinColumnResource.getTable()); - - //set table in the context model, verify resource model modified - ormJoinColumn.setSpecifiedTable("foo"); - assertEquals("foo", ormJoinColumn.getSpecifiedTable()); - assertEquals("foo", joinColumnResource.getTable()); - - //set table to null in the context model - ormJoinColumn.setSpecifiedTable(null); - assertNull(ormJoinColumn.getSpecifiedTable()); - assertNull(joinTableResource.getJoinColumns().get(0).getTable()); - } - - public void testUpdateSpecifiedNullable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedNullable()); - assertNull(joinColumnResource.getNullable()); - - //set nullable in the resource model, verify context model updated - joinColumnResource.setNullable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, joinColumnResource.getNullable()); - - //set nullable to null in the resource model - joinColumnResource.setNullable(null); - assertNull(ormJoinColumn.getSpecifiedNullable()); - assertNull(joinColumnResource.getNullable()); - - joinColumnResource.setNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, joinColumnResource.getNullable()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedNullable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedNullable()); - assertNull(joinColumnResource.getNullable()); - - //set nullable in the context model, verify resource model modified - ormJoinColumn.setSpecifiedNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, joinColumnResource.getNullable()); - - //set nullable to null in the context model - ormJoinColumn.setSpecifiedNullable(null); - assertNull(ormJoinColumn.getSpecifiedNullable()); - assertNull(joinTableResource.getJoinColumns().get(0).getNullable()); - } - - public void testUpdateSpecifiedUpdatable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedUpdatable()); - assertNull(joinColumnResource.getUpdatable()); - - //set updatable in the resource model, verify context model updated - joinColumnResource.setUpdatable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, joinColumnResource.getUpdatable()); - - //set updatable to null in the resource model - joinColumnResource.setUpdatable(null); - assertNull(ormJoinColumn.getSpecifiedUpdatable()); - assertNull(joinColumnResource.getUpdatable()); - - joinColumnResource.setUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, joinColumnResource.getUpdatable()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedUpdatable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedUpdatable()); - assertNull(joinColumnResource.getUpdatable()); - - //set updatable in the context model, verify resource model modified - ormJoinColumn.setSpecifiedUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, joinColumnResource.getUpdatable()); - - //set updatable to null in the context model - ormJoinColumn.setSpecifiedUpdatable(null); - assertNull(ormJoinColumn.getSpecifiedUpdatable()); - assertNull(joinTableResource.getJoinColumns().get(0).getUpdatable()); - } - - public void testUpdateSpecifiedInsertable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedInsertable()); - assertNull(joinColumnResource.getInsertable()); - - //set insertable in the resource model, verify context model updated - joinColumnResource.setInsertable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, joinColumnResource.getInsertable()); - - //set insertable to null in the resource model - joinColumnResource.setInsertable(null); - assertNull(ormJoinColumn.getSpecifiedInsertable()); - assertNull(joinColumnResource.getInsertable()); - - joinColumnResource.setInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, joinColumnResource.getInsertable()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedInsertable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedInsertable()); - assertNull(joinColumnResource.getInsertable()); - - //set insertable in the context model, verify resource model modified - ormJoinColumn.setSpecifiedInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, joinColumnResource.getInsertable()); - - //set insertable to null in the context model - ormJoinColumn.setSpecifiedInsertable(null); - assertNull(ormJoinColumn.getSpecifiedInsertable()); - assertNull(joinTableResource.getJoinColumns().get(0).getInsertable()); - } - - public void testUpdateSpecifiedUnique() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedUnique()); - assertNull(joinColumnResource.getUnique()); - - //set unique in the resource model, verify context model updated - joinColumnResource.setUnique(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, joinColumnResource.getUnique()); - - //set unique to null in the resource model - joinColumnResource.setUnique(null); - assertNull(ormJoinColumn.getSpecifiedUnique()); - assertNull(joinColumnResource.getUnique()); - - joinColumnResource.setUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, joinColumnResource.getUnique()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedUnique() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedUnique()); - assertNull(joinColumnResource.getUnique()); - - //set unique in the context model, verify resource model modified - ormJoinColumn.setSpecifiedUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, joinColumnResource.getUnique()); - - //set unique to null in the context model - ormJoinColumn.setSpecifiedUnique(null); - assertNull(ormJoinColumn.getSpecifiedUnique()); - assertNull(joinTableResource.getJoinColumns().get(0).getUnique()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinTableTests.java deleted file mode 100644 index b4a1da69d8..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinTableTests.java +++ /dev/null @@ -1,1156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -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.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class OrmJoinTableTests extends ContextModelTestCase -{ - public OrmJoinTableTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - 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, JPA.ID, "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); - sb.append("@Id").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 { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable()); - - - //set name in the resource model, verify context model updated - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - manyToMany.getJoinTable().setName("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedName()); - assertEquals("FOO", manyToMany.getJoinTable().getName()); - - //set name to null in the resource model - manyToMany.getJoinTable().setName(null); - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable().getName()); - - manyToMany.getJoinTable().setName("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedName()); - assertEquals("FOO", manyToMany.getJoinTable().getName()); - - manyToMany.setJoinTable(null); - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable()); - - //set name in the context model, verify resource model modified - ormJoinTable.setSpecifiedName("foo"); - assertEquals("foo", ormJoinTable.getSpecifiedName()); - assertEquals("foo", manyToMany.getJoinTable().getName()); - - //set name to null in the context model - ormJoinTable.setSpecifiedName(null); - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable()); - } - - public void testVirtualJoinTable() throws Exception { - createTestEntityWithValidManyToMany(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("projects"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(null, ormJoinTable.getSpecifiedName()); - - createTargetEntity(); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Project"); - - assertEquals(TYPE_NAME + "_Project", ormJoinTable.getSpecifiedName()); - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(ormJoinTable.getSpecifiedSchema()); - assertEquals(0, ormJoinTable.specifiedJoinColumnsSize()); - assertEquals(0, ormJoinTable.specifiedInverseJoinColumnsSize()); - OrmJoinColumn ormJoinColumn = ormJoinTable.getDefaultJoinColumn(); -//TODO need to test joinColumn defaults here as well as in java and all the relatioship mapping types -// assertEquals("id_project_id", ormJoinColumn.getDefaultName()); -// assertEquals("id_project_id", ormJoinColumn.getDefaultReferencedColumnName()); - OrmJoinColumn inverseOrmJoinColumn = ormJoinTable.getDefaultInverseJoinColumn(); -// assertEquals("id_project_id", inverseOrmJoinColumn.getDefaultName()); -// assertEquals("id_project_id", inverseOrmJoinColumn.getDefaultReferencedColumnName()); - - JavaPersistentAttribute javaPersistentAttribute = ormManyToManyMapping.getJavaPersistentAttribute(); - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) javaPersistentAttribute.getMapping(); - JavaJoinTable javaJoinTable = javaManyToManyMapping.getJoinTable(); - javaJoinTable.setSpecifiedName("FOO"); - javaJoinTable.setSpecifiedCatalog("CATALOG"); - javaJoinTable.setSpecifiedSchema("SCHEMA"); - JavaJoinColumn javaJoinColumn = javaJoinTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCED_NAME"); - JavaJoinColumn inverseJavaJoinColumn = javaJoinTable.addSpecifiedInverseJoinColumn(0); - inverseJavaJoinColumn.setSpecifiedName("INVERSE_NAME"); - inverseJavaJoinColumn.setSpecifiedReferencedColumnName("INVERSE_REFERENCED_NAME"); - - assertEquals("FOO", ormJoinTable.getSpecifiedName()); - assertEquals("CATALOG", ormJoinTable.getSpecifiedCatalog()); - assertEquals("SCHEMA", ormJoinTable.getSpecifiedSchema()); - assertEquals(1, ormJoinTable.specifiedJoinColumnsSize()); - assertEquals(1, ormJoinTable.specifiedInverseJoinColumnsSize()); - ormJoinColumn = ormJoinTable.specifiedJoinColumns().next(); - assertEquals("NAME", ormJoinColumn.getSpecifiedName()); - assertEquals("REFERENCED_NAME", ormJoinColumn.getSpecifiedReferencedColumnName()); - inverseOrmJoinColumn = ormJoinTable.specifiedInverseJoinColumns().next(); - assertEquals("INVERSE_NAME", inverseOrmJoinColumn.getSpecifiedName()); - assertEquals("INVERSE_REFERENCED_NAME", inverseOrmJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntityWithValidManyToMany(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "projects"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - assertEquals(null, ormJoinTable.getDefaultName()); - - createTargetEntity(); - OrmPersistentType targetPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Project"); - assertEquals(TYPE_NAME + "_Project", ormJoinTable.getDefaultName()); - - - ((JavaEntity) targetPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_FOO", ormJoinTable.getDefaultName()); - - ((JavaEntity) ormPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("BAR"); - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - ormPersistentType.getJavaPersistentType().getAttributeNamed("projects").setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - JavaManyToManyMapping javaManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("projects").getMapping(); - javaManyMapping.getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - - //set metadata-complete to true, will ignore java annotation settings - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME + "_Project", ormJoinTable.getDefaultName()); - - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - //remove m-m mapping from the orm.xml file - ormPersistentAttribute.makeVirtual(); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("projects"); - ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - ormJoinTable = ormManyToManyMapping.getJoinTable(); - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals("JAVA_JOIN_TABLE", ormManyToManyMapping.getJoinTable().getSpecifiedName());//specifiedName since this is a virtual mapping now - - javaManyMapping.getJoinTable().setSpecifiedName(null); - assertEquals("BAR_FOO", ormJoinTable.getSpecifiedName()); - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE_NAME"); - assertEquals("ORM_TABLE_NAME_FOO", ormJoinTable.getDefaultName()); - - ((OrmEntity) targetPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TARGET"); - assertEquals("ORM_TABLE_NAME_ORM_TARGET", ormJoinTable.getDefaultName()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable()); - - //set schema in the resource model, verify context model updated - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - manyToMany.getJoinTable().setSchema("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedSchema()); - assertEquals("FOO", manyToMany.getJoinTable().getSchema()); - - //set Schema to null in the resource model - manyToMany.getJoinTable().setSchema(null); - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable().getSchema()); - - manyToMany.getJoinTable().setSchema("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedSchema()); - assertEquals("FOO", manyToMany.getJoinTable().getSchema()); - - manyToMany.setJoinTable(null); - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable()); - } - -// public void testUpdateDefaultSchemaFromJavaTable() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.javaEntity().getTable().setSpecifiedSchema("Foo"); -// assertEquals("Foo", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.setSpecifiedMetadataComplete(Boolean.TRUE); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); -// xmlEntity.setSpecifiedMetadataComplete(Boolean.FALSE); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.setSpecifiedMetadataComplete(null); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); -// assertEquals("Foo", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.getTable().setSpecifiedName("Bar"); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// } -// -// public void testUpdateDefaultSchemaNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// } -// -// public void testUpdateDefaultSchemaFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertNull(parentXmlEntity.getTable().getDefaultSchema()); -// assertNull(childXmlEntity.getTable().getDefaultSchema()); -// -// parentXmlEntity.getTable().setSpecifiedSchema("FOO"); -// assertNull(parentXmlEntity.getTable().getDefaultSchema()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultSchema()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertNull(parentXmlEntity.getTable().getDefaultSchema()); -// assertNull(childXmlEntity.getTable().getDefaultSchema()); -// } -// -// public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema("FOO"); -// assertEquals("FOO", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().setSpecifiedSchema("BAR"); -// assertEquals("BAR", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.javaEntity().getTable().setSpecifiedSchema("JAVA_SCHEMA"); -// assertEquals("JAVA_SCHEMA", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.getTable().setSpecifiedName("BLAH"); -// //xml entity now has a table element so default schema is not taken from java -// assertEquals("BAR", xmlEntity.getTable().getDefaultSchema()); -// -// -// xmlEntity.entityMappings().setSpecifiedSchema(null); -// assertEquals("FOO", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema(null); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.getTable().setSpecifiedName(null); -// assertEquals("JAVA_SCHEMA", xmlEntity.getTable().getDefaultSchema()); -// } - - public void testModifySpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable()); - - //set Schema in the context model, verify resource model modified - ormJoinTable.setSpecifiedSchema("foo"); - assertEquals("foo", ormJoinTable.getSpecifiedSchema()); - assertEquals("foo", manyToMany.getJoinTable().getSchema()); - - //set Schema to null in the context model - ormJoinTable.setSpecifiedSchema(null); - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable()); - - //set Catalog in the resource model, verify context model updated - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - manyToMany.getJoinTable().setCatalog("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedCatalog()); - assertEquals("FOO", manyToMany.getJoinTable().getCatalog()); - - //set Catalog to null in the resource model - manyToMany.getJoinTable().setCatalog(null); - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable().getCatalog()); - - manyToMany.getJoinTable().setCatalog("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedCatalog()); - assertEquals("FOO", manyToMany.getJoinTable().getCatalog()); - - manyToMany.setJoinTable(null); - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable()); - } - - public void testModifySpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable()); - - //set Catalog in the context model, verify resource model modified - ormJoinTable.setSpecifiedCatalog("foo"); - assertEquals("foo", ormJoinTable.getSpecifiedCatalog()); - assertEquals("foo", manyToMany.getJoinTable().getCatalog()); - - //set Catalog to null in the context model - ormJoinTable.setSpecifiedCatalog(null); - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable()); - } - -// public void testUpdateDefaultCatalogFromJavaTable() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.javaEntity().getTable().setSpecifiedCatalog("Foo"); -// assertEquals("Foo", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.setSpecifiedMetadataComplete(Boolean.TRUE); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); -// xmlEntity.setSpecifiedMetadataComplete(Boolean.FALSE); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.setSpecifiedMetadataComplete(null); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); -// assertEquals("Foo", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.getTable().setSpecifiedName("Bar"); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// } -// -// public void testUpdateDefaultCatalogNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// } -// -// public void testUpdateDefaultCatalogFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertNull(parentXmlEntity.getTable().getDefaultCatalog()); -// assertNull(childXmlEntity.getTable().getDefaultCatalog()); -// -// parentXmlEntity.getTable().setSpecifiedCatalog("FOO"); -// assertNull(parentXmlEntity.getTable().getDefaultCatalog()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultCatalog()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertNull(parentXmlEntity.getTable().getDefaultCatalog()); -// assertNull(childXmlEntity.getTable().getDefaultCatalog()); -// } -// -// public void testUpdateDefaultCatalogFromPersistenceUnitDefaults() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("FOO"); -// assertEquals("FOO", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().setSpecifiedCatalog("BAR"); -// assertEquals("BAR", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.javaEntity().getTable().setSpecifiedCatalog("JAVA_CATALOG"); -// assertEquals("JAVA_CATALOG", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.getTable().setSpecifiedName("BLAH"); -// //xml entity now has a table element so default schema is not taken from java -// assertEquals("BAR", xmlEntity.getTable().getDefaultCatalog()); -// -// -// xmlEntity.entityMappings().setSpecifiedCatalog(null); -// assertEquals("FOO", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog(null); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.getTable().setSpecifiedName(null); -// assertEquals("JAVA_CATALOG", xmlEntity.getTable().getDefaultCatalog()); -//} - -// -// public void testUpdateName() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// Entity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// assertEquals("Foo", xmlEntity.getName()); -// -// //set class in the resource model, verify context model updated -// entityResource.setClassName("com.Bar"); -// assertEquals("Bar", xmlEntity.getName()); -// -// entityResource.setName("Baz"); -// assertEquals("Baz", xmlEntity.getName()); -// -// //set class to null in the resource model -// entityResource.setClassName(null); -// assertEquals("Baz", xmlEntity.getName()); -// -// entityResource.setName(null); -// assertNull(xmlEntity.getName()); -// } - - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals("FOO", joinTableResource.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormJoinTable.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("FOO", joinTableResource.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormJoinTable.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getJoinColumns().get(2).getName()); - - ListIterator<OrmJoinColumn> joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - ormJoinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormJoinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormJoinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals(3, joinTableResource.getJoinColumns().size()); - - ormJoinTable.removeSpecifiedJoinColumn(0); - assertEquals(2, joinTableResource.getJoinColumns().size()); - assertEquals("BAR", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getJoinColumns().get(1).getName()); - - ormJoinTable.removeSpecifiedJoinColumn(0); - assertEquals(1, joinTableResource.getJoinColumns().size()); - assertEquals("BAZ", joinTableResource.getJoinColumns().get(0).getName()); - - ormJoinTable.removeSpecifiedJoinColumn(0); - assertEquals(0, joinTableResource.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - ormJoinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormJoinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormJoinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals(3, joinTableResource.getJoinColumns().size()); - - - ormJoinTable.moveSpecifiedJoinColumn(2, 0); - ListIterator<OrmJoinColumn> joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getJoinColumns().get(2).getName()); - - - ormJoinTable.moveSpecifiedJoinColumn(0, 1); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("BAR", joinTableResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getJoinColumns().get(2).getName()); - } - - public void testUpdateInverseJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - joinTableResource.getInverseJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - joinTableResource.getInverseJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - joinTableResource.getInverseJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - - joinTableResource.getInverseJoinColumns().get(0).setName("FOO"); - joinTableResource.getInverseJoinColumns().get(1).setName("BAR"); - joinTableResource.getInverseJoinColumns().get(2).setName("BAZ"); - - ListIterator<OrmJoinColumn> joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().move(2, 0); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().move(0, 1); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().remove(1); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().remove(1); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedInverseJoinColumns().hasNext()); - } - - public void testAddSpecifiedInverseJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedInverseJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormJoinTable.addSpecifiedInverseJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormJoinTable.addSpecifiedInverseJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(2).getName()); - - ListIterator<OrmJoinColumn> joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedInverseJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - ormJoinTable.addSpecifiedInverseJoinColumn(0).setSpecifiedName("FOO"); - ormJoinTable.addSpecifiedInverseJoinColumn(1).setSpecifiedName("BAR"); - ormJoinTable.addSpecifiedInverseJoinColumn(2).setSpecifiedName("BAZ"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals(3, joinTableResource.getInverseJoinColumns().size()); - - ormJoinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(2, joinTableResource.getInverseJoinColumns().size()); - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(1).getName()); - - ormJoinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTableResource.getInverseJoinColumns().size()); - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(0).getName()); - - ormJoinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(0, joinTableResource.getInverseJoinColumns().size()); - } - - public void testMoveSpecifiedInverseJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - ormJoinTable.addSpecifiedInverseJoinColumn(0).setSpecifiedName("FOO"); - ormJoinTable.addSpecifiedInverseJoinColumn(1).setSpecifiedName("BAR"); - ormJoinTable.addSpecifiedInverseJoinColumn(2).setSpecifiedName("BAZ"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals(3, joinTableResource.getInverseJoinColumns().size()); - - - ormJoinTable.moveSpecifiedInverseJoinColumn(2, 0); - ListIterator<OrmJoinColumn> joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(2).getName()); - - - ormJoinTable.moveSpecifiedInverseJoinColumn(0, 1); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - joinTableResource.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - joinTableResource.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - joinTableResource.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - - joinTableResource.getJoinColumns().get(0).setName("FOO"); - joinTableResource.getJoinColumns().get(1).setName("BAR"); - joinTableResource.getJoinColumns().get(2).setName("BAZ"); - - ListIterator<OrmJoinColumn> joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().move(2, 0); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().move(0, 1); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().remove(1); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().remove(1); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - } - - - public void testUniqueConstraints() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - assertEquals(0, ormJoinTable.uniqueConstraintsSize()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, ormJoinTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = joinTableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormJoinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = joinTableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormJoinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormJoinTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, joinTableResource.getUniqueConstraints().size()); - - ormJoinTable.removeUniqueConstraint(1); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator<OrmUniqueConstraint> uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormJoinTable.removeUniqueConstraint(1); - uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormJoinTable.removeUniqueConstraint(0); - uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormJoinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormJoinTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, joinTableResource.getUniqueConstraints().size()); - - - ormJoinTable.moveUniqueConstraint(2, 0); - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - ormJoinTable.moveUniqueConstraint(0, 1); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().move(2, 0); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().move(0, 1); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().remove(1); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().remove(1); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().remove(0); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - - public void testUniqueConstraintsFromJava() throws Exception { - createTestEntityWithValidManyToMany(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentType.attributes().next().getMapping(); - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertTrue(ormManyToManyMapping.getPersistentAttribute().isVirtual()); - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().attributes().next().getMapping(); - - javaManyToManyMapping.getJoinTable().addUniqueConstraint(0).addColumnName(0, "FOO"); - javaManyToManyMapping.getJoinTable().addUniqueConstraint(1).addColumnName(0, "BAR"); - javaManyToManyMapping.getJoinTable().addUniqueConstraint(2).addColumnName(0, "BAZ"); - - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - ormManyToManyMapping.getPersistentAttribute().makeSpecified(); - - ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentType.attributes().next().getMapping(); - ormManyToManyMapping.getJoinTable(); - assertEquals(0, ormManyToManyMapping.getJoinTable().uniqueConstraintsSize()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java deleted file mode 100644 index 6507b43b0f..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java +++ /dev/null @@ -1,654 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -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.FetchType; -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.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.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -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; - -public class OrmManyToManyMappingTests extends ContextModelTestCase -{ - public OrmManyToManyMappingTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertEquals("manyToManyMapping", ormManyToManyMapping.getName()); - assertEquals("manyToManyMapping", manyToMany.getName()); - - //set name in the resource model, verify context model updated - manyToMany.setName("newName"); - assertEquals("newName", ormManyToManyMapping.getName()); - assertEquals("newName", manyToMany.getName()); - - //set name to null in the resource model - manyToMany.setName(null); - assertNull(ormManyToManyMapping.getName()); - assertNull(manyToMany.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertEquals("manyToManyMapping", ormManyToManyMapping.getName()); - assertEquals("manyToManyMapping", manyToMany.getName()); - - //set name in the context model, verify resource model updated - ormManyToManyMapping.setName("newName"); - assertEquals("newName", ormManyToManyMapping.getName()); - assertEquals("newName", manyToMany.getName()); - - //set name to null in the context model - ormManyToManyMapping.setName(null); - assertNull(ormManyToManyMapping.getName()); - assertNull(manyToMany.getName()); - } - - public void testUpdateTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - manyToMany.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormManyToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToMany.getTargetEntity()); - - //set target entity to null in the resource model - manyToMany.setTargetEntity(null); - assertNull(ormManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - } - - public void testModifyTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - ormManyToManyMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormManyToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToMany.getTargetEntity()); - - //set target entity to null in the context model - ormManyToManyMapping.setSpecifiedTargetEntity(null); - assertNull(ormManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToManyResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedFetch()); - assertNull(manyToManyResource.getFetch()); - - //set fetch in the resource model, verify context model updated - manyToManyResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormManyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, manyToManyResource.getFetch()); - - manyToManyResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormManyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, manyToManyResource.getFetch()); - - //set fetch to null in the resource model - manyToManyResource.setFetch(null); - assertNull(ormManyToManyMapping.getSpecifiedFetch()); - assertNull(manyToManyResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToManyResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedFetch()); - assertNull(manyToManyResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormManyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, manyToManyResource.getFetch()); - assertEquals(FetchType.EAGER, ormManyToManyMapping.getSpecifiedFetch()); - - ormManyToManyMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, manyToManyResource.getFetch()); - assertEquals(FetchType.LAZY, ormManyToManyMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormManyToManyMapping.setSpecifiedFetch(null); - assertNull(manyToManyResource.getFetch()); - assertNull(ormManyToManyMapping.getSpecifiedFetch()); - } - - public void testUpdateMappedBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getMappedBy()); - assertNull(manyToMany.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - manyToMany.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", ormManyToManyMapping.getMappedBy()); - assertEquals("newMappedBy", manyToMany.getMappedBy()); - - //setmappedBy to null in the resource model - manyToMany.setMappedBy(null); - assertNull(ormManyToManyMapping.getMappedBy()); - assertNull(manyToMany.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getMappedBy()); - assertNull(manyToMany.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - ormManyToManyMapping.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", ormManyToManyMapping.getMappedBy()); - assertEquals("newMappedBy", manyToMany.getMappedBy()); - - //set mappedBy to null in the context model - ormManyToManyMapping.setMappedBy(null); - assertNull(ormManyToManyMapping.getMappedBy()); - assertNull(manyToMany.getMappedBy()); - } - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getMapKey()); - assertNull(manyToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - manyToMany.setMapKey(OrmFactory.eINSTANCE.createMapKeyImpl()); - assertNull(ormManyToManyMapping.getMapKey()); - assertNotNull(manyToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - manyToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormManyToManyMapping.getMapKey()); - assertEquals("myMapKey", manyToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - manyToMany.getMapKey().setName(null); - assertNull(ormManyToManyMapping.getMapKey()); - assertNull(manyToMany.getMapKey().getName()); - - manyToMany.getMapKey().setName("myMapKey"); - manyToMany.setMapKey(null); - assertNull(ormManyToManyMapping.getMapKey()); - assertNull(manyToMany.getMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getMapKey()); - assertNull(manyToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormManyToManyMapping.setMapKey("myMapKey"); - assertEquals("myMapKey", ormManyToManyMapping.getMapKey()); - assertEquals("myMapKey", manyToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormManyToManyMapping.setMapKey(null); - assertNull(ormManyToManyMapping.getMapKey()); - assertNull(manyToMany.getMapKey()); - } - - public void testUpdateOrderBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getOrderBy()); - assertNull(manyToMany.getOrderBy()); - - //set orderBy in the resource model, verify context model updated - manyToMany.setOrderBy("newOrderBy"); - assertEquals("newOrderBy", ormManyToManyMapping.getOrderBy()); - assertEquals("newOrderBy", manyToMany.getOrderBy()); - - //set orderBy to null in the resource model - manyToMany.setOrderBy(null); - assertNull(ormManyToManyMapping.getOrderBy()); - assertNull(manyToMany.getOrderBy()); - } - - public void testModifyOrderBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getOrderBy()); - assertNull(manyToMany.getOrderBy()); - - //set mappedBy in the context model, verify resource model updated - ormManyToManyMapping.setOrderBy("newOrderBy"); - assertEquals("newOrderBy", ormManyToManyMapping.getOrderBy()); - assertEquals("newOrderBy", manyToMany.getOrderBy()); - - //set mappedBy to null in the context model - ormManyToManyMapping.setOrderBy(null); - assertNull(ormManyToManyMapping.getOrderBy()); - assertNull(manyToMany.getOrderBy()); - } - - public void testIsNoOrdering() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - - assertTrue(ormManyToManyMapping.isNoOrdering()); - - ormManyToManyMapping.setOrderBy("foo"); - assertFalse(ormManyToManyMapping.isNoOrdering()); - - ormManyToManyMapping.setOrderBy(null); - assertTrue(ormManyToManyMapping.isNoOrdering()); - } - - public void testSetNoOrdering() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - - assertTrue(ormManyToManyMapping.isNoOrdering()); - - ormManyToManyMapping.setOrderBy("foo"); - assertFalse(ormManyToManyMapping.isNoOrdering()); - - ormManyToManyMapping.setNoOrdering(true); - assertTrue(ormManyToManyMapping.isNoOrdering()); - assertNull(ormManyToManyMapping.getOrderBy()); - } -//TODO -// public boolean isOrderByPk() { -// return "".equals(getOrderBy()); -// } -// -// public void setOrderByPk() { -// setOrderBy(""); -// } - - public void testIsCustomOrdering() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - - assertFalse(ormManyToManyMapping.isCustomOrdering()); - - ormManyToManyMapping.setOrderBy("foo"); - assertTrue(ormManyToManyMapping.isCustomOrdering()); - - ormManyToManyMapping.setOrderBy(null); - assertFalse(ormManyToManyMapping.isCustomOrdering()); - } - - public void testManyToManyMorphToIdMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToVersionMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToTransientMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToEmbeddedMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToEmbeddedIdMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToOneToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getCascade().setAll(true); - manyToManyMapping.getCascade().setMerge(true); - manyToManyMapping.getCascade().setPersist(true); - manyToManyMapping.getCascade().setRefresh(true); - manyToManyMapping.getCascade().setRemove(true); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((OneToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((OneToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((OneToOneMapping) ormPersistentAttribute.getMapping()).getMappedBy()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testManyToManyMorphToOneToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getCascade().setAll(true); - manyToManyMapping.getCascade().setMerge(true); - manyToManyMapping.getCascade().setPersist(true); - manyToManyMapping.getCascade().setRefresh(true); - manyToManyMapping.getCascade().setRemove(true); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((OneToManyMapping) ormPersistentAttribute.getMapping()).getMappedBy()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - JoinTable joinTable = ((OneToManyMapping) ormPersistentAttribute.getMapping()).getJoinTable(); - assertEquals("MY_JOIN_TABLE", joinTable.getName()); - assertEquals("name", joinTable.joinColumns().next().getSpecifiedName()); - assertEquals("referenceName", joinTable.joinColumns().next().getSpecifiedReferencedColumnName()); - assertEquals("inverseName", joinTable.inverseJoinColumns().next().getSpecifiedName()); - assertEquals("inverseReferenceName", joinTable.inverseJoinColumns().next().getSpecifiedReferencedColumnName()); - } - - public void testManyToManyMorphToManyToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getCascade().setAll(true); - manyToManyMapping.getCascade().setMerge(true); - manyToManyMapping.getCascade().setPersist(true); - manyToManyMapping.getCascade().setRefresh(true); - manyToManyMapping.getCascade().setRemove(true); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testManyToManyMorphToBasicMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getCascade().setAll(true); - manyToManyMapping.getCascade().setMerge(true); - manyToManyMapping.getCascade().setPersist(true); - manyToManyMapping.getCascade().setRefresh(true); - manyToManyMapping.getCascade().setRemove(true); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); -//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java deleted file mode 100644 index ad06e23310..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java +++ /dev/null @@ -1,542 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.Cascade; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -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.iterators.ArrayIterator; - -public class OrmManyToOneMappingTests extends ContextModelTestCase -{ - public OrmManyToOneMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private ICompilationUnit createTestEntityManyToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - 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(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); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertEquals("manyToOneMapping", ormManyToOneMapping.getName()); - assertEquals("manyToOneMapping", manyToOne.getName()); - - //set name in the resource model, verify context model updated - manyToOne.setName("newName"); - assertEquals("newName", ormManyToOneMapping.getName()); - assertEquals("newName", manyToOne.getName()); - - //set name to null in the resource model - manyToOne.setName(null); - assertNull(ormManyToOneMapping.getName()); - assertNull(manyToOne.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertEquals("manyToOneMapping", ormManyToOneMapping.getName()); - assertEquals("manyToOneMapping", manyToOne.getName()); - - //set name in the context model, verify resource model updated - ormManyToOneMapping.setName("newName"); - assertEquals("newName", ormManyToOneMapping.getName()); - assertEquals("newName", manyToOne.getName()); - - //set name to null in the context model - ormManyToOneMapping.setName(null); - assertNull(ormManyToOneMapping.getName()); - assertNull(manyToOne.getName()); - } - - public void testUpdateTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - manyToOne.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormManyToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToOne.getTargetEntity()); - - //set target entity to null in the resource model - manyToOne.setTargetEntity(null); - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - } - - public void testModifyTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - ormManyToOneMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormManyToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToOne.getTargetEntity()); - - //set target entity to null in the context model - ormManyToOneMapping.setSpecifiedTargetEntity(null); - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(manyToOneResource.getFetch()); - - //set fetch in the resource model, verify context model updated - manyToOneResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, manyToOneResource.getFetch()); - - manyToOneResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormManyToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, manyToOneResource.getFetch()); - - //set fetch to null in the resource model - manyToOneResource.setFetch(null); - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(manyToOneResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(manyToOneResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormManyToOneMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, manyToOneResource.getFetch()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getSpecifiedFetch()); - - ormManyToOneMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, manyToOneResource.getFetch()); - assertEquals(FetchType.LAZY, ormManyToOneMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormManyToOneMapping.setSpecifiedFetch(null); - assertNull(manyToOneResource.getFetch()); - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - } - - public void testUpdateSpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOneResource.getOptional()); - - //set optional in the resource model, verify context model updated - manyToOneResource.setOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormManyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, manyToOneResource.getOptional()); - - manyToOneResource.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormManyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, manyToOneResource.getOptional()); - - //set optional to null in the resource model - manyToOneResource.setOptional(null); - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOneResource.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOneResource.getOptional()); - - //set optional in the context model, verify resource model updated - ormManyToOneMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, manyToOneResource.getOptional()); - assertEquals(Boolean.TRUE, ormManyToOneMapping.getSpecifiedOptional()); - - ormManyToOneMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, manyToOneResource.getOptional()); - assertEquals(Boolean.FALSE, ormManyToOneMapping.getSpecifiedOptional()); - - //set optional to null in the context model - ormManyToOneMapping.setSpecifiedOptional(null); - assertNull(manyToOneResource.getOptional()); - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - OrmJoinColumn joinColumn = ormManyToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", manyToOneResource.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormManyToOneMapping.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("FOO", manyToOneResource.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormManyToOneMapping.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", manyToOneResource.getJoinColumns().get(2).getName()); - - ListIterator<OrmJoinColumn> joinColumns = ormManyToOneMapping.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormManyToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - ormManyToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormManyToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormManyToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, manyToOneResource.getJoinColumns().size()); - - ormManyToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(2, manyToOneResource.getJoinColumns().size()); - assertEquals("BAR", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(1).getName()); - - ormManyToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(1, manyToOneResource.getJoinColumns().size()); - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(0).getName()); - - ormManyToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(0, manyToOneResource.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - ormManyToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormManyToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormManyToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, manyToOneResource.getJoinColumns().size()); - - - ormManyToOneMapping.moveSpecifiedJoinColumn(2, 0); - ListIterator<OrmJoinColumn> joinColumns = ormManyToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", manyToOneResource.getJoinColumns().get(2).getName()); - - - ormManyToOneMapping.moveSpecifiedJoinColumn(0, 1); - joinColumns = ormManyToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAR", manyToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", manyToOneResource.getJoinColumns().get(2).getName()); - } - - - public void testManyToOneMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormManyToOneMapping.getName()); - - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getFetch()); - assertEquals(Boolean.TRUE, ormManyToOneMapping.getOptional()); - assertNull(ormManyToOneMapping.getTargetEntity()); - - - assertFalse(ormManyToOneMapping.specifiedJoinColumns().hasNext()); - //TODO default joinColumns - //assertTrue(ormManyToOneMapping.defaultJoinColumns().hasNext()); - - - Cascade cascade = ormManyToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToOneMapping.getName()); - assertEquals(FetchType.LAZY, ormManyToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, ormManyToOneMapping.getSpecifiedOptional()); - assertEquals("Address", ormManyToOneMapping.getSpecifiedTargetEntity()); - - OrmJoinColumn ormJoinColumn = ormManyToOneMapping.specifiedJoinColumns().next(); - assertEquals("MY_COLUMN", ormJoinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", ormJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", ormJoinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", ormJoinColumn.getSpecifiedTable()); - - Cascade cascade = ormManyToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.makeSpecified(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getDefaultFetch()); - assertEquals(Boolean.TRUE, ormManyToOneMapping.getDefaultOptional()); - //TODO hmm, is this correct? - assertEquals("test.Address", ormManyToOneMapping.getDefaultTargetEntity()); - - //TODO default join columns in xml one-to-one -// XmlJoinColumn ormJoinColumn = ormManyToOneMapping.specifiedJoinColumns().next(); -// //TODO java default columns name in JavaSingleRelationshipMapping.JoinColumnOwner -// //assertEquals("address", ormJoinColumn.getSpecifiedName()); -// //assertEquals("address", ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getSpecifiedTable()); - - Cascade cascade = ormManyToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormManyToOneMapping.getName()); - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getFetch()); - assertEquals(Boolean.TRUE, ormManyToOneMapping.getOptional()); - assertEquals("test.Address", ormManyToOneMapping.getDefaultTargetEntity()); - - assertFalse(ormManyToOneMapping.specifiedJoinColumns().hasNext()); - - //TODO default join columns for specified xmlManyToOne mapping -// XmlJoinColumn ormJoinColumn = ormManyToOneMapping.defaultJoinColumns().next(); -// assertNull(ormJoinColumn.getSpecifiedName()); -// assertNull(ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertNull(ormJoinColumn.getSpecifiedUnique()); -// assertNull(ormJoinColumn.getSpecifiedNullable()); -// assertNull(ormJoinColumn.getSpecifiedInsertable()); -// assertNull(ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertNull(ormJoinColumn.getSpecifiedTable()); -// -// assertEquals("address", ormJoinColumn.getDefaultName()); -// assertEquals("address", ormJoinColumn.getDefaultReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getDefaultUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultUpdatable()); -// assertEquals(null, ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getDefaultTable()); - - Cascade cascade = ormManyToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - //3 things tested above - //1. virtual mapping metadata complete=false - defaults are taken from the java annotations - //2. virtual mapping metadata complete=true - defaults are taken from java defaults,annotations ignored - //3. specified mapping (metadata complete=true/false - defaults are taken from java annotations - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmMappedSuperclassTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmMappedSuperclassTests.java deleted file mode 100644 index 176aa0c4b3..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmMappedSuperclassTests.java +++ /dev/null @@ -1,347 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.ListIterator; -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.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -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; - -public class OrmMappedSuperclassTests extends ContextModelTestCase -{ - public OrmMappedSuperclassTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals("model.Foo", mappedSuperclassResource.getClassName()); - - //set class in the resource model, verify context model updated - mappedSuperclassResource.setClassName("com.Bar"); - assertEquals("com.Bar", ormMappedSuperclass.getClass_()); - assertEquals("com.Bar", mappedSuperclassResource.getClassName()); - - //set class to null in the resource model - mappedSuperclassResource.setClassName(null); - assertNull(ormMappedSuperclass.getClass_()); - assertNull(mappedSuperclassResource.getClassName()); - } - - public void testModifyClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals("model.Foo", mappedSuperclassResource.getClassName()); - - //set class in the context model, verify resource model modified - ormMappedSuperclass.setClass("com.Bar"); - assertEquals("com.Bar", ormMappedSuperclass.getClass_()); - assertEquals("com.Bar", mappedSuperclassResource.getClassName()); - - //set class to null in the context model - ormMappedSuperclass.setClass(null); - assertNull(ormMappedSuperclass.getClass_()); - assertNull(mappedSuperclassResource.getClassName()); - } - //TODO add tests for setting the className when the package is set on entity-mappings - - public void testUpdateSpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormMappedSuperclass.getSpecifiedAccess()); - assertNull(mappedSuperclassResource.getAccess()); - - //set access in the resource model, verify context model updated - mappedSuperclassResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, ormMappedSuperclass.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, mappedSuperclassResource.getAccess()); - - //set access to null in the resource model - mappedSuperclassResource.setAccess(null); - assertNull(ormMappedSuperclass.getSpecifiedAccess()); - assertNull(mappedSuperclassResource.getAccess()); - } - - public void testModifySpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormMappedSuperclass.getSpecifiedAccess()); - assertNull(mappedSuperclassResource.getAccess()); - - //set access in the context model, verify resource model modified - ormMappedSuperclass.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormMappedSuperclass.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclassResource.getAccess()); - - //set access to null in the context model - ormMappedSuperclass.setSpecifiedAccess(null); - assertNull(ormMappedSuperclass.getSpecifiedAccess()); - assertNull(mappedSuperclassResource.getAccess()); - } - //TODO test default access from - //underlying java - //persistence-unit-defaults - //entity-mappings - //with xml-mapping-metadata-complete set - - public void testUpdateSpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - //set metadata-complete in the resource model, verify context model updated - mappedSuperclassResource.setMetadataComplete(true); - assertTrue(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertTrue(mappedSuperclassResource.getMetadataComplete()); - - //set access to false in the resource model - mappedSuperclassResource.setMetadataComplete(false); - assertFalse(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertFalse(mappedSuperclassResource.getMetadataComplete()); - - mappedSuperclassResource.setMetadataComplete(null); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - } - - public void testModifySpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - //set access in the context model, verify resource model modified - ormMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - assertTrue(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertTrue(mappedSuperclassResource.getMetadataComplete()); - - //set access to null in the context model - ormMappedSuperclass.setSpecifiedMetadataComplete(Boolean.FALSE); - assertFalse(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertFalse(mappedSuperclassResource.getMetadataComplete()); - - ormMappedSuperclass.setSpecifiedMetadataComplete(null); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - } - - public void testUpdateDefaultMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertFalse(ormMappedSuperclass.isDefaultMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormMappedSuperclass.isDefaultMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertFalse(ormMappedSuperclass.isDefaultMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - } - - public void testUpdateMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertFalse(ormMappedSuperclass.isMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormMappedSuperclass.isMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertFalse(ormMappedSuperclass.isMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - } - - - public void testMakeMappedSuperclassEntity() throws Exception { - OrmPersistentType mappedSuperclassPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) mappedSuperclassPersistentType.getMapping(); - mappedSuperclass.setSpecifiedAccess(AccessType.PROPERTY); - mappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - mappedSuperclassPersistentType.setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("model.Foo", entity.getClassName()); - assertEquals(Boolean.TRUE, entity.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entity.getAccess()); - assertNull(entity.getDiscriminatorValue()); - assertNull(entity.getName()); - - OrmEntity ormEntity = (OrmEntity) mappedSuperclassPersistentType.getMapping(); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEntity.getSpecifiedAccess()); - } - - //test with 2 MappedSuperclasses, make the first one an Entity so it has to move to the end of the list - public void testMakeMappedSuperclassEntity2() throws Exception { - OrmPersistentType mappedSuperclassPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo2"); - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) mappedSuperclassPersistentType.getMapping(); - mappedSuperclass.setSpecifiedAccess(AccessType.PROPERTY); - mappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - mappedSuperclassPersistentType.setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("model.Foo", entity.getClassName()); - assertEquals(Boolean.TRUE, entity.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entity.getAccess()); - assertNull(entity.getDiscriminatorValue()); - assertNull(entity.getName()); - - OrmEntity ormEntity = (OrmEntity) mappedSuperclassPersistentType.getMapping(); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEntity.getSpecifiedAccess()); - - ListIterator<OrmPersistentType> persistentTypes = entityMappings().ormPersistentTypes(); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - } - - public void testMakeMappedSuperclassEmbeddable() throws Exception { - OrmPersistentType mappedSuperclassPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) mappedSuperclassPersistentType.getMapping(); - mappedSuperclass.setSpecifiedAccess(AccessType.PROPERTY); - mappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - mappedSuperclassPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - XmlEmbeddable embeddable = ormResource().getEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", embeddable.getClassName()); - assertEquals(Boolean.TRUE, embeddable.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddable.getAccess()); - - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) mappedSuperclassPersistentType.getMapping(); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEmbeddable.getSpecifiedAccess()); - } - //test with 2 MappedSuperclasses, make the first one an Embeddable so it has to move to the end of the list - public void testMakeMappedSuperclassEmbeddable2() throws Exception { - OrmPersistentType mappedSuperclassPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo2"); - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) mappedSuperclassPersistentType.getMapping(); - mappedSuperclass.setSpecifiedAccess(AccessType.PROPERTY); - mappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - mappedSuperclassPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - XmlEmbeddable embeddable = ormResource().getEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", embeddable.getClassName()); - assertEquals(Boolean.TRUE, embeddable.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddable.getAccess()); - - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) mappedSuperclassPersistentType.getMapping(); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEmbeddable.getSpecifiedAccess()); - - ListIterator<OrmPersistentType> persistentTypes = entityMappings().ormPersistentTypes(); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - } - - public void testUpdateIdClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - - assertNull(ormMappedSuperclass.getIdClass()); - assertNull(mappedSuperclassResource.getIdClass()); - - mappedSuperclassResource.setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - - assertNull(ormMappedSuperclass.getIdClass()); - assertNotNull(mappedSuperclassResource.getIdClass()); - - mappedSuperclassResource.getIdClass().setClassName("model.Foo"); - assertEquals("model.Foo", ormMappedSuperclass.getIdClass()); - assertEquals("model.Foo", mappedSuperclassResource.getIdClass().getClassName()); - - //test setting @IdClass value to null, id-class tag is not removed - mappedSuperclassResource.getIdClass().setClassName(null); - assertNull(ormMappedSuperclass.getIdClass()); - assertNotNull(mappedSuperclassResource.getIdClass()); - - //reset @IdClass value and then remove id-class tag - mappedSuperclassResource.setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - mappedSuperclassResource.getIdClass().setClassName("model.Foo"); - mappedSuperclassResource.setIdClass(null); - - assertNull(ormMappedSuperclass.getIdClass()); - assertNull(mappedSuperclassResource.getIdClass()); - } - - public void testModifyIdClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - - assertNull(ormMappedSuperclass.getIdClass()); - assertNull(mappedSuperclassResource.getIdClass()); - - ormMappedSuperclass.setIdClass("model.Foo"); - assertEquals("model.Foo", mappedSuperclassResource.getIdClass().getClassName()); - assertEquals("model.Foo", ormMappedSuperclass.getIdClass()); - - ormMappedSuperclass.setIdClass(null); - assertNull(ormMappedSuperclass.getIdClass()); - assertNull(mappedSuperclassResource.getIdClass()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedNativeQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedNativeQueryTests.java deleted file mode 100644 index 84b6800528..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedNativeQueryTests.java +++ /dev/null @@ -1,358 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlNamedNativeQuery; -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; - -public class OrmNamedNativeQueryTests extends ContextModelTestCase -{ - public OrmNamedNativeQueryTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertNull(ormNamedNativeQuery.getName()); - assertNull(namedNativeQueryResource.getName()); - - //set name in the resource model, verify context model updated - namedNativeQueryResource.setName("newName"); - assertEquals("newName", ormNamedNativeQuery.getName()); - assertEquals("newName", namedNativeQueryResource.getName()); - - //set name to null in the resource model - namedNativeQueryResource.setName(null); - assertNull(ormNamedNativeQuery.getName()); - assertNull(namedNativeQueryResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertNull(ormNamedNativeQuery.getName()); - assertNull(namedNativeQueryResource.getName()); - - //set name in the context model, verify resource model updated - ormNamedNativeQuery.setName("newName"); - assertEquals("newName", ormNamedNativeQuery.getName()); - assertEquals("newName", namedNativeQueryResource.getName()); - - //set name to null in the context model - ormNamedNativeQuery.setName(null); - assertNull(ormNamedNativeQuery.getName()); - assertNull(namedNativeQueryResource.getName()); - } - - public void testUpdateQuery() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertNull(ormNamedNativeQuery.getQuery()); - assertNull(namedNativeQueryResource.getQuery()); - - //set name in the resource model, verify context model updated - namedNativeQueryResource.setQuery("newName"); - assertEquals("newName", ormNamedNativeQuery.getQuery()); - assertEquals("newName", namedNativeQueryResource.getQuery()); - - //set name to null in the resource model - namedNativeQueryResource.setQuery(null); - assertNull(ormNamedNativeQuery.getQuery()); - assertNull(namedNativeQueryResource.getQuery()); - } - - public void testModifyQuery() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertNull(ormNamedNativeQuery.getQuery()); - assertNull(namedNativeQueryResource.getQuery()); - - //set name in the context model, verify resource model updated - ormNamedNativeQuery.setQuery("newName"); - assertEquals("newName", ormNamedNativeQuery.getQuery()); - assertEquals("newName", namedNativeQueryResource.getQuery()); - - //set name to null in the context model - ormNamedNativeQuery.setQuery(null); - assertNull(ormNamedNativeQuery.getQuery()); - assertNull(namedNativeQueryResource.getQuery()); - } - - public void testAddHint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - OrmQueryHint queryHint = ormNamedNativeQuery.addHint(0); - queryHint.setName("FOO"); - - assertEquals("FOO", namedNativeQueryResource.getHints().get(0).getName()); - - OrmQueryHint queryHint2 = ormNamedNativeQuery.addHint(0); - queryHint2.setName("BAR"); - - assertEquals("BAR", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("FOO", namedNativeQueryResource.getHints().get(1).getName()); - - OrmQueryHint queryHint3 = ormNamedNativeQuery.addHint(1); - queryHint3.setName("BAZ"); - - assertEquals("BAR", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedNativeQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedNativeQueryResource.getHints().get(2).getName()); - - ListIterator<OrmQueryHint> queryHints = ormNamedNativeQuery.hints(); - assertEquals(queryHint2, queryHints.next()); - assertEquals(queryHint3, queryHints.next()); - assertEquals(queryHint, queryHints.next()); - - queryHints = ormNamedNativeQuery.hints(); - assertEquals("BAR", queryHints.next().getName()); - assertEquals("BAZ", queryHints.next().getName()); - assertEquals("FOO", queryHints.next().getName()); - } - - public void testRemoveHint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - ormNamedNativeQuery.addHint(0).setName("FOO"); - ormNamedNativeQuery.addHint(1).setName("BAR"); - ormNamedNativeQuery.addHint(2).setName("BAZ"); - - assertEquals(3, namedNativeQueryResource.getHints().size()); - - ormNamedNativeQuery.removeHint(0); - assertEquals(2, namedNativeQueryResource.getHints().size()); - assertEquals("BAR", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedNativeQueryResource.getHints().get(1).getName()); - - ormNamedNativeQuery.removeHint(0); - assertEquals(1, namedNativeQueryResource.getHints().size()); - assertEquals("BAZ", namedNativeQueryResource.getHints().get(0).getName()); - - ormNamedNativeQuery.removeHint(0); - assertEquals(0, namedNativeQueryResource.getHints().size()); - } - - public void testMoveHint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - ormNamedNativeQuery.addHint(0).setName("FOO"); - ormNamedNativeQuery.addHint(1).setName("BAR"); - ormNamedNativeQuery.addHint(2).setName("BAZ"); - - assertEquals(3, namedNativeQueryResource.getHints().size()); - - - ormNamedNativeQuery.moveHint(2, 0); - ListIterator<OrmQueryHint> hints = ormNamedNativeQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAR", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedNativeQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedNativeQueryResource.getHints().get(2).getName()); - - - ormNamedNativeQuery.moveHint(0, 1); - hints = ormNamedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAZ", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("BAR", namedNativeQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedNativeQueryResource.getHints().get(2).getName()); - } - - public void testUpdateHints() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - namedNativeQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - namedNativeQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - namedNativeQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - - namedNativeQueryResource.getHints().get(0).setName("FOO"); - namedNativeQueryResource.getHints().get(1).setName("BAR"); - namedNativeQueryResource.getHints().get(2).setName("BAZ"); - - ListIterator<OrmQueryHint> hints = ormNamedNativeQuery.hints(); - assertEquals("FOO", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().move(2, 0); - hints = ormNamedNativeQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().move(0, 1); - hints = ormNamedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().remove(1); - hints = ormNamedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().remove(1); - hints = ormNamedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().remove(0); - assertFalse(ormNamedNativeQuery.hints().hasNext()); - } - - - public void testUpdateResultSetMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertEquals(null, namedNativeQueryResource.getResultSetMapping()); - assertEquals(null, ormNamedNativeQuery.getResultSetMapping()); - - //set name in the resource model, verify context model updated - namedNativeQueryResource.setResultSetMapping("foo"); - assertEquals("foo", namedNativeQueryResource.getResultSetMapping()); - assertEquals("foo", ormNamedNativeQuery.getResultSetMapping()); - - //set name to null in the resource model - namedNativeQueryResource.setResultSetMapping(null); - assertNull(namedNativeQueryResource.getResultSetMapping()); - assertNull(ormNamedNativeQuery.getResultSetMapping()); - } - - public void testModifyResultSetMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertEquals(null, namedNativeQueryResource.getResultSetMapping()); - assertEquals(null, ormNamedNativeQuery.getResultSetMapping()); - - //set name in the context model, verify resource model updated - ormNamedNativeQuery.setResultSetMapping("foo"); - assertEquals("foo", namedNativeQueryResource.getResultSetMapping()); - assertEquals("foo", ormNamedNativeQuery.getResultSetMapping()); - - //set name to null in the context model - ormNamedNativeQuery.setResultSetMapping(null); - assertNull(namedNativeQueryResource.getResultSetMapping()); - assertNull(ormNamedNativeQuery.getResultSetMapping()); - } - - public void testUpdateResultClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertEquals(null, namedNativeQueryResource.getResultClass()); - assertEquals(null, ormNamedNativeQuery.getResultClass()); - - //set name in the resource model, verify context model updated - namedNativeQueryResource.setResultClass("foo"); - assertEquals("foo", namedNativeQueryResource.getResultClass()); - assertEquals("foo", ormNamedNativeQuery.getResultClass()); - - //set name to null in the resource model - namedNativeQueryResource.setResultClass(null); - assertNull(namedNativeQueryResource.getResultClass()); - assertNull(ormNamedNativeQuery.getResultClass()); - } - - public void testModifyResultClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertEquals(null, namedNativeQueryResource.getResultClass()); - assertEquals(null, ormNamedNativeQuery.getResultClass()); - - //set name in the context model, verify resource model updated - ormNamedNativeQuery.setResultClass("foo"); - assertEquals("foo", namedNativeQueryResource.getResultClass()); - assertEquals("foo", ormNamedNativeQuery.getResultClass()); - - //set name to null in the context model - ormNamedNativeQuery.setResultClass(null); - assertNull(namedNativeQueryResource.getResultClass()); - assertNull(ormNamedNativeQuery.getResultClass()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedQueryTests.java deleted file mode 100644 index 6825936f29..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedQueryTests.java +++ /dev/null @@ -1,273 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlNamedQuery; -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; - -public class OrmNamedQueryTests extends ContextModelTestCase -{ - public OrmNamedQueryTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - assertNull(ormNamedQuery.getName()); - assertNull(namedQueryResource.getName()); - - //set name in the resource model, verify context model updated - namedQueryResource.setName("newName"); - assertEquals("newName", ormNamedQuery.getName()); - assertEquals("newName", namedQueryResource.getName()); - - //set name to null in the resource model - namedQueryResource.setName(null); - assertNull(ormNamedQuery.getName()); - assertNull(namedQueryResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - assertNull(ormNamedQuery.getName()); - assertNull(namedQueryResource.getName()); - - //set name in the context model, verify resource model updated - ormNamedQuery.setName("newName"); - assertEquals("newName", ormNamedQuery.getName()); - assertEquals("newName", namedQueryResource.getName()); - - //set name to null in the context model - ormNamedQuery.setName(null); - assertNull(ormNamedQuery.getName()); - assertNull(namedQueryResource.getName()); - } - - public void testUpdateQuery() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - assertNull(ormNamedQuery.getQuery()); - assertNull(namedQueryResource.getQuery()); - - //set name in the resource model, verify context model updated - namedQueryResource.setQuery("newName"); - assertEquals("newName", ormNamedQuery.getQuery()); - assertEquals("newName", namedQueryResource.getQuery()); - - //set name to null in the resource model - namedQueryResource.setQuery(null); - assertNull(ormNamedQuery.getQuery()); - assertNull(namedQueryResource.getQuery()); - } - - public void testModifyQuery() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - assertNull(ormNamedQuery.getQuery()); - assertNull(namedQueryResource.getQuery()); - - //set name in the context model, verify resource model updated - ormNamedQuery.setQuery("newName"); - assertEquals("newName", ormNamedQuery.getQuery()); - assertEquals("newName", namedQueryResource.getQuery()); - - //set name to null in the context model - ormNamedQuery.setQuery(null); - assertNull(ormNamedQuery.getQuery()); - assertNull(namedQueryResource.getQuery()); - } - - public void testAddHint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - OrmQueryHint queryHint = ormNamedQuery.addHint(0); - queryHint.setName("FOO"); - - assertEquals("FOO", namedQueryResource.getHints().get(0).getName()); - - OrmQueryHint queryHint2 = ormNamedQuery.addHint(0); - queryHint2.setName("BAR"); - - assertEquals("BAR", namedQueryResource.getHints().get(0).getName()); - assertEquals("FOO", namedQueryResource.getHints().get(1).getName()); - - OrmQueryHint queryHint3 = ormNamedQuery.addHint(1); - queryHint3.setName("BAZ"); - - assertEquals("BAR", namedQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedQueryResource.getHints().get(2).getName()); - - ListIterator<OrmQueryHint> queryHints = ormNamedQuery.hints(); - assertEquals(queryHint2, queryHints.next()); - assertEquals(queryHint3, queryHints.next()); - assertEquals(queryHint, queryHints.next()); - - queryHints = ormNamedQuery.hints(); - assertEquals("BAR", queryHints.next().getName()); - assertEquals("BAZ", queryHints.next().getName()); - assertEquals("FOO", queryHints.next().getName()); - } - - public void testRemoveHint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - ormNamedQuery.addHint(0).setName("FOO"); - ormNamedQuery.addHint(1).setName("BAR"); - ormNamedQuery.addHint(2).setName("BAZ"); - - assertEquals(3, namedQueryResource.getHints().size()); - - ormNamedQuery.removeHint(0); - assertEquals(2, namedQueryResource.getHints().size()); - assertEquals("BAR", namedQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedQueryResource.getHints().get(1).getName()); - - ormNamedQuery.removeHint(0); - assertEquals(1, namedQueryResource.getHints().size()); - assertEquals("BAZ", namedQueryResource.getHints().get(0).getName()); - - ormNamedQuery.removeHint(0); - assertEquals(0, namedQueryResource.getHints().size()); - } - - public void testMoveHint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - ormNamedQuery.addHint(0).setName("FOO"); - ormNamedQuery.addHint(1).setName("BAR"); - ormNamedQuery.addHint(2).setName("BAZ"); - - assertEquals(3, namedQueryResource.getHints().size()); - - - ormNamedQuery.moveHint(2, 0); - ListIterator<OrmQueryHint> hints = ormNamedQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAR", namedQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedQueryResource.getHints().get(2).getName()); - - - ormNamedQuery.moveHint(0, 1); - hints = ormNamedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAZ", namedQueryResource.getHints().get(0).getName()); - assertEquals("BAR", namedQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedQueryResource.getHints().get(2).getName()); - } - - public void testUpdateHints() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - namedQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - namedQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - namedQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - - namedQueryResource.getHints().get(0).setName("FOO"); - namedQueryResource.getHints().get(1).setName("BAR"); - namedQueryResource.getHints().get(2).setName("BAZ"); - - ListIterator<OrmQueryHint> hints = ormNamedQuery.hints(); - assertEquals("FOO", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().move(2, 0); - hints = ormNamedQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().move(0, 1); - hints = ormNamedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().remove(1); - hints = ormNamedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().remove(1); - hints = ormNamedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().remove(0); - assertFalse(ormNamedQuery.hints().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/orm/OrmOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java deleted file mode 100644 index 22225dfef0..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java +++ /dev/null @@ -1,655 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -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.FetchType; -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.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.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -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; - -public class OrmOneToManyMappingTests extends ContextModelTestCase -{ - public OrmOneToManyMappingTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertEquals("oneToManyMapping", ormOneToManyMapping.getName()); - assertEquals("oneToManyMapping", oneToMany.getName()); - - //set name in the resource model, verify context model updated - oneToMany.setName("newName"); - assertEquals("newName", ormOneToManyMapping.getName()); - assertEquals("newName", oneToMany.getName()); - - //set name to null in the resource model - oneToMany.setName(null); - assertNull(ormOneToManyMapping.getName()); - assertNull(oneToMany.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertEquals("oneToManyMapping", ormOneToManyMapping.getName()); - assertEquals("oneToManyMapping", oneToMany.getName()); - - //set name in the context model, verify resource model updated - ormOneToManyMapping.setName("newName"); - assertEquals("newName", ormOneToManyMapping.getName()); - assertEquals("newName", oneToMany.getName()); - - //set name to null in the context model - ormOneToManyMapping.setName(null); - assertNull(ormOneToManyMapping.getName()); - assertNull(oneToMany.getName()); - } - - public void testUpdateTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - oneToMany.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormOneToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToMany.getTargetEntity()); - - //set target entity to null in the resource model - oneToMany.setTargetEntity(null); - assertNull(ormOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - } - - public void testModifyTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormOneToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToMany.getTargetEntity()); - - //set target entity to null in the context model - ormOneToManyMapping.setSpecifiedTargetEntity(null); - assertNull(ormOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToManyResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedFetch()); - assertNull(oneToManyResource.getFetch()); - - //set fetch in the resource model, verify context model updated - oneToManyResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormOneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, oneToManyResource.getFetch()); - - oneToManyResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormOneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, oneToManyResource.getFetch()); - - //set fetch to null in the resource model - oneToManyResource.setFetch(null); - assertNull(ormOneToManyMapping.getSpecifiedFetch()); - assertNull(oneToManyResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToManyResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedFetch()); - assertNull(oneToManyResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, oneToManyResource.getFetch()); - assertEquals(FetchType.EAGER, ormOneToManyMapping.getSpecifiedFetch()); - - ormOneToManyMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, oneToManyResource.getFetch()); - assertEquals(FetchType.LAZY, ormOneToManyMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormOneToManyMapping.setSpecifiedFetch(null); - assertNull(oneToManyResource.getFetch()); - assertNull(ormOneToManyMapping.getSpecifiedFetch()); - } - - public void testUpdateMappedBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getMappedBy()); - assertNull(oneToMany.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - oneToMany.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", ormOneToManyMapping.getMappedBy()); - assertEquals("newMappedBy", oneToMany.getMappedBy()); - - //setmappedBy to null in the resource model - oneToMany.setMappedBy(null); - assertNull(ormOneToManyMapping.getMappedBy()); - assertNull(oneToMany.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getMappedBy()); - assertNull(oneToMany.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - ormOneToManyMapping.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", ormOneToManyMapping.getMappedBy()); - assertEquals("newMappedBy", oneToMany.getMappedBy()); - - //set mappedBy to null in the context model - ormOneToManyMapping.setMappedBy(null); - assertNull(ormOneToManyMapping.getMappedBy()); - assertNull(oneToMany.getMappedBy()); - } - - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getMapKey()); - assertNull(oneToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - oneToMany.setMapKey(OrmFactory.eINSTANCE.createMapKeyImpl()); - assertNull(ormOneToManyMapping.getMapKey()); - assertNotNull(oneToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - oneToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getMapKey()); - assertEquals("myMapKey", oneToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - oneToMany.getMapKey().setName(null); - assertNull(ormOneToManyMapping.getMapKey()); - assertNull(oneToMany.getMapKey().getName()); - - oneToMany.getMapKey().setName("myMapKey"); - oneToMany.setMapKey(null); - assertNull(ormOneToManyMapping.getMapKey()); - assertNull(oneToMany.getMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getMapKey()); - assertNull(oneToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormOneToManyMapping.setMapKey("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getMapKey()); - assertEquals("myMapKey", oneToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormOneToManyMapping.setMapKey(null); - assertNull(ormOneToManyMapping.getMapKey()); - assertNull(oneToMany.getMapKey()); - } - - public void testUpdateOrderBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getOrderBy()); - assertNull(oneToMany.getOrderBy()); - - //set orderBy in the resource model, verify context model updated - oneToMany.setOrderBy("newOrderBy"); - assertEquals("newOrderBy", ormOneToManyMapping.getOrderBy()); - assertEquals("newOrderBy", oneToMany.getOrderBy()); - - //set orderBy to null in the resource model - oneToMany.setOrderBy(null); - assertNull(ormOneToManyMapping.getOrderBy()); - assertNull(oneToMany.getOrderBy()); - } - - public void testModifyOrderBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getOrderBy()); - assertNull(oneToMany.getOrderBy()); - - //set mappedBy in the context model, verify resource model updated - ormOneToManyMapping.setOrderBy("newOrderBy"); - assertEquals("newOrderBy", ormOneToManyMapping.getOrderBy()); - assertEquals("newOrderBy", oneToMany.getOrderBy()); - - //set mappedBy to null in the context model - ormOneToManyMapping.setOrderBy(null); - assertNull(ormOneToManyMapping.getOrderBy()); - assertNull(oneToMany.getOrderBy()); - } - - public void testIsNoOrdering() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - - assertTrue(ormOneToManyMapping.isNoOrdering()); - - ormOneToManyMapping.setOrderBy("foo"); - assertFalse(ormOneToManyMapping.isNoOrdering()); - - ormOneToManyMapping.setOrderBy(null); - assertTrue(ormOneToManyMapping.isNoOrdering()); - } - - public void testSetNoOrdering() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - - assertTrue(ormOneToManyMapping.isNoOrdering()); - - ormOneToManyMapping.setOrderBy("foo"); - assertFalse(ormOneToManyMapping.isNoOrdering()); - - ormOneToManyMapping.setNoOrdering(true); - assertTrue(ormOneToManyMapping.isNoOrdering()); - assertNull(ormOneToManyMapping.getOrderBy()); - } -//TODO -// public boolean isOrderByPk() { -// return "".equals(getOrderBy()); -// } -// -// public void setOrderByPk() { -// setOrderBy(""); -// } - - public void testIsCustomOrdering() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - - assertFalse(ormOneToManyMapping.isCustomOrdering()); - - ormOneToManyMapping.setOrderBy("foo"); - assertTrue(ormOneToManyMapping.isCustomOrdering()); - - ormOneToManyMapping.setOrderBy(null); - assertFalse(ormOneToManyMapping.isCustomOrdering()); - } - - public void testOneToManyMorphToIdMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToVersionMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToTransientMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToEmbeddedMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToEmbeddedIdMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToOneToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getCascade().setAll(true); - oneToManyMapping.getCascade().setMerge(true); - oneToManyMapping.getCascade().setPersist(true); - oneToManyMapping.getCascade().setRefresh(true); - oneToManyMapping.getCascade().setRemove(true); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((OneToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((OneToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((OneToOneMapping) ormPersistentAttribute.getMapping()).getMappedBy()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testOneToManyMorphToManyToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getCascade().setAll(true); - oneToManyMapping.getCascade().setMerge(true); - oneToManyMapping.getCascade().setPersist(true); - oneToManyMapping.getCascade().setRefresh(true); - oneToManyMapping.getCascade().setRemove(true); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getMappedBy()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - JoinTable joinTable = ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getJoinTable(); - assertEquals("MY_JOIN_TABLE", joinTable.getName()); - assertEquals("name", joinTable.joinColumns().next().getSpecifiedName()); - assertEquals("referenceName", joinTable.joinColumns().next().getSpecifiedReferencedColumnName()); - assertEquals("inverseName", joinTable.inverseJoinColumns().next().getSpecifiedName()); - assertEquals("inverseReferenceName", joinTable.inverseJoinColumns().next().getSpecifiedReferencedColumnName()); - } - - public void testOneToManyMorphToManyToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getCascade().setAll(true); - oneToManyMapping.getCascade().setMerge(true); - oneToManyMapping.getCascade().setPersist(true); - oneToManyMapping.getCascade().setRefresh(true); - oneToManyMapping.getCascade().setRemove(true); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testOneToManyMorphToBasicMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getCascade().setAll(true); - oneToManyMapping.getCascade().setMerge(true); - oneToManyMapping.getCascade().setPersist(true); - oneToManyMapping.getCascade().setRefresh(true); - oneToManyMapping.getCascade().setRemove(true); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); -//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java deleted file mode 100644 index 19f63d59ac..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java +++ /dev/null @@ -1,955 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.BasicMapping; -import org.eclipse.jpt.core.context.Cascade; -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.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.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -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.iterators.ArrayIterator; - -public class OrmOneToOneMappingTests extends ContextModelTestCase -{ - public OrmOneToOneMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private ICompilationUnit createTestEntityOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - 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(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); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertEquals("oneToOneMapping", ormOneToOneMapping.getName()); - assertEquals("oneToOneMapping", oneToOne.getName()); - - //set name in the resource model, verify context model updated - oneToOne.setName("newName"); - assertEquals("newName", ormOneToOneMapping.getName()); - assertEquals("newName", oneToOne.getName()); - - //set name to null in the resource model - oneToOne.setName(null); - assertNull(ormOneToOneMapping.getName()); - assertNull(oneToOne.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertEquals("oneToOneMapping", ormOneToOneMapping.getName()); - assertEquals("oneToOneMapping", oneToOne.getName()); - - //set name in the context model, verify resource model updated - ormOneToOneMapping.setName("newName"); - assertEquals("newName", ormOneToOneMapping.getName()); - assertEquals("newName", oneToOne.getName()); - - //set name to null in the context model - ormOneToOneMapping.setName(null); - assertNull(ormOneToOneMapping.getName()); - assertNull(oneToOne.getName()); - } - - public void testUpdateSpecifiedTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - oneToOne.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormOneToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToOne.getTargetEntity()); - - //set target entity to null in the resource model - oneToOne.setTargetEntity(null); - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - ormOneToOneMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormOneToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToOne.getTargetEntity()); - - //set target entity to null in the context model - ormOneToOneMapping.setSpecifiedTargetEntity(null); - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOneResource.getFetch()); - - //set fetch in the resource model, verify context model updated - oneToOneResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, oneToOneResource.getFetch()); - - oneToOneResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormOneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, oneToOneResource.getFetch()); - - //set fetch to null in the resource model - oneToOneResource.setFetch(null); - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOneResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOneResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormOneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, oneToOneResource.getFetch()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getSpecifiedFetch()); - - ormOneToOneMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, oneToOneResource.getFetch()); - assertEquals(FetchType.LAZY, ormOneToOneMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormOneToOneMapping.setSpecifiedFetch(null); - assertNull(oneToOneResource.getFetch()); - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - } - - public void testUpdateMappedBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getMappedBy()); - assertNull(oneToOne.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - oneToOne.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", ormOneToOneMapping.getMappedBy()); - assertEquals("newMappedBy", oneToOne.getMappedBy()); - - //set mappedBy to null in the resource model - oneToOne.setMappedBy(null); - assertNull(ormOneToOneMapping.getMappedBy()); - assertNull(oneToOne.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getMappedBy()); - assertNull(oneToOne.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - ormOneToOneMapping.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", ormOneToOneMapping.getMappedBy()); - assertEquals("newMappedBy", oneToOne.getMappedBy()); - - //set mappedBy to null in the context model - ormOneToOneMapping.setMappedBy(null); - assertNull(ormOneToOneMapping.getMappedBy()); - assertNull(oneToOne.getMappedBy()); - } - - - public void testUpdateSpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOneResource.getOptional()); - - //set optional in the resource model, verify context model updated - oneToOneResource.setOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormOneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, oneToOneResource.getOptional()); - - oneToOneResource.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormOneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, oneToOneResource.getOptional()); - - //set optional to null in the resource model - oneToOneResource.setOptional(null); - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOneResource.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOneResource.getOptional()); - - //set optional in the context model, verify resource model updated - ormOneToOneMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, oneToOneResource.getOptional()); - assertEquals(Boolean.TRUE, ormOneToOneMapping.getSpecifiedOptional()); - - ormOneToOneMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToOneResource.getOptional()); - assertEquals(Boolean.FALSE, ormOneToOneMapping.getSpecifiedOptional()); - - //set optional to null in the context model - ormOneToOneMapping.setSpecifiedOptional(null); - assertNull(oneToOneResource.getOptional()); - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - OrmJoinColumn joinColumn = ormOneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", oneToOneResource.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormOneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("FOO", oneToOneResource.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormOneToOneMapping.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getJoinColumns().get(2).getName()); - - ListIterator<OrmJoinColumn> joinColumns = ormOneToOneMapping.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormOneToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - ormOneToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormOneToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormOneToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToOneResource.getJoinColumns().size()); - - ormOneToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(2, oneToOneResource.getJoinColumns().size()); - assertEquals("BAR", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(1).getName()); - - ormOneToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(1, oneToOneResource.getJoinColumns().size()); - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(0).getName()); - - ormOneToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(0, oneToOneResource.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - ormOneToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormOneToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormOneToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToOneResource.getJoinColumns().size()); - - - ormOneToOneMapping.moveSpecifiedJoinColumn(2, 0); - ListIterator<OrmJoinColumn> joinColumns = ormOneToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getJoinColumns().get(2).getName()); - - - ormOneToOneMapping.moveSpecifiedJoinColumn(0, 1); - joinColumns = ormOneToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAR", oneToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getJoinColumns().get(2).getName()); - } - - public void testOneToOneMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormOneToOneMapping.getName()); - - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(Boolean.TRUE, ormOneToOneMapping.getOptional()); - assertNull(ormOneToOneMapping.getTargetEntity()); - - - assertFalse(ormOneToOneMapping.specifiedJoinColumns().hasNext()); - //TODO default joinColumns - //assertTrue(ormOneToOneMapping.defaultJoinColumns().hasNext()); - - - Cascade cascade = ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormOneToOneMapping.getName()); - assertEquals(FetchType.LAZY, ormOneToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, ormOneToOneMapping.getSpecifiedOptional()); - assertEquals("Address", ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(ormOneToOneMapping.getMappedBy()); - - OrmJoinColumn ormJoinColumn = ormOneToOneMapping.specifiedJoinColumns().next(); - assertEquals("MY_COLUMN", ormJoinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", ormJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", ormJoinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", ormJoinColumn.getSpecifiedTable()); - - Cascade cascade = ormOneToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.makeSpecified(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormOneToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(Boolean.TRUE, ormOneToOneMapping.getOptional()); - assertEquals("test.Address", ormOneToOneMapping.getTargetEntity()); - assertNull(ormOneToOneMapping.getMappedBy()); - - //TODO default join columns in xml one-to-one -// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.specifiedJoinColumns().next(); -// //TODO java default columns name in JavaSingleRelationshipMapping.JoinColumnOwner -// //assertEquals("address", ormJoinColumn.getSpecifiedName()); -// //assertEquals("address", ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getSpecifiedTable()); - - Cascade cascade = ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormOneToOneMapping.getName()); - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(ormOneToOneMapping.getMappedBy()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(Boolean.TRUE, ormOneToOneMapping.getOptional()); - //TODO default target entity in xml - //assertEquals("test.Address", ormOneToOneMapping.getDefaultTargetEntity()); - - assertFalse(ormOneToOneMapping.specifiedJoinColumns().hasNext()); - - //TODO default join columns for specified xmlOneToOne mapping -// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.defaultJoinColumns().next(); -// assertNull(ormJoinColumn.getSpecifiedName()); -// assertNull(ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertNull(ormJoinColumn.getSpecifiedUnique()); -// assertNull(ormJoinColumn.getSpecifiedNullable()); -// assertNull(ormJoinColumn.getSpecifiedInsertable()); -// assertNull(ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertNull(ormJoinColumn.getSpecifiedTable()); -// -// assertEquals("address", ormJoinColumn.getDefaultName()); -// assertEquals("address", ormJoinColumn.getDefaultReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getDefaultUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultUpdatable()); -// assertEquals(null, ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getDefaultTable()); - - Cascade cascade = ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - - public void testOneToOneMorphToIdMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToVersionMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToTransientMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToEmbeddedMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToEmbeddedIdMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToManyToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getMappedBy()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testOneToOneMorphToOneToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((OneToManyMapping) ormPersistentAttribute.getMapping()).getMappedBy()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testOneToOneMorphToManyToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - - joinColumn = ((ManyToOneMapping) ormPersistentAttribute.getMapping()).specifiedJoinColumns().next(); - assertEquals("name", joinColumn.getName()); - assertEquals("referenceName", joinColumn.getReferencedColumnName()); - } - - public void testOneToOneMorphToBasicMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - - - - - public void testAddPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - OrmPrimaryKeyJoinColumn joinColumn = ormOneToOneMapping.addPrimaryKeyJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - - OrmPrimaryKeyJoinColumn joinColumn2 = ormOneToOneMapping.addPrimaryKeyJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - - OrmPrimaryKeyJoinColumn joinColumn3 = ormOneToOneMapping.addPrimaryKeyJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(2).getName()); - - ListIterator<OrmPrimaryKeyJoinColumn> joinColumns = ormOneToOneMapping.primaryKeyJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormOneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemovePrimaryKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - ormOneToOneMapping.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormOneToOneMapping.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormOneToOneMapping.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToOneResource.getPrimaryKeyJoinColumns().size()); - - ormOneToOneMapping.removePrimaryKeyJoinColumn(0); - assertEquals(2, oneToOneResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - - ormOneToOneMapping.removePrimaryKeyJoinColumn(0); - assertEquals(1, oneToOneResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - - ormOneToOneMapping.removePrimaryKeyJoinColumn(0); - assertEquals(0, oneToOneResource.getPrimaryKeyJoinColumns().size()); - } - - public void testMovePrimaryKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - ormOneToOneMapping.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormOneToOneMapping.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormOneToOneMapping.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToOneResource.getPrimaryKeyJoinColumns().size()); - - - ormOneToOneMapping.movePrimaryKeyJoinColumn(2, 0); - ListIterator<OrmPrimaryKeyJoinColumn> joinColumns = ormOneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(2).getName()); - - - ormOneToOneMapping.movePrimaryKeyJoinColumn(0, 1); - joinColumns = ormOneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(2).getName()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPersistentAttributeTests.java deleted file mode 100644 index aaefccf921..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPersistentAttributeTests.java +++ /dev/null @@ -1,251 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.orm; - -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.BasicMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmIdMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmNullAttributeMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmOneToOneMapping; -import org.eclipse.jpt.core.resource.java.JPA; -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; - -public class OrmPersistentAttributeTests extends ContextModelTestCase -{ - public OrmPersistentAttributeTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private ICompilationUnit createTestTypeNullAttributeMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestEntityIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Column(name=\"FOO\")"); - } - }); - } - - private ICompilationUnit createTestEntityOneToOneMapping() 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"); - sb.append(" private Address address;"); - } - }); - } - - public void testMakeSpecified() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - ormPersistentAttribute.makeSpecified(); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ormPersistentAttribute.makeSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - ListIterator<OrmPersistentAttribute> specifiedAttributes = ormPersistentType.specifiedAttributes(); - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("name", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeSpecifiedMappingKey() throws Exception { - createTestTypeNullAttributeMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - //take a virtual mapping with a mapping type and make it specified - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("address", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertTrue(ormPersistentAttribute.getMapping() instanceof GenericOrmNullAttributeMapping); - ormPersistentAttribute.makeSpecified(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof GenericOrmOneToOneMapping); - - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ormPersistentAttribute.makeSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - ListIterator<OrmPersistentAttribute> specifiedAttributes = ormPersistentType.specifiedAttributes(); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof GenericOrmIdMapping); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeVirtual() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().makeSpecified(); - ormPersistentType.virtualAttributes().next().makeSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute.makeVirtual(); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - - specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.makeVirtual(); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - assertEquals(0, ormPersistentType.specifiedAttributesSize()); - - ListIterator<OrmPersistentAttribute> virtualAttributes = ormPersistentType.virtualAttributes(); - OrmPersistentAttribute virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - } - - public void testMakeVirtualNoUnderlyingJavaAttribute() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().makeSpecified(); - ormPersistentType.virtualAttributes().next().makeSpecified(); - - - ormPersistentType.specifiedAttributes().next().getMapping().setName("noJavaAttribute"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - - - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.makeVirtual(); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - - assertEquals("id", ormPersistentType.virtualAttributes().next().getName()); - assertEquals("name", ormPersistentType.specifiedAttributes().next().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("FOO", ((IdMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("id", ((BasicMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete2() throws Exception { - createTestEntityOneToOneMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPersistentTypeTests.java deleted file mode 100644 index 116390af5b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPersistentTypeTests.java +++ /dev/null @@ -1,510 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlBasicImpl; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedIdImpl; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedImpl; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.orm.XmlIdImpl; -import org.eclipse.jpt.core.resource.orm.XmlManyToManyImpl; -import org.eclipse.jpt.core.resource.orm.XmlManyToOneImpl; -import org.eclipse.jpt.core.resource.orm.XmlOneToManyImpl; -import org.eclipse.jpt.core.resource.orm.XmlOneToOneImpl; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.resource.orm.XmlTransientImpl; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -import org.eclipse.jpt.core.resource.orm.XmlVersionImpl; -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; - -public class OrmPersistentTypeTests extends ContextModelTestCase -{ - public OrmPersistentTypeTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - -// public void testUpdateXmlTypeMapping() throws Exception { -// assertFalse(entityMappings().ormPersistentTypes().hasNext()); -// assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); -// assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); -// assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); -// -// //add embeddable in the resource model, verify context model updated -// Embeddable embeddable = OrmFactory.eINSTANCE.createEmbeddable(); -// ormResource().getEntityMappings().getEmbeddables().add(embeddable); -// embeddable.setClassName("model.Foo"); -// assertTrue(entityMappings().ormPersistentTypes().hasNext()); -// assertEquals("model.Foo", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); -// assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); -// assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); -// assertEquals("model.Foo", ormResource().getEntityMappings().getEmbeddables().get(0).getClassName()); -// -// //add entity in the resource model, verify context model updated -// Entity entity = OrmFactory.eINSTANCE.createEntity(); -// ormResource().getEntityMappings().getEntities().add(entity); -// entity.setClassName("model.Foo2"); -// assertTrue(entityMappings().ormPersistentTypes().hasNext()); -// assertEquals("model.Foo2", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); -// assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); -// assertEquals("model.Foo2", ormResource().getEntityMappings().getEntities().get(0).getClassName()); -// -// //add mapped-superclass in the resource model, verify context model updated -// MappedSuperclass mappedSuperclass = OrmFactory.eINSTANCE.createMappedSuperclass(); -// ormResource().getEntityMappings().getMappedSuperclasses().add(mappedSuperclass); -// mappedSuperclass.setClassName("model.Foo3"); -// assertTrue(entityMappings().ormPersistentTypes().hasNext()); -// assertEquals("model.Foo3", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); -// assertFalse(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); -// assertEquals("model.Foo3", ormResource().getEntityMappings().getMappedSuperclasses().get(0).getClassName()); -// } -// - - public void testMorphXmlTypeMapping() throws Exception { - assertFalse(entityMappings().ormPersistentTypes().hasNext()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - - OrmPersistentType embeddablePersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - OrmPersistentType mappedSuperclassPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo3"); - - OrmPersistentType ormPersistentType = entityMappings().ormPersistentTypes().next(); - assertEquals(mappedSuperclassPersistentType, ormPersistentType); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, ormPersistentType.getMapping().getKey()); - - ormPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - assertEquals(0, ormResource().getEntityMappings().getMappedSuperclasses().size()); - assertEquals(1, ormResource().getEntityMappings().getEntities().size()); - assertEquals(2, ormResource().getEntityMappings().getEmbeddables().size()); - - Iterator<OrmPersistentType> ormPersistentTypes = entityMappings().ormPersistentTypes(); - //the same OrmPersistentTypes should still be in the context model - assertEquals(ormPersistentTypes.next(), entityPersistentType); - assertEquals(ormPersistentTypes.next(), embeddablePersistentType); - assertEquals(ormPersistentTypes.next(), mappedSuperclassPersistentType); - - assertEquals("model.Foo", ormResource().getEntityMappings().getEmbeddables().get(0).getClassName()); - assertEquals("model.Foo3", ormResource().getEntityMappings().getEmbeddables().get(1).getClassName()); - } - - public void testAddSpecifiedPersistentAttribute() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicAttribute"); - - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entity.getAttributes().getBasics().get(0); - assertEquals("basicAttribute", basic.getName()); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedAttribute"); - - XmlEmbedded embedded = entity.getAttributes().getEmbeddeds().get(0); - assertEquals("embeddedAttribute", embedded.getName()); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientAttribute"); - - XmlTransient transientResource = entity.getAttributes().getTransients().get(0); - assertEquals("transientAttribute", transientResource.getName()); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionAttribute"); - - XmlVersion version = entity.getAttributes().getVersions().get(0); - assertEquals("versionAttribute", version.getName()); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idAttribute"); - - XmlId id = entity.getAttributes().getIds().get(0); - assertEquals("idAttribute", id.getName()); - - - ListIterator<OrmPersistentAttribute> persistentAttributes = entityPersistentType.specifiedAttributes(); - assertEquals("idAttribute", persistentAttributes.next().getName()); - assertEquals("basicAttribute", persistentAttributes.next().getName()); - assertEquals("versionAttribute", persistentAttributes.next().getName()); - assertEquals("embeddedAttribute", persistentAttributes.next().getName()); - assertEquals("transientAttribute", persistentAttributes.next().getName()); - assertFalse(persistentAttributes.hasNext()); - } - - public void testRemoveSpecifiedPersistentAttribute() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicAttribute"); - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedAttribute"); - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionAttribute"); - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idAttribute"); - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientAttribute"); - - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("basicAttribute", entity.getAttributes().getBasics().get(0).getName()); - assertEquals("embeddedAttribute", entity.getAttributes().getEmbeddeds().get(0).getName()); - assertEquals("versionAttribute", entity.getAttributes().getVersions().get(0).getName()); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("basicAttribute")); - assertEquals("embeddedAttribute", entity.getAttributes().getEmbeddeds().get(0).getName()); - assertEquals("versionAttribute", entity.getAttributes().getVersions().get(0).getName()); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("embeddedAttribute")); - assertEquals("versionAttribute", entity.getAttributes().getVersions().get(0).getName()); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("versionAttribute")); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("idAttribute")); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("transientAttribute")); - assertNull(entity.getAttributes()); - } - - public void testRemoveId() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idAttribute"); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("idAttribute")); - assertNull(entity.getAttributes()); - } - - public void testRemoveBasic() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicAttribute"); - assertEquals("basicAttribute", entity.getAttributes().getBasics().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("basicAttribute")); - assertNull(entity.getAttributes()); - } - - public void testRemoveVersion() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionAttribute"); - assertEquals("versionAttribute", entity.getAttributes().getVersions().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("versionAttribute")); - assertNull(entity.getAttributes()); - } - - public void testRemoveEmbedded() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedAttribute"); - assertEquals("embeddedAttribute", entity.getAttributes().getEmbeddeds().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("embeddedAttribute")); - assertNull(entity.getAttributes()); - } - - public void testRemoveTransient() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientAttribute"); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("transientAttribute")); - assertNull(entity.getAttributes()); - } - - public void testUpdateSpecifiedPersistentAttributes() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - - entity.setAttributes(OrmFactory.eINSTANCE.createAttributes()); - XmlBasicImpl basic = OrmFactory.eINSTANCE.createXmlBasicImpl(); - entity.getAttributes().getBasics().add(basic); - basic.setName("basicAttribute"); - - OrmPersistentAttribute ormPersistentAttribute = entityPersistentType.attributes().next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - - XmlEmbeddedImpl embedded = OrmFactory.eINSTANCE.createXmlEmbeddedImpl(); - entity.getAttributes().getEmbeddeds().add(embedded); - embedded.setName("embeddedAttribute"); - - ListIterator<OrmPersistentAttribute> attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlVersionImpl version = OrmFactory.eINSTANCE.createXmlVersionImpl(); - entity.getAttributes().getVersions().add(version); - version.setName("versionAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlIdImpl id = OrmFactory.eINSTANCE.createXmlIdImpl(); - entity.getAttributes().getIds().add(id); - id.setName("idAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlTransientImpl transientResource = OrmFactory.eINSTANCE.createXmlTransientImpl(); - entity.getAttributes().getTransients().add(transientResource); - transientResource.setName("transientAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlManyToOneImpl manyToOneResource = OrmFactory.eINSTANCE.createXmlManyToOneImpl(); - entity.getAttributes().getManyToOnes().add(manyToOneResource); - manyToOneResource.setName("manyToOneAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlManyToManyImpl manyToManyResource = OrmFactory.eINSTANCE.createXmlManyToManyImpl(); - entity.getAttributes().getManyToManys().add(manyToManyResource); - manyToManyResource.setName("manyToManyAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlOneToManyImpl oneToManyResource = OrmFactory.eINSTANCE.createXmlOneToManyImpl(); - entity.getAttributes().getOneToManys().add(oneToManyResource); - oneToManyResource.setName("oneToManyAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlOneToOneImpl oneToOneResource = OrmFactory.eINSTANCE.createXmlOneToOneImpl(); - entity.getAttributes().getOneToOnes().add(oneToOneResource); - oneToOneResource.setName("oneToOneAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - - XmlEmbeddedIdImpl embeddedIdResource = OrmFactory.eINSTANCE.createXmlEmbeddedIdImpl(); - entity.getAttributes().getEmbeddedIds().add(embeddedIdResource); - embeddedIdResource.setName("embeddedIdAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedIdAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - entity.getAttributes().getBasics().remove(0); - entity.getAttributes().getEmbeddeds().remove(0); - entity.getAttributes().getTransients().remove(0); - entity.getAttributes().getIds().remove(0); - entity.getAttributes().getVersions().remove(0); - entity.getAttributes().getManyToOnes().remove(0); - entity.getAttributes().getManyToManys().remove(0); - entity.getAttributes().getOneToManys().remove(0); - entity.getAttributes().getOneToOnes().remove(0); - entity.getAttributes().getEmbeddedIds().remove(0); - assertFalse(entityPersistentType.attributes().hasNext()); - assertNotNull(entity.getAttributes()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPrimaryKeyJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPrimaryKeyJoinColumnTests.java deleted file mode 100644 index 8f0dfae4da..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPrimaryKeyJoinColumnTests.java +++ /dev/null @@ -1,292 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -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.iterators.ArrayIterator; - -public class OrmPrimaryKeyJoinColumnTests extends ContextModelTestCase -{ - public OrmPrimaryKeyJoinColumnTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - 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 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 void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertNull(primaryKeyJoinColumnResource.getName()); - - //set name in the resource model, verify context model updated - primaryKeyJoinColumnResource.setName("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumnResource.getName()); - - //set name to null in the resource model - primaryKeyJoinColumnResource.setName(null); - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertNull(primaryKeyJoinColumnResource.getName()); - - primaryKeyJoinColumnResource.setName("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumnResource.getName()); - - entityResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormEntity.specifiedPrimaryKeyJoinColumns().hasNext()); - assertTrue(entityResource.getPrimaryKeyJoinColumns().isEmpty()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertNull(primaryKeyJoinColumnResource.getName()); - - //set name in the context model, verify resource model modified - ormPrimaryKeyJoinColumn.setSpecifiedName("foo"); - assertEquals("foo", ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertEquals("foo", primaryKeyJoinColumnResource.getName()); - - //set name to null in the context model - ormPrimaryKeyJoinColumn.setSpecifiedName(null); - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertNull(entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - } - - public void testUpdateSpecifiedReferencedColumnName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertNull(primaryKeyJoinColumnResource.getReferencedColumnName()); - - //set name in the resource model, verify context model updated - primaryKeyJoinColumnResource.setReferencedColumnName("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals("FOO", primaryKeyJoinColumnResource.getReferencedColumnName()); - - //set name to null in the resource model - primaryKeyJoinColumnResource.setReferencedColumnName(null); - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertNull(primaryKeyJoinColumnResource.getReferencedColumnName()); - - primaryKeyJoinColumnResource.setReferencedColumnName("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals("FOO", primaryKeyJoinColumnResource.getReferencedColumnName()); - - entityResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormEntity.specifiedPrimaryKeyJoinColumns().hasNext()); - assertTrue(entityResource.getPrimaryKeyJoinColumns().isEmpty()); - } - - public void testModifySpecifiedReferencedColumnName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertNull(primaryKeyJoinColumnResource.getReferencedColumnName()); - - //set name in the context model, verify resource model modified - ormPrimaryKeyJoinColumn.setSpecifiedReferencedColumnName("foo"); - assertEquals("foo", ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals("foo", primaryKeyJoinColumnResource.getReferencedColumnName()); - - //set name to null in the context model - ormPrimaryKeyJoinColumn.setSpecifiedReferencedColumnName(null); - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertNull(entityResource.getPrimaryKeyJoinColumns().get(0).getReferencedColumnName()); - } - -// public void testUpdateDefaultNameFromJavaTable() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.javaEntity().getTable().setSpecifiedName("Foo"); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// -// ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); -// ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.setSpecifiedMetadataComplete(null); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// -// ormEntity.getTable().setSpecifiedName("Bar"); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// } -// -// public void testUpdateDefaultNameNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// } -// -// public void testUpdateDefaultNameFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals(TYPE_NAME, childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.getTable().setSpecifiedName("FOO"); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("AnnotationTestTypeChild", childXmlEntity.getTable().getDefaultName()); -// } - - - public void testUpdateSpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertNull(primaryKeyJoinColumnResource.getColumnDefinition()); - - //set name in the resource model, verify context model updated - primaryKeyJoinColumnResource.setColumnDefinition("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertEquals("FOO", primaryKeyJoinColumnResource.getColumnDefinition()); - - //set name to null in the resource model - primaryKeyJoinColumnResource.setColumnDefinition(null); - assertNull(ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertNull(primaryKeyJoinColumnResource.getColumnDefinition()); - - primaryKeyJoinColumnResource.setColumnDefinition("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertEquals("FOO", primaryKeyJoinColumnResource.getColumnDefinition()); - - entityResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormEntity.specifiedPrimaryKeyJoinColumns().hasNext()); - assertTrue(entityResource.getPrimaryKeyJoinColumns().isEmpty()); - } - - public void testModifySpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertNull(primaryKeyJoinColumnResource.getColumnDefinition()); - - //set name in the context model, verify resource model modified - ormPrimaryKeyJoinColumn.setColumnDefinition("foo"); - assertEquals("foo", ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertEquals("foo", primaryKeyJoinColumnResource.getColumnDefinition()); - - //set name to null in the context model - ormPrimaryKeyJoinColumn.setColumnDefinition(null); - assertNull(ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertNull(entityResource.getPrimaryKeyJoinColumns().get(0).getColumnDefinition()); - } - - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmQueryHintTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmQueryHintTests.java deleted file mode 100644 index 1323d381d3..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmQueryHintTests.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.XmlQueryHint; -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; - -public class OrmQueryHintTests extends ContextModelTestCase -{ - public OrmQueryHintTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmQueryHint ormQueryHint = ormEntity.addNamedQuery(0).addHint(0); - - XmlQueryHint queryHintResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0).getHints().get(0); - - assertNull(ormQueryHint.getName()); - assertNull(queryHintResource.getName()); - - //set name in the resource model, verify context model updated - queryHintResource.setName("newName"); - assertEquals("newName", ormQueryHint.getName()); - assertEquals("newName", queryHintResource.getName()); - - //set name to null in the resource model - queryHintResource.setName(null); - assertNull(ormQueryHint.getName()); - assertNull(queryHintResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmQueryHint ormQueryHint = ormEntity.addNamedQuery(0).addHint(0); - - XmlQueryHint queryHintResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0).getHints().get(0); - - assertNull(ormQueryHint.getName()); - assertNull(queryHintResource.getName()); - - //set name in the context model, verify resource model updated - ormQueryHint.setName("newName"); - assertEquals("newName", ormQueryHint.getName()); - assertEquals("newName", queryHintResource.getName()); - - //set name to null in the context model - ormQueryHint.setName(null); - assertNull(ormQueryHint.getName()); - assertNull(queryHintResource.getName()); - } - - public void testUpdateValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmQueryHint ormQueryHint = ormEntity.addNamedQuery(0).addHint(0); - - XmlQueryHint queryHintResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0).getHints().get(0); - - assertNull(ormQueryHint.getValue()); - assertNull(queryHintResource.getValue()); - - //set name in the resource model, verify context model updated - queryHintResource.setValue("newName"); - assertEquals("newName", ormQueryHint.getValue()); - assertEquals("newName", queryHintResource.getValue()); - - //set name to null in the resource model - queryHintResource.setValue(null); - assertNull(ormQueryHint.getValue()); - assertNull(queryHintResource.getValue()); - } - - public void testModifyValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmQueryHint ormQueryHint = ormEntity.addNamedQuery(0).addHint(0); - - XmlQueryHint queryHintResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0).getHints().get(0); - - assertNull(ormQueryHint.getValue()); - assertNull(queryHintResource.getValue()); - - //set name in the context model, verify resource model updated - ormQueryHint.setValue("newName"); - assertEquals("newName", ormQueryHint.getValue()); - assertEquals("newName", queryHintResource.getValue()); - - //set name to null in the context model - ormQueryHint.setValue(null); - assertNull(ormQueryHint.getValue()); - assertNull(queryHintResource.getValue()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSecondaryTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSecondaryTableTests.java deleted file mode 100644 index e150408d8a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSecondaryTableTests.java +++ /dev/null @@ -1,763 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.InheritanceType; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -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.iterators.ArrayIterator; - -public class OrmSecondaryTableTests extends ContextModelTestCase -{ - public OrmSecondaryTableTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - 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 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 void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - //set name in the resource model, verify context model updated - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTableImpl()); - entityResource.getSecondaryTables().get(0).setName("FOO"); - OrmSecondaryTable secondaryTable = ormEntity.specifiedSecondaryTables().next(); - assertEquals("FOO", secondaryTable.getSpecifiedName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(0).getName()); - - //set name to null in the resource model - entityResource.getSecondaryTables().get(0).setName(null); - assertNull(secondaryTable.getSpecifiedName()); - assertNull(entityResource.getSecondaryTables().get(0).getName()); - - entityResource.getSecondaryTables().remove(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - //set name in the context model, verify resource model modified - OrmSecondaryTable secondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable.setSpecifiedName("foo"); - - assertEquals("foo", secondaryTable.getSpecifiedName()); - assertEquals("foo", entityResource.getSecondaryTables().get(0).getName()); - - //set name to null in the context model - secondaryTable.setSpecifiedName(null); - assertNull(secondaryTable.getSpecifiedName()); - assertNull(entityResource.getSecondaryTables().get(0).getName()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - ormEntity.getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - - OrmSecondaryTable ormSecondaryTable = ormEntity.virtualSecondaryTables().next(); - assertEquals("FOO", ormSecondaryTable.getSpecifiedName()); - - ormEntity.getJavaEntity().specifiedSecondaryTables().next().setSpecifiedName("BAZ"); - assertEquals("BAZ", ormSecondaryTable.getSpecifiedName()); - - ormEntity.setSecondaryTablesDefinedInXml(true); - assertNull(ormEntity.specifiedSecondaryTables().next().getDefaultName()); - assertEquals("BAZ", ormEntity.specifiedSecondaryTables().next().getSpecifiedName()); - - } - - public void testUpdateSpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - //set schema in the resource model, verify context model updated - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTableImpl()); - entityResource.getSecondaryTables().get(0).setSchema("FOO"); - OrmSecondaryTable secondaryTable = ormEntity.specifiedSecondaryTables().next(); - assertEquals("FOO", secondaryTable.getSpecifiedSchema()); - assertEquals("FOO", entityResource.getSecondaryTables().get(0).getSchema()); - - //set schema to null in the resource model - entityResource.getSecondaryTables().get(0).setSchema(null); - assertNull(secondaryTable.getSpecifiedSchema()); - assertNull(entityResource.getSecondaryTables().get(0).getSchema()); - - entityResource.getSecondaryTables().remove(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testModifySpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - //set schema in the context model, verify resource model modified - OrmSecondaryTable secondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable.setSpecifiedSchema("foo"); - - assertEquals("foo", secondaryTable.getSpecifiedSchema()); - assertEquals("foo", entityResource.getSecondaryTables().get(0).getSchema()); - - //set schema to null in the context model - secondaryTable.setSpecifiedSchema(null); - assertNull(secondaryTable.getSpecifiedSchema()); - assertNull(entityResource.getSecondaryTables().get(0).getSchema()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testUpdateDefaultSchemaFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - SecondaryTable javaSecondaryTable = ormEntity.getJavaEntity().addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("FOO"); - javaSecondaryTable.setSpecifiedSchema("BAR"); - - OrmSecondaryTable ormSecondaryTable = ormEntity.virtualSecondaryTables().next(); - assertEquals("BAR", ormSecondaryTable.getSpecifiedSchema()); - - javaSecondaryTable.setSpecifiedSchema("BAZ"); - assertEquals("BAZ", ormSecondaryTable.getSpecifiedSchema()); - - - ormEntity.setSecondaryTablesDefinedInXml(true); - assertNull(ormEntity.specifiedSecondaryTables().next().getDefaultSchema()); - assertEquals("BAZ", ormEntity.specifiedSecondaryTables().next().getSpecifiedSchema()); - } - - public void testUpdateDefaultSchemaFromParent() throws Exception { - createTestEntity(); - createTestSubType(); - - OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentOrmEntity = (OrmEntity) parentOrmPersistentType.getMapping(); - OrmEntity childOrmEntity = (OrmEntity) childOrmPersistentType.getMapping(); - - assertNull(parentOrmEntity.getTable().getDefaultSchema()); - assertNull(childOrmEntity.getTable().getDefaultSchema()); - - parentOrmEntity.getTable().setSpecifiedSchema("FOO"); - assertNull(parentOrmEntity.getTable().getDefaultSchema()); - assertEquals("FOO", childOrmEntity.getTable().getDefaultSchema()); - - parentOrmEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertNull(parentOrmEntity.getTable().getDefaultSchema()); - assertNull(childOrmEntity.getTable().getDefaultSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - ormSecondaryTable.setSpecifiedName("FOO"); - assertNull(ormSecondaryTable.getDefaultSchema()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", ormSecondaryTable.getDefaultSchema()); - - entityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", ormSecondaryTable.getDefaultSchema()); - - SecondaryTable javaSecondaryTable = ormEntity.getJavaEntity().addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("FOO"); - javaSecondaryTable.setSpecifiedSchema("JAVA_SCHEMA"); - assertEquals("BAR", ormSecondaryTable.getDefaultSchema()); //schema is not defaulted from underlying java - - entityMappings().setSpecifiedSchema(null); - assertEquals("FOO", ormSecondaryTable.getDefaultSchema()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema(null); - assertNull(ormSecondaryTable.getDefaultSchema()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - //set catalog in the resource model, verify context model updated - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTableImpl()); - entityResource.getSecondaryTables().get(0).setCatalog("FOO"); - OrmSecondaryTable secondaryTable = ormEntity.specifiedSecondaryTables().next(); - assertEquals("FOO", secondaryTable.getSpecifiedCatalog()); - assertEquals("FOO", entityResource.getSecondaryTables().get(0).getCatalog()); - - //set catalog to null in the resource model - entityResource.getSecondaryTables().get(0).setCatalog(null); - assertNull(secondaryTable.getSpecifiedCatalog()); - assertNull(entityResource.getSecondaryTables().get(0).getCatalog()); - - entityResource.getSecondaryTables().remove(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testModifySpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - //set catalog in the context model, verify resource model modified - OrmSecondaryTable secondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable.setSpecifiedCatalog("foo"); - - assertEquals("foo", secondaryTable.getSpecifiedCatalog()); - assertEquals("foo", entityResource.getSecondaryTables().get(0).getCatalog()); - - //set catalog to null in the context model - secondaryTable.setSpecifiedCatalog(null); - assertNull(secondaryTable.getSpecifiedCatalog()); - assertNull(entityResource.getSecondaryTables().get(0).getCatalog()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testUpdateDefaultCatalogFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - SecondaryTable javaSecondaryTable = ormEntity.getJavaEntity().addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("FOO"); - javaSecondaryTable.setSpecifiedCatalog("BAR"); - - OrmSecondaryTable ormSecondaryTable = ormEntity.virtualSecondaryTables().next(); - assertEquals("BAR", ormSecondaryTable.getSpecifiedCatalog()); - - javaSecondaryTable.setSpecifiedCatalog("BAZ"); - assertEquals("BAZ", ormSecondaryTable.getSpecifiedCatalog()); - - ormEntity.setSecondaryTablesDefinedInXml(true); - assertNull(ormEntity.specifiedSecondaryTables().next().getDefaultCatalog()); - assertEquals("BAZ", ormEntity.specifiedSecondaryTables().next().getSpecifiedCatalog()); - } - - public void testUpdateDefaultCatalogFromPersistenceUnitDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - ormSecondaryTable.setSpecifiedName("FOO"); - assertNull(ormSecondaryTable.getDefaultCatalog()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog("FOO"); - assertEquals("FOO", ormSecondaryTable.getDefaultCatalog()); - - entityMappings().setSpecifiedCatalog("BAR"); - assertEquals("BAR", ormSecondaryTable.getDefaultCatalog()); - - SecondaryTable javaSecondaryTable = ormEntity.getJavaEntity().addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("FOO"); - javaSecondaryTable.setSpecifiedCatalog("JAVA_CATALOG"); - assertEquals("BAR", ormSecondaryTable.getDefaultCatalog()); //schema is not defaulted from underlying java - - entityMappings().setSpecifiedCatalog(null); - assertEquals("FOO", ormSecondaryTable.getDefaultCatalog()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog(null); - assertNull(ormSecondaryTable.getDefaultCatalog()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); - primaryKeyJoinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn2 = ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); - primaryKeyJoinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn3 = ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(1); - primaryKeyJoinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(2).getName()); - - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals(primaryKeyJoinColumn2, primaryKeyJoinColumns.next()); - assertEquals(primaryKeyJoinColumn3, primaryKeyJoinColumns.next()); - assertEquals(primaryKeyJoinColumn, primaryKeyJoinColumns.next()); - - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - } - - public void testRemoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - - ormSecondaryTable.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(2, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - - ormSecondaryTable.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(1, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - - ormSecondaryTable.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(0, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - } - - public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - - - ormSecondaryTable.moveSpecifiedPrimaryKeyJoinColumn(2, 0); - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(2).getName()); - - - ormSecondaryTable.moveSpecifiedPrimaryKeyJoinColumn(0, 1); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(2).getName()); - } - - public void testUpdatePrimaryKeyJoinColumns() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - secondaryTableResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl()); - secondaryTableResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl()); - secondaryTableResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl()); - - secondaryTableResource.getPrimaryKeyJoinColumns().get(0).setName("FOO"); - secondaryTableResource.getPrimaryKeyJoinColumns().get(1).setName("BAR"); - secondaryTableResource.getPrimaryKeyJoinColumns().get(2).setName("BAZ"); - - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().move(2, 0); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().move(0, 1); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().remove(1); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().remove(1); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormSecondaryTable.specifiedPrimaryKeyJoinColumns().hasNext()); - } - - - public void testUniqueConstraints() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - assertEquals(0, ormSecondaryTable.uniqueConstraintsSize()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, ormSecondaryTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = secondaryTableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormSecondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = secondaryTableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormSecondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormSecondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, secondaryTableResource.getUniqueConstraints().size()); - - ormSecondaryTable.removeUniqueConstraint(1); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator<OrmUniqueConstraint> uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormSecondaryTable.removeUniqueConstraint(1); - uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormSecondaryTable.removeUniqueConstraint(0); - uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormSecondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormSecondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, secondaryTableResource.getUniqueConstraints().size()); - - - ormSecondaryTable.moveUniqueConstraint(2, 0); - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - ormSecondaryTable.moveUniqueConstraint(0, 1); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().move(2, 0); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().move(0, 1); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().remove(1); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().remove(1); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().remove(0); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - - public void testUniqueConstraintsFromJava() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - JavaEntity javaEntity = (JavaEntity) ormPersistentType.getJavaPersistentType().getMapping(); - JavaSecondaryTable javaSecondaryTable = javaEntity.addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("SECONDARY"); - - OrmSecondaryTable ormSecondaryTable = ormEntity.secondaryTables().next(); - assertTrue(ormSecondaryTable.isVirtual()); - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - - javaSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - javaSecondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - javaSecondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - ormEntity.setSecondaryTablesDefinedInXml(true); - OrmSecondaryTable ormSecondaryTable2 = ormEntity.secondaryTables().next(); - ormSecondaryTable2.setSpecifiedName("SECONDARY"); - - assertEquals("SECONDARY", ormSecondaryTable.getSpecifiedName()); - assertFalse(ormSecondaryTable2.isVirtual()); - assertEquals(0, ormSecondaryTable2.uniqueConstraintsSize()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSequenceGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSequenceGeneratorTests.java deleted file mode 100644 index 5d54536317..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSequenceGeneratorTests.java +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.SequenceGenerator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -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.iterators.ArrayIterator; - -public class OrmSequenceGeneratorTests extends ContextModelTestCase -{ - public OrmSequenceGeneratorTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - 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 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 void testUpdateSpecifiedName() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set name in the resource model, verify context model updated - sequenceGeneratorResource.setName("FOO"); - assertEquals("FOO", sequenceGenerator.getName()); - assertEquals("FOO", sequenceGeneratorResource.getName()); - - //set name to null in the resource model - sequenceGeneratorResource.setName(null); - assertNull(sequenceGenerator.getName()); - assertNull(sequenceGeneratorResource.getName()); - } - - public void testModifySpecifiedName() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set name in the context model, verify resource model modified - sequenceGenerator.setName("FOO"); - assertEquals("FOO", sequenceGeneratorResource.getName()); - assertEquals("FOO", sequenceGenerator.getName()); - - //set name to null in the context model - sequenceGenerator.setName(null); - assertNull(sequenceGeneratorResource.getName()); - assertNull(sequenceGenerator.getName()); - } - - public void testUpdateSpecifiedSequenceName() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set name in the resource model, verify context model updated - sequenceGeneratorResource.setSequenceName("FOO"); - assertEquals("FOO", sequenceGenerator.getSpecifiedSequenceName()); - assertEquals("FOO", sequenceGeneratorResource.getSequenceName()); - - //set name to null in the resource model - sequenceGeneratorResource.setSequenceName(null); - assertNull(sequenceGenerator.getSpecifiedSequenceName()); - assertNull(sequenceGeneratorResource.getSequenceName()); - } - - public void testModifySpecifiedSequenceName() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set name in the context model, verify resource model modified - sequenceGenerator.setSpecifiedSequenceName("FOO"); - assertEquals("FOO", sequenceGeneratorResource.getSequenceName()); - assertEquals("FOO", sequenceGenerator.getSpecifiedSequenceName()); - - //set name to null in the context model - sequenceGenerator.setSpecifiedSequenceName(null); - assertNull(sequenceGeneratorResource.getSequenceName()); - assertNull(sequenceGenerator.getSpecifiedSequenceName()); - } - - public void testUpdateSpecifiedInitialValue() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set initial value in the resource model, verify context model updated - sequenceGeneratorResource.setInitialValue(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), sequenceGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(10), sequenceGeneratorResource.getInitialValue()); - - //set initial value to 1, which happens to be the default, in the resource model - sequenceGeneratorResource.setInitialValue(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), sequenceGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(1), sequenceGeneratorResource.getInitialValue()); - - //set initial value to null in the resource model - sequenceGeneratorResource.setInitialValue(null); - assertNull(sequenceGenerator.getSpecifiedInitialValue()); - assertNull(sequenceGeneratorResource.getInitialValue()); - } - - public void testModifySpecifiedInitialValue() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set initial value in the context model, verify resource model modified - sequenceGenerator.setSpecifiedInitialValue(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), sequenceGeneratorResource.getInitialValue()); - assertEquals(Integer.valueOf(10), sequenceGenerator.getSpecifiedInitialValue()); - - sequenceGenerator.setSpecifiedInitialValue(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), sequenceGeneratorResource.getInitialValue()); - assertEquals(Integer.valueOf(1), sequenceGenerator.getSpecifiedInitialValue()); - - //set initial value to null in the context model - sequenceGenerator.setSpecifiedInitialValue(null); - assertNull(sequenceGeneratorResource.getInitialValue()); - assertNull(sequenceGenerator.getSpecifiedInitialValue()); - } - - public void testUpdateSpecifiedAllocationSize() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set allocation size in the resource model, verify context model updated - sequenceGeneratorResource.setAllocationSize(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), sequenceGenerator.getSpecifiedAllocationSize()); - assertEquals(Integer.valueOf(10), sequenceGeneratorResource.getAllocationSize()); - - //set allocation size to 50, which happens to be the default, in the resource model - sequenceGeneratorResource.setAllocationSize(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), sequenceGenerator.getSpecifiedAllocationSize()); - assertEquals(Integer.valueOf(1), sequenceGeneratorResource.getAllocationSize()); - - //set allocation size to null in the resource model - sequenceGeneratorResource.setAllocationSize(null); - assertNull(sequenceGenerator.getSpecifiedAllocationSize()); - assertNull(sequenceGeneratorResource.getAllocationSize()); - } - - public void testModifySpecifiedAllocationSize() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set allocation size in the context model, verify resource model modified - sequenceGenerator.setSpecifiedAllocationSize(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), sequenceGeneratorResource.getAllocationSize()); - assertEquals(Integer.valueOf(10), sequenceGenerator.getSpecifiedAllocationSize()); - - sequenceGenerator.setSpecifiedAllocationSize(Integer.valueOf(50)); - assertEquals(Integer.valueOf(50), sequenceGeneratorResource.getAllocationSize()); - assertEquals(Integer.valueOf(50), sequenceGenerator.getSpecifiedAllocationSize()); - - //set allocation size to null in the context model - sequenceGenerator.setSpecifiedAllocationSize(null); - assertNull(sequenceGeneratorResource.getAllocationSize()); - assertNull(sequenceGenerator.getSpecifiedAllocationSize()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableGeneratorTests.java deleted file mode 100644 index ac4af0ec38..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableGeneratorTests.java +++ /dev/null @@ -1,622 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.TableGenerator; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -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.iterators.ArrayIterator; - -public class OrmTableGeneratorTests extends ContextModelTestCase -{ - public OrmTableGeneratorTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - 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 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 void testUpdateSpecifiedName() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setName("FOO"); - assertEquals("FOO", tableGenerator.getName()); - assertEquals("FOO", tableGeneratorResource.getName()); - - //set name to null in the resource model - tableGeneratorResource.setName(null); - assertNull(tableGenerator.getName()); - assertNull(tableGeneratorResource.getName()); - } - - public void testModifySpecifiedName() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setName("FOO"); - assertEquals("FOO", tableGeneratorResource.getName()); - assertEquals("FOO", tableGenerator.getName()); - - //set name to null in the context model - tableGenerator.setName(null); - assertNull(tableGeneratorResource.getName()); - assertNull(tableGenerator.getName()); - } - - public void testUpdateSpecifiedInitialValue() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set initial value in the resource model, verify context model updated - tableGeneratorResource.setInitialValue(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), tableGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(10), tableGeneratorResource.getInitialValue()); - - //set initial value to 1, which happens to be the default, in the resource model - tableGeneratorResource.setInitialValue(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(1), tableGeneratorResource.getInitialValue()); - - //set initial value to null in the resource model - tableGeneratorResource.setInitialValue(null); - assertNull(tableGenerator.getSpecifiedInitialValue()); - assertNull(tableGeneratorResource.getInitialValue()); - } - - public void testModifySpecifiedInitialValue() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set initial value in the context model, verify resource model modified - tableGenerator.setSpecifiedInitialValue(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), tableGeneratorResource.getInitialValue()); - assertEquals(Integer.valueOf(10), tableGenerator.getSpecifiedInitialValue()); - - tableGenerator.setSpecifiedInitialValue(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), tableGeneratorResource.getInitialValue()); - assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedInitialValue()); - - //set initial value to null in the context model - tableGenerator.setSpecifiedInitialValue(null); - assertNull(tableGeneratorResource.getInitialValue()); - assertNull(tableGenerator.getSpecifiedInitialValue()); - } - - public void testUpdateSpecifiedAllocationSize() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set allocation size in the resource model, verify context model updated - tableGeneratorResource.setAllocationSize(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), tableGenerator.getSpecifiedAllocationSize()); - assertEquals(Integer.valueOf(10), tableGeneratorResource.getAllocationSize()); - - //set allocation size to 50, which happens to be the default, in the resource model - tableGeneratorResource.setAllocationSize(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedAllocationSize()); - assertEquals(Integer.valueOf(1), tableGeneratorResource.getAllocationSize()); - - //set allocation size to null in the resource model - tableGeneratorResource.setAllocationSize(null); - assertNull(tableGenerator.getSpecifiedAllocationSize()); - assertNull(tableGeneratorResource.getAllocationSize()); - } - - public void testModifySpecifiedAllocationSize() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set allocation size in the context model, verify resource model modified - tableGenerator.setSpecifiedAllocationSize(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), tableGeneratorResource.getAllocationSize()); - assertEquals(Integer.valueOf(10), tableGenerator.getSpecifiedAllocationSize()); - - tableGenerator.setSpecifiedAllocationSize(Integer.valueOf(50)); - assertEquals(Integer.valueOf(50), tableGeneratorResource.getAllocationSize()); - assertEquals(Integer.valueOf(50), tableGenerator.getSpecifiedAllocationSize()); - - //set allocation size to null in the context model - tableGenerator.setSpecifiedAllocationSize(null); - assertNull(tableGeneratorResource.getAllocationSize()); - assertNull(tableGenerator.getSpecifiedAllocationSize()); - } - - public void testUpdateSpecifiedTable() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setTable("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedTable()); - assertEquals("FOO", tableGeneratorResource.getTable()); - - //set name to null in the resource model - tableGeneratorResource.setTable(null); - assertNull(tableGenerator.getSpecifiedTable()); - assertNull(tableGeneratorResource.getTable()); - } - - public void testModifySpecifiedTable() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedTable("FOO"); - assertEquals("FOO", tableGeneratorResource.getTable()); - assertEquals("FOO", tableGenerator.getSpecifiedTable()); - - //set name to null in the context model - tableGenerator.setSpecifiedTable(null); - assertNull(tableGeneratorResource.getTable()); - assertNull(tableGenerator.getSpecifiedTable()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setSchema("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedSchema()); - assertEquals("FOO", tableGeneratorResource.getSchema()); - - //set name to null in the resource model - tableGeneratorResource.setSchema(null); - assertNull(tableGenerator.getSpecifiedSchema()); - assertNull(tableGeneratorResource.getSchema()); - } - - public void testModifySpecifiedSchema() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedSchema("FOO"); - assertEquals("FOO", tableGeneratorResource.getSchema()); - assertEquals("FOO", tableGenerator.getSpecifiedSchema()); - - //set name to null in the context model - tableGenerator.setSpecifiedSchema(null); - assertNull(tableGeneratorResource.getSchema()); - assertNull(tableGenerator.getSpecifiedSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - - assertNull(tableGenerator.getDefaultSchema()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", tableGenerator.getDefaultSchema()); - - entityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", tableGenerator.getDefaultSchema()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setCatalog("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedCatalog()); - assertEquals("FOO", tableGeneratorResource.getCatalog()); - - //set name to null in the resource model - tableGeneratorResource.setCatalog(null); - assertNull(tableGenerator.getSpecifiedCatalog()); - assertNull(tableGeneratorResource.getCatalog()); - } - - public void testModifySpecifiedCatalog() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedCatalog("FOO"); - assertEquals("FOO", tableGeneratorResource.getCatalog()); - assertEquals("FOO", tableGenerator.getSpecifiedCatalog()); - - //set name to null in the context model - tableGenerator.setSpecifiedCatalog(null); - assertNull(tableGeneratorResource.getCatalog()); - assertNull(tableGenerator.getSpecifiedCatalog()); - } - - public void testUpdateSpecifiedPkColumnName() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setPkColumnName("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedPkColumnName()); - assertEquals("FOO", tableGeneratorResource.getPkColumnName()); - - //set name to null in the resource model - tableGeneratorResource.setPkColumnName(null); - assertNull(tableGenerator.getSpecifiedPkColumnName()); - assertNull(tableGeneratorResource.getPkColumnName()); - } - - public void testModifySpecifiedPkColumnName() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedPkColumnName("FOO"); - assertEquals("FOO", tableGeneratorResource.getPkColumnName()); - assertEquals("FOO", tableGenerator.getSpecifiedPkColumnName()); - - //set name to null in the context model - tableGenerator.setSpecifiedPkColumnName(null); - assertNull(tableGeneratorResource.getPkColumnName()); - assertNull(tableGenerator.getSpecifiedPkColumnName()); - } - - public void testUpdateSpecifiedValueColumnName() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setValueColumnName("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedValueColumnName()); - assertEquals("FOO", tableGeneratorResource.getValueColumnName()); - - //set name to null in the resource model - tableGeneratorResource.setValueColumnName(null); - assertNull(tableGenerator.getSpecifiedValueColumnName()); - assertNull(tableGeneratorResource.getValueColumnName()); - } - - public void testModifySpecifiedValueColumnName() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedValueColumnName("FOO"); - assertEquals("FOO", tableGeneratorResource.getValueColumnName()); - assertEquals("FOO", tableGenerator.getSpecifiedValueColumnName()); - - //set name to null in the context model - tableGenerator.setSpecifiedValueColumnName(null); - assertNull(tableGeneratorResource.getValueColumnName()); - assertNull(tableGenerator.getSpecifiedValueColumnName()); - } - - public void testUpdateSpecifiedPkColumnValue() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setPkColumnValue("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedPkColumnValue()); - assertEquals("FOO", tableGeneratorResource.getPkColumnValue()); - - //set name to null in the resource model - tableGeneratorResource.setPkColumnValue(null); - assertNull(tableGenerator.getSpecifiedPkColumnValue()); - assertNull(tableGeneratorResource.getPkColumnValue()); - } - - public void testModifySpecifiedPkColumnValue() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedPkColumnValue("FOO"); - assertEquals("FOO", tableGeneratorResource.getPkColumnValue()); - assertEquals("FOO", tableGenerator.getSpecifiedPkColumnValue()); - - //set name to null in the context model - tableGenerator.setSpecifiedPkColumnValue(null); - assertNull(tableGeneratorResource.getPkColumnValue()); - assertNull(tableGenerator.getSpecifiedPkColumnValue()); - } - - - public void testUniqueConstraints() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - ListIterator<OrmUniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - 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 { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - assertEquals(0, tableGenerator.uniqueConstraintsSize()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, tableGenerator.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = tableGeneratorResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = tableGeneratorResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, tableGeneratorResource.getUniqueConstraints().size()); - - tableGenerator.removeUniqueConstraint(1); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator<UniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - tableGenerator.removeUniqueConstraint(1); - uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - tableGenerator.removeUniqueConstraint(0); - uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, tableGeneratorResource.getUniqueConstraints().size()); - - - 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<XmlUniqueConstraint> uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - 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()); - - uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - 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()); - - tableGeneratorResource.getUniqueConstraints().move(2, 0); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().move(0, 1); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().remove(1); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().remove(1); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().remove(0); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsFromJava() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentType.attributes().next().getMapping(); - - JavaIdMapping javaIdMapping = (JavaIdMapping) ormPersistentType.getJavaPersistentType().attributes().next().getMapping(); - JavaTableGenerator javaTableGenerator = javaIdMapping.addTableGenerator(); - javaTableGenerator.setName("TABLE_GENERATOR"); - - OrmTableGenerator ormTableGenerator = ormIdMapping.getTableGenerator(); - assertTrue(ormTableGenerator.isVirtual()); - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormTableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - - javaTableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - javaTableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - javaTableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - uniqueConstraints = ormTableGenerator.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - ormIdMapping.getPersistentAttribute().makeSpecified(); - ormIdMapping = (OrmIdMapping) ormPersistentType.attributes().next().getMapping(); - - OrmTableGenerator ormTableGenerator2 = ormIdMapping.addTableGenerator(); - ormTableGenerator2.setName("TABLE_GENERATOR"); - - assertFalse(ormTableGenerator2.isVirtual()); - assertEquals(0, ormTableGenerator2.uniqueConstraintsSize()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableTests.java deleted file mode 100644 index 5fba977c37..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableTests.java +++ /dev/null @@ -1,767 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.InheritanceType; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTable; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -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.iterators.ArrayIterator; - -public class OrmTableTests extends ContextModelTestCase -{ - public OrmTableTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - 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 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 void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable()); - - //set name in the resource model, verify context model updated - entityResource.setTable(OrmFactory.eINSTANCE.createXmlTable()); - entityResource.getTable().setName("FOO"); - assertEquals("FOO", ormTable.getSpecifiedName()); - assertEquals("FOO", entityResource.getTable().getName()); - - //set name to null in the resource model - entityResource.getTable().setName(null); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable().getName()); - - entityResource.getTable().setName("FOO"); - assertEquals("FOO", ormTable.getSpecifiedName()); - assertEquals("FOO", entityResource.getTable().getName()); - - entityResource.setTable(null); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmTable ormTable = ((OrmEntity) ormPersistentType.getMapping()).getTable(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable()); - - //set name in the context model, verify resource model modified - ormTable.setSpecifiedName("foo"); - assertEquals("foo", ormTable.getSpecifiedName()); - assertEquals("foo", entityResource.getTable().getName()); - - //set name to null in the context model - ormTable.setSpecifiedName(null); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - ormEntity.getJavaEntity().getTable().setSpecifiedName("Foo"); - assertEquals("Foo", ormEntity.getTable().getDefaultName()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals("Foo", ormEntity.getTable().getDefaultName()); - - ormEntity.getTable().setSpecifiedName("Bar"); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - } - - public void testUpdateDefaultNameNoJava() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals("Foo", ormEntity.getTable().getDefaultName()); - } - - public void testUpdateDefaultNameFromEntityName() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - ormEntity.setSpecifiedName("foo"); - - assertEquals("foo", ormEntity.getTable().getDefaultName()); - - ormEntity.setSpecifiedName(null); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - ormEntity.getJavaEntity().setSpecifiedName("foo"); - assertEquals("foo", ormEntity.getTable().getDefaultName()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - } - - public void testUpdateDefaultNameFromParent() throws Exception { - createTestEntity(); - createTestSubType(); - - OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentXmlEntity = (OrmEntity) parentOrmPersistentType.getMapping(); - OrmEntity childXmlEntity = (OrmEntity) childOrmPersistentType.getMapping(); - - assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); - assertEquals(TYPE_NAME, childXmlEntity.getTable().getDefaultName()); - - parentXmlEntity.getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); - assertEquals("FOO", childXmlEntity.getTable().getDefaultName()); - - parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); - assertEquals("AnnotationTestTypeChild", childXmlEntity.getTable().getDefaultName()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable()); - - //set schema in the resource model, verify context model updated - entityResource.setTable(OrmFactory.eINSTANCE.createXmlTable()); - entityResource.getTable().setSchema("FOO"); - assertEquals("FOO", ormTable.getSpecifiedSchema()); - assertEquals("FOO", entityResource.getTable().getSchema()); - - //set Schema to null in the resource model - entityResource.getTable().setSchema(null); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable().getSchema()); - - entityResource.getTable().setSchema("FOO"); - assertEquals("FOO", ormTable.getSpecifiedSchema()); - assertEquals("FOO", entityResource.getTable().getSchema()); - - entityResource.setTable(null); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable()); - } - - public void testUpdateDefaultSchemaFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultSchema()); - - ormEntity.getJavaEntity().getTable().setSpecifiedSchema("Foo"); - assertEquals("Foo", ormEntity.getTable().getDefaultSchema()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertNull(ormEntity.getTable().getDefaultSchema()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertNull(ormEntity.getTable().getDefaultSchema()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertNull(ormEntity.getTable().getDefaultSchema()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals("Foo", ormEntity.getTable().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedName("Bar"); - assertNull(ormEntity.getTable().getDefaultSchema()); - } - - public void testUpdateDefaultSchemaNoJava() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultSchema()); - } - - public void testUpdateDefaultSchemaFromParent() throws Exception { - createTestEntity(); - createTestSubType(); - - OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentXmlEntity = (OrmEntity) parentOrmPersistentType.getMapping(); - OrmEntity childXmlEntity = (OrmEntity) childOrmPersistentType.getMapping(); - - assertNull(parentXmlEntity.getTable().getDefaultSchema()); - assertNull(childXmlEntity.getTable().getDefaultSchema()); - - parentXmlEntity.getTable().setSpecifiedSchema("FOO"); - assertNull(parentXmlEntity.getTable().getDefaultSchema()); - assertEquals("FOO", childXmlEntity.getTable().getDefaultSchema()); - - parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertNull(parentXmlEntity.getTable().getDefaultSchema()); - assertNull(childXmlEntity.getTable().getDefaultSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultSchema()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", ormEntity.getTable().getDefaultSchema()); - - entityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", ormEntity.getTable().getDefaultSchema()); - - ormEntity.getJavaEntity().getTable().setSpecifiedSchema("JAVA_SCHEMA"); - assertEquals("JAVA_SCHEMA", ormEntity.getTable().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedName("BLAH"); - //xml entity now has a table element so default schema is not taken from java - assertEquals("BAR", ormEntity.getTable().getDefaultSchema()); - - - entityMappings().setSpecifiedSchema(null); - assertEquals("FOO", ormEntity.getTable().getDefaultSchema()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema(null); - assertNull(ormEntity.getTable().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedName(null); - assertEquals("JAVA_SCHEMA", ormEntity.getTable().getDefaultSchema()); - } - - public void testModifySpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable()); - - //set Schema in the context model, verify resource model modified - ormTable.setSpecifiedSchema("foo"); - assertEquals("foo", ormTable.getSpecifiedSchema()); - assertEquals("foo", entityResource.getTable().getSchema()); - - //set Schema to null in the context model - ormTable.setSpecifiedSchema(null); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable()); - - //set Catalog in the resource model, verify context model updated - entityResource.setTable(OrmFactory.eINSTANCE.createXmlTable()); - entityResource.getTable().setCatalog("FOO"); - assertEquals("FOO", ormTable.getSpecifiedCatalog()); - assertEquals("FOO", entityResource.getTable().getCatalog()); - - //set Catalog to null in the resource model - entityResource.getTable().setCatalog(null); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable().getCatalog()); - - entityResource.getTable().setCatalog("FOO"); - assertEquals("FOO", ormTable.getSpecifiedCatalog()); - assertEquals("FOO", entityResource.getTable().getCatalog()); - - entityResource.setTable(null); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable()); - } - - public void testModifySpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable()); - - //set Catalog in the context model, verify resource model modified - ormTable.setSpecifiedCatalog("foo"); - assertEquals("foo", ormTable.getSpecifiedCatalog()); - assertEquals("foo", entityResource.getTable().getCatalog()); - - //set Catalog to null in the context model - ormTable.setSpecifiedCatalog(null); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable()); - } - - public void testUpdateDefaultCatalogFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getJavaEntity().getTable().setSpecifiedCatalog("Foo"); - assertEquals("Foo", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals("Foo", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getTable().setSpecifiedName("Bar"); - assertNull(ormEntity.getTable().getDefaultCatalog()); - } - - public void testUpdateDefaultCatalogNoJava() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultCatalog()); - } - - public void testUpdateDefaultCatalogFromParent() throws Exception { - createTestEntity(); - createTestSubType(); - - OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentXmlEntity = (OrmEntity) parentOrmPersistentType.getMapping(); - OrmEntity childXmlEntity = (OrmEntity) childOrmPersistentType.getMapping(); - - assertNull(parentXmlEntity.getTable().getDefaultCatalog()); - assertNull(childXmlEntity.getTable().getDefaultCatalog()); - - parentXmlEntity.getTable().setSpecifiedCatalog("FOO"); - assertNull(parentXmlEntity.getTable().getDefaultCatalog()); - assertEquals("FOO", childXmlEntity.getTable().getDefaultCatalog()); - - parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertNull(parentXmlEntity.getTable().getDefaultCatalog()); - assertNull(childXmlEntity.getTable().getDefaultCatalog()); - } - - public void testUpdateDefaultCatalogFromPersistenceUnitDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog("FOO"); - assertEquals("FOO", ormEntity.getTable().getDefaultCatalog()); - - entityMappings().setSpecifiedCatalog("BAR"); - assertEquals("BAR", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getJavaEntity().getTable().setSpecifiedCatalog("JAVA_CATALOG"); - assertEquals("JAVA_CATALOG", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getTable().setSpecifiedName("BLAH"); - //xml entity now has a table element so default schema is not taken from java - assertEquals("BAR", ormEntity.getTable().getDefaultCatalog()); - - - entityMappings().setSpecifiedCatalog(null); - assertEquals("FOO", ormEntity.getTable().getDefaultCatalog()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog(null); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getTable().setSpecifiedName(null); - assertEquals("JAVA_CATALOG", ormEntity.getTable().getDefaultCatalog()); -} - -// -// public void testUpdateName() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// Entity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// assertEquals("Foo", ormEntity.getName()); -// -// //set class in the resource model, verify context model updated -// entityResource.setClassName("com.Bar"); -// assertEquals("Bar", ormEntity.getName()); -// -// entityResource.setName("Baz"); -// assertEquals("Baz", ormEntity.getName()); -// -// //set class to null in the resource model -// entityResource.setClassName(null); -// assertEquals("Baz", ormEntity.getName()); -// -// entityResource.setName(null); -// assertNull(ormEntity.getName()); -// } - - public void testUniqueConstraints() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormEntity.getTable().uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = OrmFactory.eINSTANCE.createXmlTable(); - entityResource.setTable(tableResource); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = ormEntity.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 { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - assertEquals(0, ormEntity.getTable().uniqueConstraintsSize()); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = OrmFactory.eINSTANCE.createXmlTable(); - entityResource.setTable(tableResource); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, ormEntity.getTable().uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(0).addColumnName(0, "BAR"); - table.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = entityResource.getTable(); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = tableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = entityResource.getTable(); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = tableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = entityResource.getTable(); - - assertEquals(3, tableResource.getUniqueConstraints().size()); - - table.removeUniqueConstraint(1); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator<OrmUniqueConstraint> uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - table.removeUniqueConstraint(1); - uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - table.removeUniqueConstraint(0); - uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = entityResource.getTable(); - - assertEquals(3, tableResource.getUniqueConstraints().size()); - - - table.moveUniqueConstraint(2, 0); - ListIterator<OrmUniqueConstraint> uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - 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()); - - uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = OrmFactory.eINSTANCE.createXmlTable(); - entityResource.setTable(tableResource); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - ListIterator<OrmUniqueConstraint> uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().move(2, 0); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().move(0, 1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().remove(1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().remove(1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().remove(0); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - -//TODO not yet supporting unique constriants from java -// public void testUniqueConstraintsFromJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); -// -// ListIterator<OrmUniqueConstraint> uniqueConstraints = ormEntity.getTable().uniqueConstraints(); -// assertFalse(uniqueConstraints.hasNext()); -// -// JavaEntity javaEntity = (JavaEntity) ormPersistentType.getJavaPersistentType().getMapping(); -// javaEntity.getTable().addUniqueConstraint(0).addColumnName(0, "FOO"); -// javaEntity.getTable().addUniqueConstraint(1).addColumnName(0, "BAR"); -// javaEntity.getTable().addUniqueConstraint(2).addColumnName(0, "BAZ"); -// -// -// XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// assertNull(entityResource.getTable()); -// -// uniqueConstraints = ormEntity.getTable().uniqueConstraints(); -// assertTrue(uniqueConstraints.hasNext()); -// assertEquals("FOO", uniqueConstraints.next().columnNames().next()); -// assertEquals("BAR", uniqueConstraints.next().columnNames().next()); -// assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); -// assertFalse(uniqueConstraints.hasNext()); -// -// entityResource.setTable(OrmFactory.eINSTANCE.createXmlTableImpl()); -// assertEquals(0, ormEntity.getTable().uniqueConstraintsSize()); -// } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTransientMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTransientMappingTests.java deleted file mode 100644 index 369fc2ad05..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTransientMappingTests.java +++ /dev/null @@ -1,301 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.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.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTransientMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -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; - -public class OrmTransientMappingTests extends ContextModelTestCase -{ - public OrmTransientMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private ICompilationUnit createTestEntityTransientMapping() 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"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transient"); - } - }); - } - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientMapping"); - OrmTransientMapping xmlTransientnMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - XmlTransient transientResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getTransients().get(0); - - assertEquals("transientMapping", xmlTransientnMapping.getName()); - assertEquals("transientMapping", transientResource.getName()); - - //set name in the resource model, verify context model updated - transientResource.setName("newName"); - assertEquals("newName", xmlTransientnMapping.getName()); - assertEquals("newName", transientResource.getName()); - - //set name to null in the resource model - transientResource.setName(null); - assertNull(xmlTransientnMapping.getName()); - assertNull(transientResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientMapping"); - OrmTransientMapping xmlTransientnMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - XmlTransient transientResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getTransients().get(0); - - assertEquals("transientMapping", xmlTransientnMapping.getName()); - assertEquals("transientMapping", transientResource.getName()); - - //set name in the context model, verify resource model updated - xmlTransientnMapping.setName("newName"); - assertEquals("newName", xmlTransientnMapping.getName()); - assertEquals("newName", transientResource.getName()); - - //set name to null in the context model - xmlTransientnMapping.setName(null); - assertNull(xmlTransientnMapping.getName()); - assertNull(transientResource.getName()); - } - - - public void testTransientMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityTransientMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmTransientMapping ormTransientMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormTransientMapping.getName()); - } - - //@Basic(fetch=FetchType.LAZY, optional=false) - //@Column(name="MY_COLUMN", unique=true, nullable=false, insertable=false, updatable=false, - // columnDefinition="COLUMN_DEFINITION", table="MY_TABLE", length=5, precision=6, scale=7)"); - //@Column( - //@Lob - //@Temporal(TemporalType.TIMESTAMP) - //@Enumerated(EnumType.STRING) - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmTransientMapping ormTransientMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormTransientMapping.getName()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.makeSpecified(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmTransientMapping ormTransientMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormTransientMapping.getName()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityTransientMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "id"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmTransientMapping ormTransientMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - - assertEquals("id", ormTransientMapping.getName()); - } - - public void testTransientMorphToIdMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToVersionMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToTransientMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToEmbeddedMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToEmbeddedIdMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToOneToOneMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToOneToManyMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToManyToOneMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToManyToManyMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmVersionMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmVersionMappingTests.java deleted file mode 100644 index 7ff26c1a79..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmVersionMappingTests.java +++ /dev/null @@ -1,485 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.orm; - -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.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.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.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -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; - -public class OrmVersionMappingTests extends ContextModelTestCase -{ - public OrmVersionMappingTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private ICompilationUnit createTestEntityVersionMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.VERSION, JPA.COLUMN, JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version"); - sb.append(CR); - sb.append(" @Column(name=\"MY_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\", length=5, precision=6, scale=7)"); - sb.append(CR); - sb.append(" @Temporal(TemporalType.TIMESTAMP)"); - } - }); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionMapping"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion versionResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - - assertEquals("versionMapping", ormVersionMapping.getName()); - assertEquals("versionMapping", versionResource.getName()); - - //set name in the resource model, verify context model updated - versionResource.setName("newName"); - assertEquals("newName", ormVersionMapping.getName()); - assertEquals("newName", versionResource.getName()); - - //set name to null in the resource model - versionResource.setName(null); - assertNull(ormVersionMapping.getName()); - assertNull(versionResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionMapping"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion versionResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - - assertEquals("versionMapping", ormVersionMapping.getName()); - assertEquals("versionMapping", versionResource.getName()); - - //set name in the context model, verify resource model updated - ormVersionMapping.setName("newName"); - assertEquals("newName", ormVersionMapping.getName()); - assertEquals("newName", versionResource.getName()); - - //set name to null in the context model - ormVersionMapping.setName(null); - assertNull(ormVersionMapping.getName()); - assertNull(versionResource.getName()); - } - - public void testUpdateTemporal() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionMapping"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion versionResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - - assertNull(ormVersionMapping.getSpecifiedConverter()); - assertNull(versionResource.getTemporal()); - - //set temporal in the resource model, verify context model updated - versionResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.DATE); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormVersionMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, versionResource.getTemporal()); - - versionResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIME); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormVersionMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, versionResource.getTemporal()); - - versionResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormVersionMapping.getConverter()).getTemporalType()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, versionResource.getTemporal()); - - //set temporal to null in the resource model - versionResource.setTemporal(null); - assertNull(ormVersionMapping.getSpecifiedConverter()); - assertNull(versionResource.getTemporal()); - } - - public void testModifyTemporal() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionMapping"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion versionResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - - assertNull(ormVersionMapping.getSpecifiedConverter()); - assertNull(versionResource.getTemporal()); - - //set temporal in the context model, verify resource model updated - ormVersionMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) ormVersionMapping.getSpecifiedConverter()).setTemporalType(TemporalType.DATE); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, versionResource.getTemporal()); - assertEquals(TemporalType.DATE, ((TemporalConverter) ormVersionMapping.getSpecifiedConverter()).getTemporalType()); - - ((TemporalConverter) ormVersionMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, versionResource.getTemporal()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ormVersionMapping.getSpecifiedConverter()).getTemporalType()); - - ((TemporalConverter) ormVersionMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIMESTAMP); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, versionResource.getTemporal()); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormVersionMapping.getSpecifiedConverter()).getTemporalType()); - - //set temporal to null in the context model - ormVersionMapping.setSpecifiedConverter(null); - assertNull(versionResource.getTemporal()); - assertNull(ormVersionMapping.getSpecifiedConverter()); - } - - //TODO test defaults - //TODO test overriding java mapping with a different mapping type in xml - - public void testVersionMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityVersionMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormVersionMapping.getName()); - assertNull(ormVersionMapping.getSpecifiedConverter()); - - - OrmColumn ormColumn = ormVersionMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("foo", ormColumn.getDefaultName()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Integer.valueOf(255), ormColumn.getDefaultLength()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultScale()); - } - - //@Basic(fetch=FetchType.LAZY, optional=false) - //@Column(name="MY_COLUMN", unique=true, nullable=false, insertable=false, updatable=false, - // columnDefinition="COLUMN_DEFINITION", table="MY_TABLE", length=5, precision=6, scale=7)"); - //@Column( - //@Lob - //@Temporal(TemporalType.TIMESTAMP) - //@Enumerated(EnumType.STRING) - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormVersionMapping.getName()); - assertEquals(Converter.TEMPORAL_CONVERTER, ormVersionMapping.getConverter().getType()); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) ormVersionMapping.getConverter()).getTemporalType()); - - OrmColumn ormColumn = ormVersionMapping.getColumn(); - assertEquals("MY_COLUMN", ormColumn.getSpecifiedName()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", ormColumn.getColumnDefinition()); - assertEquals("MY_TABLE", ormColumn.getSpecifiedTable()); - assertEquals(Integer.valueOf(5), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(6), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedScale()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.makeSpecified(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormVersionMapping.getName()); - assertNull(ormVersionMapping.getSpecifiedConverter()); - - OrmColumn ormColumn = ormVersionMapping.getColumn(); - assertEquals("id", ormColumn.getName()); - assertEquals(Boolean.FALSE, ormColumn.getUnique()); - assertEquals(Boolean.TRUE, ormColumn.getNullable()); - assertEquals(Boolean.TRUE, ormColumn.getInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getTable()); - assertEquals(Integer.valueOf(255), ormColumn.getLength()); - assertEquals(Integer.valueOf(0), ormColumn.getPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getScale()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityVersionMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "id"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - - assertEquals("id", ormVersionMapping.getName()); - assertNull(ormVersionMapping.getSpecifiedConverter()); - - OrmColumn ormColumn = ormVersionMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("id", ormColumn.getDefaultName()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Integer.valueOf(255), ormColumn.getDefaultLength()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultScale()); - } - - public void testVersionMorphToIdMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - assertEquals("FOO", ((IdMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testVersionMorphToBasicMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - assertEquals("FOO", ((BasicMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testVersionMorphToTransientMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToEmbeddedMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToEmbeddedIdMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToOneToOneMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToOneToManyMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToManyToOneMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToManyToManyMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setSpecifiedConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) versionMapping.getSpecifiedConverter()).setTemporalType(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmXmlTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmXmlTests.java deleted file mode 100644 index 2cc31866cf..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmXmlTests.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.OrmResource; -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; - -public class OrmXmlTests extends ContextModelTestCase -{ - public OrmXmlTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - xmlPersistenceUnit().setName("foo"); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - protected PersistenceXml persistenceXml() { - return getRootContextNode().getPersistenceXml(); - } - - protected OrmXml ormXml() { - return (OrmXml) persistenceUnit().mappingFileRefs().next().getMappingFile(); - } - - public void testUpdateAddEntityMappings() throws Exception { - OrmResource ormResource = ormResource(); - ormResource.getContents().clear(); - ormResource.save(null); - - // removing root node now results in reducing content type to simple xml - assertNull(ormXml()); - - ormResource.getContents().add(OrmFactory.eINSTANCE.createXmlEntityMappings()); - ormResource.save(null); - - assertNotNull(ormXml().getRoot()); - } - - public void testModifyAddEntityMappings() { - OrmResource ormResource = ormResource(); - ormResource.getContents().remove(ormResource.getEntityMappings()); - assertNull(ormResource.getEntityMappings()); - - OrmXml ormXml = ormXml(); - assertNull(ormXml.getRoot()); - - ormXml.addEntityMappings(); - - assertNotNull(ormXml.getRoot()); - - boolean exceptionThrown = false; - try { - ormXml.addEntityMappings(); - } - catch (IllegalStateException ise) { - exceptionThrown = true; - } - - assertTrue("IllegalStateException was not thrown", exceptionThrown); - } - - public void testUpdateRemoveEntityMappings() throws Exception { - OrmResource ormResource = ormResource(); - - assertNotNull(ormXml().getRoot()); - - ormResource.getContents().clear(); - - assertNull(ormXml().getRoot()); - } - - public void testModifyRemoveEntityMappings() { - OrmXml ormXml = ormXml(); - - assertNotNull(ormXml.getRoot()); - - ormXml.removeEntityMappings(); - - assertNull(ormXml.getRoot()); - - boolean exceptionThrown = false; - try { - ormXml.removeEntityMappings(); - } - catch (IllegalStateException ise) { - exceptionThrown = true; - } - - assertTrue("IllegalStateException was not thrown", exceptionThrown); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitDefaultsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitDefaultsTests.java deleted file mode 100644 index 4e74faad75..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitDefaultsTests.java +++ /dev/null @@ -1,369 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitDefaults; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata; -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; - -public class PersistenceUnitDefaultsTests extends ContextModelTestCase -{ - public PersistenceUnitDefaultsTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - protected OrmPersistenceUnitDefaults persistenceUnitDefaults() { - return entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults(); - } - - public void testIsAllFeaturesUnset() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - XmlPersistenceUnitMetadata persistenceUnitMetadata = OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata(); - ormResource().getEntityMappings().setPersistenceUnitMetadata(persistenceUnitMetadata); - assertTrue(persistenceUnitMetadata.isAllFeaturesUnset()); - - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults persistenceUnitDefaultsResource = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - persistenceUnitMetadata.setPersistenceUnitDefaults(persistenceUnitDefaultsResource); - assertTrue(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setCascadePersist(true); - assertFalse(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setCascadePersist(false); - assertTrue(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setSchema("asdf"); - assertFalse(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setSchema(null); - assertTrue(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setCatalog("asdf"); - assertFalse(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setCatalog(null); - assertTrue(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - - persistenceUnitDefaultsResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY); - assertFalse(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertFalse(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setAccess(null); - assertTrue(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - } - - public void testUpdateSchema() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set schema in the resource model, verify context model updated - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set schema to null in the resource model - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - } - - public void testModifySchema() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set schema in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set schema to null in the context model - persistenceUnitDefaults.setSpecifiedSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifySchema2() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set schema in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("MY_CATALOG"); - //set schema to null in the context model - persistenceUnitDefaults.setSpecifiedSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - } - - public void testModifySchema3() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set schema in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set schema to null in the context model - persistenceUnitDefaults.setSpecifiedSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - - public void testUpdateCatalog() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set catalog in the resource model, verify context model updated - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set catalog to null in the resource model - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - } - - public void testModifyCatalog() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set catalog in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set catalog to null in the context model - persistenceUnitDefaults.setSpecifiedCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyCatalog2() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set catalog in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema("MY_SCHEMA"); - //set catalog to null in the context model - persistenceUnitDefaults.setSpecifiedCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - } - - public void testModifyCatalog3() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set catalog in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set catalog to null in the context model - persistenceUnitDefaults.setSpecifiedCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - - public void testUpdateCascadePersist() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set cascadePersist in the resource model, verify context model updated - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set cascadePersist to null in the resource model, persistence-unit-defaults tag not removed - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertFalse(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - } - - public void testModifyCascadePersist() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set cascadePersist in the context model, verify resource model modified - persistenceUnitDefaults.setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set cascadePersist to null in the context model - persistenceUnitDefaults.setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyCascadePersist2() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set cascadePersist in the context model, verify resource model modified - persistenceUnitDefaults.setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("MY_CATALOG"); - //set cascadePersist to null in the context model - persistenceUnitDefaults.setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertFalse(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - } - - public void testModifyCascadePersist3() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set cascadePersist in the context model, verify resource model modified - persistenceUnitDefaults.setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set cascadePersist to null in the context model - persistenceUnitDefaults.setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - - - public void testUpdateAccess() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set access in the resource model, verify context model updated - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set access to null in the resource model - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - } - - public void testModifyAccess() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set access in the context model, verify resource model modified - persistenceUnitDefaults.setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set access to null in the context model - persistenceUnitDefaults.setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyAccess2() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set access in the context model, verify resource model modified - persistenceUnitDefaults.setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCascadePersist(true); - //set access to null in the context model - persistenceUnitDefaults.setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - } - - public void testModifyAccess3() throws Exception { - OrmPersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set access in the context model, verify resource model modified - persistenceUnitDefaults.setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set access to null in the context model - persistenceUnitDefaults.setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitMetadataTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitMetadataTests.java deleted file mode 100644 index feada5432d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitMetadataTests.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -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; - -public class PersistenceUnitMetadataTests extends ContextModelTestCase -{ - public PersistenceUnitMetadataTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - protected PersistenceUnitMetadata persistenceUnitMetadata() { - return entityMappings().getPersistenceUnitMetadata(); - } - - public void testIsAllFeaturesUnset() throws Exception { - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata persistenceUnitMetadata = OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata(); - ormResource().getEntityMappings().setPersistenceUnitMetadata(persistenceUnitMetadata); - assertTrue(persistenceUnitMetadata.isAllFeaturesUnset()); - - persistenceUnitMetadata.setXmlMappingMetadataComplete(true); - assertFalse(persistenceUnitMetadata.isAllFeaturesUnset()); - - persistenceUnitMetadata.setXmlMappingMetadataComplete(false); - assertTrue(persistenceUnitMetadata.isAllFeaturesUnset()); - - persistenceUnitMetadata.setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - assertFalse(persistenceUnitMetadata.isAllFeaturesUnset()); - } - - public void testUpdateXmlMappingMetadataComplete() throws Exception { - PersistenceUnitMetadata persistenceUnitMetadata = entityMappings().getPersistenceUnitMetadata(); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set xmlMappingMetadataComplete in the resource model, verify context model updated - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - - //set xmlMappingMetadataComplete to null in the resource model - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertFalse(ormResource().getEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - } - - public void testModifyXmlMappingMetadataComplete() throws Exception { - PersistenceUnitMetadata persistenceUnitMetadata = entityMappings().getPersistenceUnitMetadata(); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set xmlMappingMetadataComplete in the context model, verify resource model modified - persistenceUnitMetadata.setXmlMappingMetadataComplete(true); - assertTrue(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - - //set xmlMappingMetadataComplete to null in the context model - persistenceUnitMetadata.setXmlMappingMetadataComplete(false); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyXmlMappingMetadataComplete2() throws Exception { - PersistenceUnitMetadata persistenceUnitMetadata = entityMappings().getPersistenceUnitMetadata(); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set xmlMappingMetadataComplete in the context model, verify resource model modified - persistenceUnitMetadata.setXmlMappingMetadataComplete(true); - assertTrue(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - - //set xmlMappingMetadataComplete to null in the context model - //set another element on the persistence-unit-metadata element so it doesn't get removed - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - persistenceUnitMetadata.setXmlMappingMetadataComplete(false); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertFalse(ormResource().getEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - } -}
\ No newline at end of file |