Search in sources :

Example 1 with FP2Base

use of org.datanucleus.samples.fetchplan.FP2Base in project tests by datanucleus.

the class FetchPlanTest method testDetachmentRoots.

/**
 * Test the detachment roots
 */
public void testDetachmentRoots() {
    FetchPlan fp = getFetchPlan();
    FP2Base baseObj = new FP2Base();
    assertEquals(0, fp.getDetachmentRoots().size());
    // verify immutable
    try {
        fp.getDetachmentRoots().add(baseObj);
        fail("exception UnsupportedOperationException");
    } catch (UnsupportedOperationException ex) {
    // expected
    }
    List<Object> elms = new ArrayList<>();
    elms.add(baseObj);
    fp.setDetachmentRoots(elms);
    assertEquals(1, fp.getDetachmentRoots().size());
    // verify if immutable by changing original collection
    FP2Base baseObj2 = new FP2Base();
    elms.add(baseObj2);
    assertEquals(1, fp.getDetachmentRoots().size());
    // verify immutable after setting roots
    try {
        fp.getDetachmentRoots().add(baseObj);
        fail("exception UnsupportedOperationException");
    } catch (UnsupportedOperationException ex) {
    // expected
    }
}
Also used : ArrayList(java.util.ArrayList) FetchPlan(org.datanucleus.FetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan) FP2Base(org.datanucleus.samples.fetchplan.FP2Base)

Aggregations

ArrayList (java.util.ArrayList)1 FetchPlan (org.datanucleus.FetchPlan)1 JDOFetchPlan (org.datanucleus.api.jdo.JDOFetchPlan)1 FP2Base (org.datanucleus.samples.fetchplan.FP2Base)1