diff options
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmIdMappingTests.java')
-rw-r--r-- | jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmIdMappingTests.java | 388 |
1 files changed, 0 insertions, 388 deletions
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmIdMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmIdMappingTests.java deleted file mode 100644 index adfc494486..0000000000 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmIdMappingTests.java +++ /dev/null @@ -1,388 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -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.eclipselink.core.context.EclipseLinkConvert; -import org.eclipse.jpt.eclipselink.core.context.EclipseLinkIdMapping; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkBasicMapping; -import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkIdMapping; -import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity; -import org.eclipse.jpt.eclipselink.core.resource.orm.XmlId; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class EclipseLinkOrmIdMappingTests - extends EclipseLinkOrmContextModelTestCase -{ - public EclipseLinkOrmIdMappingTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithMutableIdDate() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, EclipseLink.MUTABLE, "java.util.Date"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append(" @Mutable").append(CR); - sb.append(" private Date myDate;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - public void testUpdateMutable() throws Exception { - createTestEntityWithIdMapping(); - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - OrmEclipseLinkIdMapping contextId = - (OrmEclipseLinkIdMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlId resourceId = - (XmlId) resourceEntity.getAttributes().getIds().get(0); - EclipseLinkIdMapping javaIdMapping = (EclipseLinkIdMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - // check defaults - - assertNull(resourceId.getMutable()); - assertTrue(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - - // set xml mutable to false, check context - - resourceId.setMutable(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceId.getMutable()); - assertTrue(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - // set xml mutable to true, check context - - resourceId.setMutable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceId.getMutable()); - assertTrue(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - - // clear xml mutable, check context - - resourceId.setMutable(null); - - assertNull(resourceId.getMutable()); - assertTrue(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - - // TODO - test defaults for java serializable and date/time types, - // with and without persistence property - - // set mutable on java basic mapping - - javaIdMapping.getMutable().setSpecifiedMutable(Boolean.FALSE); - assertNull(resourceId.getMutable()); - assertTrue(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - assertFalse(javaIdMapping.getMutable().isMutable()); - - // remove attribute from xml, test default mutable from java - - ormPersistentType.removeSpecifiedAttribute(ormPersistentAttribute); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - contextId = (OrmEclipseLinkIdMapping) ormPersistentAttribute.getMapping(); - - assertNull(resourceId.getMutable()); - assertTrue(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - assertFalse(javaIdMapping.getMutable().isMutable()); - - // set metadata complete - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - OrmEclipseLinkBasicMapping contextBasic = (OrmEclipseLinkBasicMapping) ormPersistentAttribute.getMapping(); - assertNull(resourceId.getMutable()); - assertTrue(contextBasic.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextBasic.getMutable().getSpecifiedMutable()); - assertTrue(contextBasic.getMutable().isMutable()); - assertFalse(javaIdMapping.getMutable().isMutable()); - } - - public void testUpdateMutableDate() throws Exception { - createTestEntityWithMutableIdDate(); - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "myDate"); - OrmEclipseLinkIdMapping contextId = - (OrmEclipseLinkIdMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlId resourceId = - (XmlId) resourceEntity.getAttributes().getIds().get(0); - EclipseLinkIdMapping javaIdMapping = (EclipseLinkIdMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("myDate").getMapping(); - - // check defaults - - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - // set xml mutable to false, check context - - resourceId.setMutable(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - // set xml mutable to true, check context - - resourceId.setMutable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - - // clear xml mutable, check context - - resourceId.setMutable(null); - - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - - getPersistenceUnit().getOptions().setTemporalMutable(Boolean.TRUE); - assertNull(resourceId.getMutable()); - assertTrue(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - - getPersistenceUnit().getOptions().setTemporalMutable(Boolean.FALSE); - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - getPersistenceUnit().getOptions().setTemporalMutable(null); - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - // set mutable on java id mapping - - javaIdMapping.getMutable().setSpecifiedMutable(Boolean.TRUE); - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - assertTrue(javaIdMapping.getMutable().isMutable()); - - // remove attribute from xml, test default mutable from java - - ormPersistentType.removeSpecifiedAttribute(ormPersistentAttribute); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("myDate"); - contextId = (OrmEclipseLinkIdMapping) ormPersistentAttribute.getMapping(); - - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - assertTrue(javaIdMapping.getMutable().isMutable()); - - // set metadata complete - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("myDate"); - OrmEclipseLinkBasicMapping contextBasic = (OrmEclipseLinkBasicMapping) ormPersistentAttribute.getMapping(); - assertNull(resourceId.getMutable()); - assertFalse(contextBasic.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextBasic.getMutable().getSpecifiedMutable()); - assertFalse(contextBasic.getMutable().isMutable()); - assertTrue(javaIdMapping.getMutable().isMutable()); - } - - public void testModifyMutable() throws Exception { - OrmPersistentType ormPersistentType = - getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = - ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "basic"); - OrmEclipseLinkIdMapping contextId = - (OrmEclipseLinkIdMapping) ormPersistentAttribute.getMapping(); - XmlEntity resourceEntity = - (XmlEntity)getXmlEntityMappings().getEntities().get(0); - XmlId resourceId = - (XmlId) resourceEntity.getAttributes().getIds().get(0); - - // check defaults - - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - // set context mutable to true, check resource - - contextId.getMutable().setSpecifiedMutable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.TRUE, contextId.getMutable().getSpecifiedMutable()); - assertTrue(contextId.getMutable().isMutable()); - - // set context mutable to false, check resource - - contextId.getMutable().setSpecifiedMutable(Boolean.FALSE); - - assertEquals(Boolean.FALSE, resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertEquals(Boolean.FALSE, contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - - // set context read only to null, check resource - - contextId.getMutable().setSpecifiedMutable(null); - - assertNull(resourceId.getMutable()); - assertFalse(contextId.getMutable().isDefaultMutable()); - assertNull(contextId.getMutable().getSpecifiedMutable()); - assertFalse(contextId.getMutable().isMutable()); - } - - public void testUpdateConvert() throws Exception { - createTestEntityWithIdMapping(); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId basicResource = (XmlId) getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - JavaIdMapping javaIdMapping = (JavaIdMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(Converter.NO_CONVERTER, ormIdMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - - //set lob in the resource model, verify context model updated - basicResource.setConvert("myConvert"); - assertEquals(EclipseLinkConvert.ECLIPSE_LINK_CONVERTER, ormIdMapping.getConverter().getType()); - assertEquals("myConvert", basicResource.getConvert()); - - //set lob to null in the resource model - basicResource.setConvert(null); - assertEquals(Converter.NO_CONVERTER, ormIdMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - - - javaIdMapping.setConverter(EclipseLinkConvert.ECLIPSE_LINK_CONVERTER); - ((EclipseLinkConvert) javaIdMapping.getConverter()).setSpecifiedConverterName("foo"); - - assertEquals(Converter.NO_CONVERTER, ormIdMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - assertEquals("foo", ((EclipseLinkConvert) javaIdMapping.getConverter()).getSpecifiedConverterName()); - - - ormPersistentType.removeSpecifiedAttribute(ormPersistentAttribute); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("id"); - ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - - assertEquals(EclipseLinkConvert.ECLIPSE_LINK_CONVERTER, ormIdMapping.getConverter().getType()); - assertEquals("foo", ((EclipseLinkConvert) ormIdMapping.getConverter()).getSpecifiedConverterName()); - assertEquals(null, basicResource.getConvert()); - assertEquals("foo", ((EclipseLinkConvert) javaIdMapping.getConverter()).getSpecifiedConverterName()); - - ((EclipseLinkConvert) javaIdMapping.getConverter()).setSpecifiedConverterName("bar"); - assertEquals(EclipseLinkConvert.ECLIPSE_LINK_CONVERTER, ormIdMapping.getConverter().getType()); - assertEquals("bar", ((EclipseLinkConvert) ormIdMapping.getConverter()).getSpecifiedConverterName()); - assertEquals(null, basicResource.getConvert()); - assertEquals("bar", ((EclipseLinkConvert) javaIdMapping.getConverter()).getSpecifiedConverterName()); - - javaIdMapping.setConverter(Converter.NO_CONVERTER); - assertEquals(Converter.NO_CONVERTER, ormIdMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - assertEquals(Converter.NO_CONVERTER, javaIdMapping.getConverter().getType()); - } - - public void testModifyConvert() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId basicResource = (XmlId) getXmlEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertEquals(Converter.NO_CONVERTER, ormIdMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - - //set lob in the context model, verify resource model updated - ormIdMapping.setConverter(EclipseLinkConvert.ECLIPSE_LINK_CONVERTER); - assertEquals("", basicResource.getConvert()); - assertEquals(EclipseLinkConvert.ECLIPSE_LINK_CONVERTER, ormIdMapping.getConverter().getType()); - - ((EclipseLinkConvert) ormIdMapping.getConverter()).setSpecifiedConverterName("bar"); - assertEquals("bar", basicResource.getConvert()); - assertEquals(EclipseLinkConvert.ECLIPSE_LINK_CONVERTER, ormIdMapping.getConverter().getType()); - assertEquals("bar", ((EclipseLinkConvert) ormIdMapping.getConverter()).getSpecifiedConverterName()); - - ((EclipseLinkConvert) ormIdMapping.getConverter()).setSpecifiedConverterName(null); - - assertEquals(Converter.NO_CONVERTER, ormIdMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - - //set lob to false in the context model - ormIdMapping.setConverter(Converter.NO_CONVERTER); - assertEquals(Converter.NO_CONVERTER, ormIdMapping.getConverter().getType()); - assertEquals(null, basicResource.getConvert()); - } -} |