blob: 41e6ae911219504cc340497371ce1dbbadecc4b0 [file] [log] [blame]
/*******************************************************************************
* 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.orm;
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.jpa2.context.OneToManyMapping2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmOneToManyMapping2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovable2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmOrphanRemovalHolder2_0;
import org.eclipse.jpt.core.resource.orm.XmlOneToMany;
/**
* EclipseLink2_0OrmOneToManyMappingTests
*/
public class EclipseLink2_0OrmOneToManyMappingTests
extends EclipseLink2_0OrmContextModelTestCase
{
public EclipseLink2_0OrmOneToManyMappingTests(String name) {
super(name);
}
private OrmOrphanRemovable2_0 getOrphanRemovalOf(OneToManyMapping2_0 oneToManyMapping) {
return ((OrmOrphanRemovalHolder2_0) oneToManyMapping).getOrphanRemoval();
}
public void testUpdateSpecifiedOrphanRemoval() throws Exception {
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping");
OrmOneToManyMapping2_0 oneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping();
OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping);
XmlOneToMany oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0);
assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval());
assertEquals(null, oneToManyResource.getOrphanRemoval());
//set enumerated in the resource model, verify context model updated
oneToManyResource.setOrphanRemoval(Boolean.TRUE);
assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval());
assertEquals(Boolean.TRUE, oneToManyResource.getOrphanRemoval());
oneToManyResource.setOrphanRemoval(Boolean.FALSE);
assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval());
assertEquals(Boolean.FALSE, oneToManyResource.getOrphanRemoval());
}
public void testModifySpecifiedOrphanRemoval() throws Exception {
OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo");
OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping");
OrmOneToManyMapping2_0 oneToManyMapping = (OrmOneToManyMapping2_0) ormPersistentAttribute.getMapping();
OrmOrphanRemovable2_0 mappingsOrphanRemoval = this.getOrphanRemovalOf(oneToManyMapping);
XmlOneToMany oneToManyResource = getXmlEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0);
assertEquals(null, mappingsOrphanRemoval.getSpecifiedOrphanRemoval());
assertEquals(null, oneToManyResource.getOrphanRemoval());
//set enumerated in the context model, verify resource model updated
mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.TRUE);
assertEquals(Boolean.TRUE, oneToManyResource.getOrphanRemoval());
assertEquals(Boolean.TRUE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval());
mappingsOrphanRemoval.setSpecifiedOrphanRemoval(Boolean.FALSE);
assertEquals(Boolean.FALSE, oneToManyResource.getOrphanRemoval());
assertEquals(Boolean.FALSE, mappingsOrphanRemoval.getSpecifiedOrphanRemoval());
}
}