use of org.apache.cayenne.testdo.relationships_collection_to_many.CollectionToManyTarget in project cayenne by apache.
the class CDOCollectionRelationshipIT method testAddToMany.
@Test
public void testAddToMany() throws Exception {
CollectionToMany o1 = Cayenne.objectForPK(context, CollectionToMany.class, 1);
Collection<?> targets = o1.getTargets();
assertNotNull(targets);
assertEquals(3, targets.size());
CollectionToManyTarget newTarget = o1.getObjectContext().newObject(CollectionToManyTarget.class);
o1.addToTargets(newTarget);
assertEquals(4, targets.size());
assertTrue(o1.getTargets().contains(newTarget));
assertSame(o1, newTarget.getCollectionToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(4, o1.getTargets().size());
}
use of org.apache.cayenne.testdo.relationships_collection_to_many.CollectionToManyTarget in project cayenne by apache.
the class CDOCollectionRelationshipIT method testAddToManyViaReverse.
@Test
public void testAddToManyViaReverse() throws Exception {
CollectionToMany o1 = Cayenne.objectForPK(context, CollectionToMany.class, 1);
Collection<?> targets = o1.getTargets();
assertNotNull(targets);
assertEquals(3, targets.size());
CollectionToManyTarget newTarget = o1.getObjectContext().newObject(CollectionToManyTarget.class);
newTarget.setCollectionToMany(o1);
assertEquals(4, targets.size());
assertTrue(o1.getTargets().contains(newTarget));
assertSame(o1, newTarget.getCollectionToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(4, o1.getTargets().size());
}
use of org.apache.cayenne.testdo.relationships_collection_to_many.CollectionToManyTarget in project cayenne by apache.
the class CDOCollectionRelationshipIT method testRemoveToMany.
@Test
public void testRemoveToMany() throws Exception {
CollectionToMany o1 = Cayenne.objectForPK(context, CollectionToMany.class, 1);
Collection<?> targets = o1.getTargets();
assertEquals(3, targets.size());
CollectionToManyTarget target = Cayenne.objectForPK(o1.getObjectContext(), CollectionToManyTarget.class, 2);
o1.removeFromTargets(target);
assertEquals(2, targets.size());
assertFalse(o1.getTargets().contains(target));
assertNull(target.getCollectionToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(2, o1.getTargets().size());
assertFalse(o1.getTargets().contains(target));
}
Aggregations