use of org.apache.cayenne.testdo.testmap.ArtGroup in project cayenne by apache.
the class CayenneDataObjectFlattenedRelIT method testAddRemoveFlattenedRelationship1.
@Test
public void testAddRemoveFlattenedRelationship1() throws Exception {
create1Artist1ArtGroupDataSet();
Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp("name", "g1"));
List<?> results = context.performQuery(q);
assertEquals(1, results.size());
ArtGroup group = (ArtGroup) results.get(0);
a1.addToGroupArray(group);
group.removeFromArtistArray(a1);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
context.commitChanges();
}
});
}
use of org.apache.cayenne.testdo.testmap.ArtGroup in project cayenne by apache.
the class CayenneDataObjectFlattenedRelIT method testRemoveFlattenedRelationshipAndRootRecord.
// Demonstrates a possible bug in ordering of deletes, when a flattened relationships
// link record is deleted at the same time (same transaction) as one of the record to
// which it links.
@Test
public void testRemoveFlattenedRelationshipAndRootRecord() throws Exception {
create1Artist1ArtGroup1ArtistGroupDataSet();
Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
ArtGroup group = a1.getGroupArray().get(0);
// Cause the delete of the link record
a1.removeFromGroupArray(group);
// Cause the deletion of the artist
context.deleteObjects(a1);
try {
context.commitChanges();
} catch (Exception e) {
e.printStackTrace();
fail("Should not have thrown the exception :" + e.getMessage());
}
}
use of org.apache.cayenne.testdo.testmap.ArtGroup in project cayenne by apache.
the class CayenneDataObjectFlattenedRelIT method testReadFlattenedRelationship.
@Test
public void testReadFlattenedRelationship() throws Exception {
create1Artist1ArtGroupDataSet();
Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
List<ArtGroup> groupList = a1.getGroupArray();
assertNotNull(groupList);
assertEquals(0, groupList.size());
}
use of org.apache.cayenne.testdo.testmap.ArtGroup in project cayenne by apache.
the class CayenneDataObjectFlattenedRelIT method testDoubleCommitAddToFlattenedRelationship.
// Test case to show up a bug in committing more than once
@Test
public void testDoubleCommitAddToFlattenedRelationship() throws Exception {
create1Artist1ArtGroupDataSet();
Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp("name", "g1"));
List<?> results = context.performQuery(q);
assertEquals(1, results.size());
ArtGroup group = (ArtGroup) results.get(0);
a1.addToGroupArray(group);
List<?> groupList = a1.getGroupArray();
assertEquals(1, groupList.size());
assertEquals("g1", ((ArtGroup) groupList.get(0)).getName());
// Ensure that the commit doesn't fail
a1.getObjectContext().commitChanges();
try {
// The bug caused the second commit to fail (the link record
// was inserted again)
a1.getObjectContext().commitChanges();
} catch (Exception e) {
e.printStackTrace();
fail("Should not have thrown an exception");
}
}
use of org.apache.cayenne.testdo.testmap.ArtGroup in project cayenne by apache.
the class CayenneDataObjectRelationshipsIT method testReflexiveRelationshipInsertOrder4.
@Test
public void testReflexiveRelationshipInsertOrder4() {
// 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("subchild");
childGroup2.setToParentGroup(childGroup1);
context.commitChanges();
childGroup1.setToParentGroup(null);
context.commitChanges();
childGroup2.setToParentGroup(null);
context.commitChanges();
}
Aggregations