Search in sources :

Example 1 with MockDataNode

use of org.apache.cayenne.access.MockDataNode in project cayenne by apache.

the class CayenneDataObjectFlattenedRelIT method testAddRemoveFlattenedRelationship2.

@Test
public void testAddRemoveFlattenedRelationship2() throws Exception {
    create1Artist2ArtGroupDataSet();
    Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
    SelectQuery q = new SelectQuery(ArtGroup.class);
    List<?> results = context.performQuery(q);
    assertEquals(2, results.size());
    ArtGroup g1 = (ArtGroup) results.get(0);
    ArtGroup g2 = (ArtGroup) results.get(1);
    a1.addToGroupArray(g1);
    a1.addToGroupArray(g2);
    // test that there is no delete query issued when a flattened join is first
    // added and then deleted AND there are some other changes (CAY-548)
    a1.removeFromGroupArray(g1);
    MockDataNode nodeWrapper = MockDataNode.interceptNode(runtime.getDataDomain(), runtime.getDataDomain().getDataNodes().iterator().next());
    try {
        context.commitChanges();
    } finally {
        nodeWrapper.stopInterceptNode();
    }
    assertEquals(1, nodeWrapper.getRunCount());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SelectQuery(org.apache.cayenne.query.SelectQuery) MockDataNode(org.apache.cayenne.access.MockDataNode) ArtGroup(org.apache.cayenne.testdo.testmap.ArtGroup) Test(org.junit.Test)

Aggregations

MockDataNode (org.apache.cayenne.access.MockDataNode)1 SelectQuery (org.apache.cayenne.query.SelectQuery)1 ArtGroup (org.apache.cayenne.testdo.testmap.ArtGroup)1 Artist (org.apache.cayenne.testdo.testmap.Artist)1 Test (org.junit.Test)1