use of org.apache.cayenne.testdo.relationships_set_to_many.SetToManyTarget in project cayenne by apache.
the class CDOSetRelationshipIT method testAddToMany.
@Test
public void testAddToMany() throws Exception {
createTestDataSet();
SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
Set targets = o1.getTargets();
assertNotNull(targets);
assertEquals(3, targets.size());
SetToManyTarget newTarget = o1.getObjectContext().newObject(SetToManyTarget.class);
o1.addToTargets(newTarget);
assertEquals(4, targets.size());
assertTrue(o1.getTargets().contains(newTarget));
assertSame(o1, newTarget.getSetToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(4, o1.getTargets().size());
}
use of org.apache.cayenne.testdo.relationships_set_to_many.SetToManyTarget in project cayenne by apache.
the class CDOSetRelationshipIT method testRemoveToMany.
@Test
public void testRemoveToMany() throws Exception {
createTestDataSet();
SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
Set targets = o1.getTargets();
assertEquals(3, targets.size());
SetToManyTarget target = Cayenne.objectForPK(o1.getObjectContext(), SetToManyTarget.class, 2);
o1.removeFromTargets(target);
assertEquals(2, targets.size());
assertFalse(o1.getTargets().contains(target));
assertNull(target.getSetToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(2, o1.getTargets().size());
assertFalse(o1.getTargets().contains(target));
}
use of org.apache.cayenne.testdo.relationships_set_to_many.SetToManyTarget in project cayenne by apache.
the class CDOSetRelationshipIT method testAddToManyViaReverse.
@Test
public void testAddToManyViaReverse() throws Exception {
createTestDataSet();
SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
Set targets = o1.getTargets();
assertNotNull(targets);
assertEquals(3, targets.size());
SetToManyTarget newTarget = o1.getObjectContext().newObject(SetToManyTarget.class);
newTarget.setSetToMany(o1);
assertEquals(4, targets.size());
assertTrue(o1.getTargets().contains(newTarget));
assertSame(o1, newTarget.getSetToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(4, o1.getTargets().size());
}
Aggregations