use of org.apache.cayenne.testdo.testmap.ArtGroup in project cayenne by apache.
the class CayenneDataObjectRelationshipsIT method testReflexiveRelationshipInsertOrder2.
@Test
public void testReflexiveRelationshipInsertOrder2() {
ArtGroup childGroup1 = context.newObject(ArtGroup.class);
childGroup1.setName("child1");
ArtGroup parentGroup = context.newObject(ArtGroup.class);
parentGroup.setName("parent");
childGroup1.setToParentGroup(parentGroup);
context.commitChanges();
childGroup1.setToParentGroup(null);
context.commitChanges();
}
use of org.apache.cayenne.testdo.testmap.ArtGroup in project cayenne by apache.
the class CayenneDataObjectRelationshipsIT method testReflexiveRelationshipInsertOrder3.
@Test
public void testReflexiveRelationshipInsertOrder3() {
// multiple children, one created before parent, one after
ArtGroup childGroup1 = context.newObject(ArtGroup.class);
childGroup1.setName("child1");
ArtGroup parentGroup = context.newObject(ArtGroup.class);
parentGroup.setName("parent");
childGroup1.setToParentGroup(parentGroup);
ArtGroup childGroup2 = context.newObject(ArtGroup.class);
childGroup2.setName("child2");
childGroup2.setToParentGroup(parentGroup);
context.commitChanges();
childGroup1.setToParentGroup(null);
context.commitChanges();
childGroup2.setToParentGroup(null);
context.commitChanges();
}
use of org.apache.cayenne.testdo.testmap.ArtGroup in project cayenne by apache.
the class DataContextDeleteRulesIT method testNullifyToMany.
@Test
public void testNullifyToMany() {
// ArtGroup childGroupsArray
ArtGroup parentGroup = (ArtGroup) context.newObject("ArtGroup");
parentGroup.setName("Parent");
ArtGroup childGroup = (ArtGroup) context.newObject("ArtGroup");
childGroup.setName("Child");
parentGroup.addToChildGroupsArray(childGroup);
// Preconditions - good to check to be sure
assertEquals(parentGroup, childGroup.getToParentGroup());
assertTrue(parentGroup.getChildGroupsArray().contains(childGroup));
context.commitChanges();
context.deleteObjects(parentGroup);
// The things we are testing.
assertNull(childGroup.getToParentGroup());
// Although deleted, the property should be null (good cleanup policy)
// assertFalse(parentGroup.getChildGroupsArray().contains(childGroup));
context.commitChanges();
}
use of org.apache.cayenne.testdo.testmap.ArtGroup in project cayenne by apache.
the class DataContextDeleteRulesIT method testCascadeToManyFlattened.
/**
* Tests that deleting a source of a flattened relationship with CASCADE
* rule results in deleting a join and a target.
*/
@Test
public void testCascadeToManyFlattened() {
// testing Artist.groupArray relationship
ArtGroup aGroup = context.newObject(ArtGroup.class);
aGroup.setName("Group Name");
Artist anArtist = context.newObject(Artist.class);
anArtist.setArtistName("A Name");
anArtist.addToGroupArray(aGroup);
assertTrue(anArtist.getGroupArray().contains(aGroup));
context.commitChanges();
SQLTemplate checkQuery = new SQLTemplate(Artist.class, "SELECT * FROM ARTIST_GROUP");
checkQuery.setFetchingDataRows(true);
List<?> joins1 = context.performQuery(checkQuery);
assertEquals(1, joins1.size());
context.deleteObjects(anArtist);
assertEquals(PersistenceState.DELETED, aGroup.getPersistenceState());
assertFalse(anArtist.getGroupArray().contains(aGroup));
context.commitChanges();
List<?> joins2 = context.performQuery(checkQuery);
assertEquals(0, joins2.size());
}
Aggregations