Search in sources :

Example 1 with ToOneFK2

use of org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2 in project cayenne by apache.

the class CDOOneToOneFKIT method testTakeObjectSnapshotDependentFault.

@Test
public void testTakeObjectSnapshotDependentFault() throws Exception {
    ToOneFK2 src = context.newObject(ToOneFK2.class);
    ToOneFK1 target = context.newObject(ToOneFK1.class);
    src.setToOneToFK(target);
    context.commitChanges();
    ObjectIdQuery refetch = new ObjectIdQuery(src.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
    ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
    assertTrue(src2.readPropertyDirectly("toOneToFK") instanceof Fault);
    // test that taking a snapshot does not trigger a fault, and generally works well
    context.currentSnapshot(src2);
    assertTrue(src2.readPropertyDirectly("toOneToFK") instanceof Fault);
}
Also used : ToOneFK2(org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2) ToOneFK1(org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK1) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 2 with ToOneFK2

use of org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2 in project cayenne by apache.

the class CDOOneToOneFKIT method testDelete.

@Test
public void testDelete() throws Exception {
    ToOneFK2 src = context.newObject(ToOneFK2.class);
    ToOneFK1 target = context.newObject(ToOneFK1.class);
    src.setToOneToFK(target);
    context.commitChanges();
    src.setToOneToFK(null);
    context.deleteObjects(target);
    context.commitChanges();
    // test database data
    ObjectIdQuery refetch = new ObjectIdQuery(src.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
    ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
    assertNull(src.getToOneToFK());
    assertEquals(src.getObjectId(), src2.getObjectId());
}
Also used : ToOneFK2(org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2) ToOneFK1(org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK1) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 3 with ToOneFK2

use of org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2 in project cayenne by apache.

the class CDOOneToOneFKIT method test2Null.

@Test
public void test2Null() throws Exception {
    ToOneFK2 src = context.newObject(ToOneFK2.class);
    context.commitChanges();
    // test database data
    ObjectIdQuery refetch = new ObjectIdQuery(src.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
    ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
    // *** TESTING THIS ***
    assertNull(src2.getToOneToFK());
}
Also used : ToOneFK2(org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 4 with ToOneFK2

use of org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2 in project cayenne by apache.

the class CDOOneToOneFKIT method testReplaceNull1.

@Test
public void testReplaceNull1() throws Exception {
    ToOneFK2 src = context.newObject(ToOneFK2.class);
    context.commitChanges();
    // test database data
    ObjectIdQuery refetch = new ObjectIdQuery(src.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
    ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
    assertEquals(src.getObjectId(), src2.getObjectId());
    // *** TESTING THIS ***
    src2.setToOneToFK(null);
    assertNull(src2.getToOneToFK());
}
Also used : ToOneFK2(org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 5 with ToOneFK2

use of org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2 in project cayenne by apache.

the class CDOOneToOneFKIT method testReplaceNull2.

@Test
public void testReplaceNull2() throws Exception {
    ToOneFK2 src = context.newObject(ToOneFK2.class);
    context.commitChanges();
    ToOneFK1 target = context.newObject(ToOneFK1.class);
    // *** TESTING THIS ***
    src.setToOneToFK(target);
    // test before save
    assertSame(target, src.getToOneToFK());
    // do save
    context.commitChanges();
    // test database data
    ObjectIdQuery refetch = new ObjectIdQuery(src.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
    ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
    ToOneFK1 target2 = src2.getToOneToFK();
    assertNotNull(target2);
    assertEquals(src.getObjectId(), src2.getObjectId());
    assertEquals(target.getObjectId(), target2.getObjectId());
}
Also used : ToOneFK2(org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2) ToOneFK1(org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK1) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Aggregations

ToOneFK2 (org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2)7 Test (org.junit.Test)7 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)6 ToOneFK1 (org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK1)5