| /******************************************************************************* |
| * Copyright (c) 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.eclipselink2_0.core.tests.internal.context.java; |
| |
| import java.util.Iterator; |
| |
| import org.eclipse.jdt.core.ICompilationUnit; |
| import org.eclipse.jpt.core.MappingKeys; |
| import org.eclipse.jpt.core.context.AttributeMapping; |
| import org.eclipse.jpt.core.context.OneToOneMapping; |
| import org.eclipse.jpt.core.context.PersistentAttribute; |
| import org.eclipse.jpt.core.context.java.JavaBasicMapping; |
| import org.eclipse.jpt.core.context.java.JavaIdMapping; |
| import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; |
| import org.eclipse.jpt.core.context.java.JavaPersistentType; |
| import org.eclipse.jpt.core.jpa2.context.OneToOneMapping2_0; |
| import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneMapping2_0; |
| import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0; |
| import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; |
| import org.eclipse.jpt.core.jpa2.resource.java.MapsId2_0Annotation; |
| import org.eclipse.jpt.core.jpa2.resource.java.OneToOne2_0Annotation; |
| import org.eclipse.jpt.core.resource.java.JPA; |
| import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; |
| import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; |
| import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; |
| import org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.EclipseLink2_0ContextModelTestCase; |
| import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; |
| |
| @SuppressWarnings("nls") |
| public class EclipseLink2_0JavaOneToOneMappingTests |
| extends EclipseLink2_0ContextModelTestCase |
| { |
| public EclipseLink2_0JavaOneToOneMappingTests(String name) { |
| super(name); |
| } |
| |
| |
| private void createTestEntity() throws Exception { |
| 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"); |
| sb.append(CR); |
| } |
| |
| @Override |
| public void appendIdFieldAnnotationTo(StringBuilder sb) { |
| sb.append(CR); |
| sb.append(" @OneToOne"); |
| sb.append(CR); |
| sb.append(" private Address address;"); |
| sb.append(CR); |
| sb.append(CR); |
| sb.append(" @Id"); |
| } |
| }); |
| } |
| |
| private void createTestEntityWithValidOneToOneMappingOrphanRemovalSpecified() throws Exception { |
| 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"); |
| sb.append(CR); |
| } |
| |
| @Override |
| public void appendIdFieldAnnotationTo(StringBuilder sb) { |
| sb.append(CR); |
| sb.append(" @OneToOne(orphanRemoval=false)"); |
| sb.append(CR); |
| sb.append(" private Address address;"); |
| sb.append(CR); |
| sb.append(CR); |
| sb.append(" @Id"); |
| } |
| }); |
| } |
| |
| private ICompilationUnit createTestEntityWithDerivedId() throws Exception { |
| return this.createTestType(new DefaultAnnotationWriter() { |
| @Override |
| public Iterator<String> imports() { |
| return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); |
| } |
| @Override |
| public void appendTypeAnnotationTo(StringBuilder sb) { |
| sb.append("@Entity").append(CR); |
| } |
| |
| @Override |
| public void appendIdFieldAnnotationTo(StringBuilder sb) { |
| sb.append(CR); |
| sb.append(" @OneToOne @Id").append(CR); |
| sb.append(" private " + TYPE_NAME + " oneToOne;").append(CR); |
| sb.append(CR); |
| } |
| }); |
| } |
| |
| private ICompilationUnit createTestEntityWithValidOneToOneMapping() throws Exception { |
| return this.createTestType(new DefaultAnnotationWriter() { |
| @Override |
| public Iterator<String> imports() { |
| return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); |
| } |
| @Override |
| public void appendTypeAnnotationTo(StringBuilder sb) { |
| sb.append("@Entity").append(CR); |
| } |
| |
| @Override |
| public void appendIdFieldAnnotationTo(StringBuilder sb) { |
| sb.append(CR); |
| sb.append(" @OneToOne").append(CR); |
| sb.append(" private Address address;").append(CR); |
| sb.append(CR); |
| sb.append(" @Id").append(CR); |
| } |
| }); |
| } |
| |
| private void createTestTargetEntityAddress() throws Exception { |
| SourceWriter sourceWriter = new SourceWriter() { |
| public void appendSourceTo(StringBuilder sb) { |
| sb.append(CR); |
| sb.append("import "); |
| sb.append(JPA.ENTITY); |
| sb.append(";"); |
| sb.append(CR); |
| sb.append("import "); |
| sb.append(JPA.ID); |
| sb.append(";"); |
| sb.append(CR); |
| sb.append("import "); |
| sb.append(JPA.EMBEDDED); |
| sb.append(";"); |
| sb.append(CR); |
| sb.append("@Entity"); |
| sb.append(CR); |
| sb.append("public class ").append("Address").append(" "); |
| sb.append("{").append(CR); |
| sb.append(CR); |
| sb.append(" @Id").append(CR); |
| sb.append(" private int id;").append(CR); |
| sb.append(CR); |
| sb.append(" private String city;").append(CR); |
| sb.append(CR); |
| sb.append(" @Embedded").append(CR); |
| sb.append(" private State state;").append(CR); |
| sb.append(CR); |
| sb.append(" private int zip;").append(CR); |
| sb.append(CR); |
| sb.append("}").append(CR); |
| } |
| }; |
| this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); |
| } |
| |
| private void createTestEmbeddableState() throws Exception { |
| SourceWriter sourceWriter = new SourceWriter() { |
| public void appendSourceTo(StringBuilder sb) { |
| sb.append(CR); |
| sb.append("import "); |
| sb.append(JPA.EMBEDDABLE); |
| sb.append(";"); |
| sb.append(CR); |
| sb.append("@Embeddable"); |
| sb.append(CR); |
| sb.append("public class ").append("State").append(" "); |
| sb.append("{").append(CR); |
| sb.append(CR); |
| sb.append(" private String foo;").append(CR); |
| sb.append(CR); |
| sb.append(" private Address address;").append(CR); |
| sb.append(CR); |
| sb.append("}").append(CR); |
| } |
| }; |
| this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter); |
| } |
| |
| public void testUpdateDerivedId() throws Exception { |
| createTestEntityWithDerivedId(); |
| addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentType resourceType = |
| getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); |
| JavaPersistentType contextType = getJavaPersistentType(); |
| JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); |
| JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); |
| |
| assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); |
| assertTrue(contextMapping.getDerivedId().getValue()); |
| |
| resourceAttribute.removeAnnotation(JPA.ID); |
| assertNull(resourceAttribute.getAnnotation(JPA.ID)); |
| assertFalse(contextMapping.getDerivedId().getValue()); |
| |
| resourceAttribute.addAnnotation(JPA.ID); |
| assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); |
| assertTrue(contextMapping.getDerivedId().getValue()); |
| } |
| |
| public void testSetDerivedId() throws Exception { |
| createTestEntityWithDerivedId(); |
| addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentType resourceType = |
| getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); |
| JavaPersistentType contextType = getJavaPersistentType(); |
| JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); |
| JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); |
| |
| assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); |
| assertTrue(contextMapping.getDerivedId().getValue()); |
| |
| contextMapping.getDerivedId().setValue(false); |
| assertNull(resourceAttribute.getAnnotation(JPA.ID)); |
| assertFalse(contextMapping.getDerivedId().getValue()); |
| |
| contextMapping.getDerivedId().setValue(true); |
| assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); |
| assertTrue(contextMapping.getDerivedId().getValue()); |
| } |
| |
| public void testUpdateMapsId() throws Exception { |
| createTestEntity(); |
| addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentType resourceType = |
| getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); |
| JavaPersistentType contextType = getJavaPersistentType(); |
| JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("address"); |
| JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); |
| |
| assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); |
| assertNull(contextMapping.getMapsId().getValue()); |
| |
| MapsId2_0Annotation annotation = |
| (MapsId2_0Annotation) resourceAttribute.addAnnotation(JPA2_0.MAPS_ID); |
| annotation.setValue("foo"); |
| assertEquals("foo", annotation.getValue()); |
| assertEquals("foo", contextMapping.getMapsId().getValue()); |
| |
| annotation.setValue("bar"); |
| assertEquals("bar", annotation.getValue()); |
| assertEquals("bar", contextMapping.getMapsId().getValue()); |
| |
| resourceAttribute.removeAnnotation(JPA2_0.MAPS_ID); |
| assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); |
| assertNull(contextMapping.getMapsId().getValue()); |
| } |
| |
| public void testSetMapsId() throws Exception { |
| createTestEntity(); |
| addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentType resourceType = |
| getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); |
| JavaPersistentType contextType = getJavaPersistentType(); |
| JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("address"); |
| JavaOneToOneMapping2_0 contextMapping = (JavaOneToOneMapping2_0) contextAttribute.getMapping(); |
| |
| assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); |
| assertNull(contextMapping.getMapsId().getValue()); |
| |
| contextMapping.getMapsId().setValue("foo"); |
| MapsId2_0Annotation annotation = |
| (MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID); |
| assertNotNull(annotation); |
| assertEquals("foo", annotation.getValue()); |
| assertEquals("foo", contextMapping.getMapsId().getValue()); |
| |
| contextMapping.getMapsId().setValue("bar"); |
| assertEquals("bar", annotation.getValue()); |
| assertEquals("bar", contextMapping.getMapsId().getValue()); |
| |
| contextMapping.getMapsId().setValue(null); |
| assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); |
| assertNull(contextMapping.getMapsId().getValue()); |
| } |
| |
| public void testMorphMapping() throws Exception { |
| createTestEntityWithDerivedId(); |
| addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentType resourceType = |
| getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentAttribute resourceAttribute = resourceType.persistableAttributes().next(); |
| JavaPersistentType contextType = getJavaPersistentType(); |
| JavaPersistentAttribute contextAttribute = contextType.getAttributeNamed("oneToOne"); |
| |
| ((MapsId2_0Annotation) resourceAttribute.addAnnotation(JPA2_0.MAPS_ID)).setValue("foo"); |
| assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); |
| assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); |
| assertEquals("foo", ((MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)).getValue()); |
| assertTrue(((JavaOneToOneMapping2_0) contextAttribute.getMapping()).getDerivedId().getValue()); |
| |
| contextAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); |
| assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); |
| assertNotNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); |
| assertEquals("foo", ((MapsId2_0Annotation) resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)).getValue()); |
| assertTrue(((JavaManyToOneMapping2_0) contextAttribute.getMapping()).getDerivedId().getValue()); |
| |
| contextAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); |
| assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); |
| assertNull(resourceAttribute.getAnnotation(JPA2_0.MAPS_ID)); |
| assertTrue(contextAttribute.getMapping() instanceof JavaIdMapping); |
| |
| contextAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); |
| assertNotNull(resourceAttribute.getAnnotation(JPA.ID)); |
| assertTrue(((JavaOneToOneMapping2_0) contextAttribute.getMapping()).getDerivedId().getValue()); |
| |
| contextAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); |
| assertNull(resourceAttribute.getAnnotation(JPA.ID)); |
| assertTrue(contextAttribute.getMapping() instanceof JavaBasicMapping); |
| } |
| |
| |
| public void testCandidateMappedByAttributeNames() throws Exception { |
| createTestEntityWithValidOneToOneMapping(); |
| createTestTargetEntityAddress(); |
| createTestEmbeddableState(); |
| addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| addXmlClassRef(PACKAGE_NAME + ".Address"); |
| addXmlClassRef(PACKAGE_NAME + ".State"); |
| |
| PersistentAttribute persistentAttribute = (getJavaPersistentType()).attributes().next(); |
| OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); |
| |
| Iterator<String> attributeNames = |
| oneToOneMapping.getRelationshipReference().getMappedByJoiningStrategy().candidateMappedByAttributeNames(); |
| assertEquals("id", attributeNames.next()); |
| assertEquals("city", attributeNames.next()); |
| assertEquals("state", attributeNames.next()); |
| assertEquals("state.foo", attributeNames.next()); |
| assertEquals("state.address", attributeNames.next()); |
| assertEquals("zip", attributeNames.next()); |
| assertFalse(attributeNames.hasNext()); |
| |
| oneToOneMapping.setSpecifiedTargetEntity("foo"); |
| attributeNames = |
| oneToOneMapping.getRelationshipReference().getMappedByJoiningStrategy().candidateMappedByAttributeNames(); |
| assertFalse(attributeNames.hasNext()); |
| |
| oneToOneMapping.setSpecifiedTargetEntity(null); |
| attributeNames = |
| oneToOneMapping.getRelationshipReference().getMappedByJoiningStrategy().candidateMappedByAttributeNames(); |
| assertEquals("id", attributeNames.next()); |
| assertEquals("city", attributeNames.next()); |
| assertEquals("state", attributeNames.next()); |
| assertEquals("state.foo", attributeNames.next()); |
| assertEquals("state.address", attributeNames.next()); |
| assertEquals("zip", attributeNames.next()); |
| assertFalse(attributeNames.hasNext()); |
| |
| AttributeMapping stateFooMapping = oneToOneMapping.getResolvedTargetEntity().resolveAttributeMapping("state.foo"); |
| assertEquals("foo", stateFooMapping.getName()); |
| } |
| |
| public void testDefaultOneToOneGetDefaultOrphanRemoval() throws Exception { |
| this.createTestEntity(); |
| this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| |
| PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); |
| OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); |
| assertEquals(false, oneToOneMapping.isDefaultOrphanRemoval()); |
| } |
| |
| public void testSpecifiedOneToOneGetDefaultOrphanRemoval() throws Exception { |
| this.createTestEntity(); |
| this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| |
| PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); |
| OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getSpecifiedMapping(); |
| assertEquals(false, oneToOneMapping.isDefaultOrphanRemoval()); |
| } |
| |
| public void testGetOrphanRemoval() throws Exception { |
| this.createTestEntity(); |
| this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| |
| PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); |
| OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getSpecifiedMapping(); |
| |
| assertEquals(false, oneToOneMapping.isOrphanRemoval()); |
| |
| oneToOneMapping.setSpecifiedOrphanRemoval(Boolean.TRUE); |
| assertEquals(true, oneToOneMapping.isOrphanRemoval()); |
| } |
| |
| public void testGetSpecifiedOrphanRemoval() throws Exception { |
| this.createTestEntity(); |
| this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| |
| PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); |
| OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getSpecifiedMapping(); |
| |
| assertNull(oneToOneMapping.getSpecifiedOrphanRemoval()); |
| |
| JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); |
| OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); |
| oneToOne.setOrphanRemoval(Boolean.FALSE); |
| |
| assertEquals(Boolean.FALSE, oneToOneMapping.getSpecifiedOrphanRemoval()); |
| } |
| |
| public void testGetSpecifiedOrphanRemoval2() throws Exception { |
| this.createTestEntityWithValidOneToOneMappingOrphanRemovalSpecified(); |
| this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| |
| PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); |
| OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getSpecifiedMapping(); |
| |
| assertEquals(Boolean.FALSE, oneToOneMapping.getSpecifiedOrphanRemoval()); |
| } |
| |
| public void testSetSpecifiedOrphanRemoval() throws Exception { |
| this.createTestEntity(); |
| this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| |
| PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); |
| OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); |
| assertNull(oneToOneMapping.getSpecifiedOrphanRemoval()); |
| |
| oneToOneMapping.setSpecifiedOrphanRemoval(Boolean.TRUE); |
| |
| JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); |
| OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); |
| |
| assertEquals(Boolean.TRUE, oneToOne.getOrphanRemoval()); |
| |
| oneToOneMapping.setSpecifiedOrphanRemoval(null); |
| assertNotNull(attributeResource.getAnnotation(JPA.ONE_TO_ONE)); // .getElement); |
| } |
| |
| public void testSetSpecifiedOrphanRemoval2() throws Exception { |
| this.createTestEntity(); |
| this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| |
| PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); |
| OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); |
| assertNull(oneToOneMapping.getSpecifiedOrphanRemoval()); |
| |
| oneToOneMapping.setSpecifiedOrphanRemoval(Boolean.TRUE); |
| |
| JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); |
| OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); |
| |
| assertEquals(Boolean.TRUE, oneToOne.getOrphanRemoval()); |
| |
| oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); |
| assertEquals(Boolean.TRUE, oneToOneMapping.getSpecifiedOrphanRemoval()); |
| |
| oneToOneMapping.setSpecifiedOrphanRemoval(null); |
| assertNotNull(attributeResource.getAnnotation(JPA.ONE_TO_ONE)); |
| |
| oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getMapping(); |
| } |
| |
| public void testGetSpecifiedOrphanRemovalUpdatesFromResourceModelChange() throws Exception { |
| this.createTestEntity(); |
| this.addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); |
| |
| PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); |
| OneToOneMapping2_0 oneToOneMapping = (OneToOneMapping2_0) persistentAttribute.getSpecifiedMapping(); |
| |
| assertNull(oneToOneMapping.getSpecifiedOrphanRemoval()); |
| |
| JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); |
| JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); |
| OneToOne2_0Annotation oneToOne = (OneToOne2_0Annotation) attributeResource.getAnnotation(JPA.ONE_TO_ONE); |
| oneToOne.setOrphanRemoval(Boolean.FALSE); |
| |
| assertEquals(Boolean.FALSE, oneToOneMapping.getSpecifiedOrphanRemoval()); |
| |
| oneToOne.setOrphanRemoval(null); |
| assertNull(oneToOneMapping.getSpecifiedOrphanRemoval()); |
| assertSame(oneToOneMapping, persistentAttribute.getSpecifiedMapping()); |
| |
| oneToOne.setOrphanRemoval(Boolean.FALSE); |
| attributeResource.setPrimaryAnnotation(null, new String[0]); |
| |
| assertNull(persistentAttribute.getSpecifiedMapping()); |
| } |
| |
| } |