diff options
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmPersistentAttributeTests.java')
-rw-r--r-- | jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmPersistentAttributeTests.java | 313 |
1 files changed, 0 insertions, 313 deletions
diff --git a/jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmPersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmPersistentAttributeTests.java deleted file mode 100644 index 6c0078b579..0000000000 --- a/jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmPersistentAttributeTests.java +++ /dev/null @@ -1,313 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jpa.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.AccessType; -import org.eclipse.jpt.jpa.core.context.BasicMapping; -import org.eclipse.jpt.jpa.core.context.IdMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyPersistentAttribute; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.jpa.core.resource.java.JPA; -import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.jpa.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.jpa.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.jpa.eclipselink.core.internal.context.orm.OrmEclipseLinkIdMapping; -import org.eclipse.jpt.jpa.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToOneMapping; - -@SuppressWarnings("nls") -public class EclipseLinkOrmPersistentAttributeTests - extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkOrmPersistentAttributeTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptJpaCorePlugin.DEFAULT_ORM_XML_RUNTIME_PATH.toString()); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().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 = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - ormPersistentAttribute.convertToSpecified(); - - 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.convertToSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - Iterator<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 = getEntityMappings().addPersistentType(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 - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("address", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertTrue(ormPersistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping); - ormPersistentAttribute.convertToSpecified(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()); - assertEquals(specifiedOrmPersistentAttribute.getMappingKey(), MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof OrmEclipseLinkOneToOneMapping); - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ormPersistentAttribute.convertToSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - Iterator<OrmPersistentAttribute> specifiedAttributes = ormPersistentType.specifiedAttributes(); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof OrmEclipseLinkIdMapping); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeVirtual() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().convertToSpecified(); - ormPersistentType.virtualAttributes().next().convertToSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - - specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.convertToVirtual(); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - assertEquals(0, ormPersistentType.specifiedAttributesSize()); - - Iterator<OrmReadOnlyPersistentAttribute> virtualAttributes = ormPersistentType.virtualAttributes(); - OrmReadOnlyPersistentAttribute virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - } - - public void testMakeVirtualNoUnderlyingJavaAttribute() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().convertToSpecified(); - ormPersistentType.virtualAttributes().next().convertToSpecified(); - - - ormPersistentType.specifiedAttributes().next().getMapping().setName("noJavaAttribute"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - - - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.convertToVirtual(); - 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 = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute 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.getAttributeNamed("id"); - 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 = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmReadOnlyPersistentAttribute 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.getAttributeNamed("address"); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - } - - public void testGetJavaPersistentAttribute() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - OrmReadOnlyPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - JavaPersistentAttribute javaPersistentAttribute = javaPersistentType.getAttributeNamed("id"); - - //virtual orm attribute, access type matches java : FIELD, name matches java - assertTrue(ormPersistentAttribute.isVirtual()); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - JavaResourcePersistentAttribute javaResourcePersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute(); - assertTrue(javaResourcePersistentAttribute.isField()); - assertEquals("id", javaResourcePersistentAttribute.getName()); - assertEquals(javaPersistentType.getResourcePersistentType().persistableFields().next(), javaResourcePersistentAttribute); - - - //specified orm attribute, access type matches java : FIELD, name matches java - //javaPersistentAttribute should be == to java context model object - ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertFalse(ormPersistentAttribute.isVirtual()); - assertEquals(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - - - //virtual orm attribute, java access type FIELD, orm access type PROPERTY, name matches java - //verify the property java resource persistent attribute is used in orm. - ((OrmPersistentAttribute) ormPersistentAttribute).convertToVirtual(); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertNotSame(ormPersistentAttribute, ormPersistentType.getAttributeNamed("id")); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - assertNotSame(javaPersistentAttribute, ormPersistentAttribute.getJavaPersistentAttribute()); - javaResourcePersistentAttribute = ormPersistentAttribute.getJavaPersistentAttribute().getResourcePersistentAttribute(); - assertTrue(javaResourcePersistentAttribute.isProperty()); - assertEquals("id", javaResourcePersistentAttribute.getName()); - assertEquals(javaPersistentType.getResourcePersistentType().persistableProperties().next(), javaResourcePersistentAttribute); - - - ormPersistentType.setSpecifiedAccess(null);//default access will be field - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - OrmPersistentAttribute ormPersistentAttribute2 = ormPersistentAttribute.convertToSpecified(); - ormPersistentAttribute2.getMapping().setName("id2"); - assertEquals(null, ormPersistentAttribute2.getJavaPersistentAttribute()); - - ormPersistentAttribute2.getMapping().setName(null); - assertEquals(null, ormPersistentAttribute2.getJavaPersistentAttribute()); - - ormPersistentAttribute2.getMapping().setName("id"); - assertEquals(javaPersistentAttribute, ormPersistentAttribute2.getJavaPersistentAttribute()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(javaPersistentAttribute, ormPersistentAttribute2.getJavaPersistentAttribute()); - } - -}
\ No newline at end of file |