Search in sources :

Example 11 with PaintingInfo

use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.

the class CayenneDOTestBase method newPaintingInfo.

protected PaintingInfo newPaintingInfo() {
    PaintingInfo p1 = context.newObject(PaintingInfo.class);
    p1.setTextReview(textReview);
    p1.setImageBlob(paintingImage);
    return p1;
}
Also used : PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo)

Example 12 with PaintingInfo

use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.

the class DataContextDeleteRulesIT method testCascadeToOne.

@Test
public void testCascadeToOne() {
    // Painting toPaintingInfo
    Painting painting = (Painting) context.newObject("Painting");
    painting.setPaintingTitle("A Title");
    PaintingInfo info = (PaintingInfo) context.newObject("PaintingInfo");
    painting.setToPaintingInfo(info);
    // Must commit before deleting.. this relationship is dependent,
    // and everything must be committed for certain things to work
    context.commitChanges();
    context.deleteObjects(painting);
    // info must also be deleted
    assertEquals(PersistenceState.DELETED, info.getPersistenceState());
    assertNull(info.getPainting());
    assertNull(painting.getToPaintingInfo());
    context.commitChanges();
}
Also used : PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 13 with PaintingInfo

use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.

the class DataContextDisjointByIdPrefetchIT method testOneToOneRelationship.

@Test
public void testOneToOneRelationship() throws Exception {
    createTwoPaintingsWithInfosDataSet();
    SelectQuery query = new SelectQuery(Painting.class);
    query.addPrefetch(Painting.TO_PAINTING_INFO.disjointById());
    final List<Painting> result = context.performQuery(query);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertFalse(result.isEmpty());
            List<String> boxColors = new ArrayList<String>();
            for (Painting box : result) {
                PaintingInfo info = (PaintingInfo) box.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
                assertNotNull(info);
                boxColors.add(info.getTextReview());
                assertEquals(PersistenceState.COMMITTED, info.getPersistenceState());
            }
            assertTrue(boxColors.containsAll(Arrays.asList("red", "green")));
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ArrayList(java.util.ArrayList) List(java.util.List) PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 14 with PaintingInfo

use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.

the class CDOOne2OneDepIT method testNewAdd.

@Test
public void testNewAdd() throws Exception {
    Artist a1 = newArtist();
    PaintingInfo pi1 = newPaintingInfo();
    Painting p1 = newPainting();
    // needed to save without errors
    p1.setToArtist(a1);
    // *** TESTING THIS ***
    p1.setToPaintingInfo(pi1);
    // test before save
    assertSame(pi1, p1.getToPaintingInfo());
    assertSame(p1, pi1.getPainting());
    // do save
    context.commitChanges();
    context = context1;
    // test database data
    Painting p2 = fetchPainting();
    PaintingInfo pi2 = p2.getToPaintingInfo();
    assertNotNull(pi2);
    assertEquals(textReview, pi2.getTextReview());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 15 with PaintingInfo

use of org.apache.cayenne.testdo.testmap.PaintingInfo in project cayenne by apache.

the class CDOOne2OneDepIT method testTakeObjectSnapshotDependentFault.

@Test
public void testTakeObjectSnapshotDependentFault() throws Exception {
    // prepare data
    Artist a1 = newArtist();
    PaintingInfo pi1 = newPaintingInfo();
    Painting p1 = newPainting();
    p1.setToArtist(a1);
    p1.setToPaintingInfo(pi1);
    context.commitChanges();
    context = context1;
    Painting painting = fetchPainting();
    assertTrue(painting.readPropertyDirectly("toPaintingInfo") instanceof Fault);
    // test that taking a snapshot does not trigger a fault, and generally works well
    DataRow snapshot = ((DataContext) context).currentSnapshot(painting);
    assertEquals(paintingName, snapshot.get("PAINTING_TITLE"));
    assertTrue(painting.readPropertyDirectly("toPaintingInfo") instanceof Fault);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) DataContext(org.apache.cayenne.access.DataContext) PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Aggregations

PaintingInfo (org.apache.cayenne.testdo.testmap.PaintingInfo)15 Painting (org.apache.cayenne.testdo.testmap.Painting)14 Test (org.junit.Test)14 SelectQuery (org.apache.cayenne.query.SelectQuery)6 Artist (org.apache.cayenne.testdo.testmap.Artist)6 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)6 ByteArrayTypeTest (org.apache.cayenne.access.types.ByteArrayTypeTest)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ObjectContext (org.apache.cayenne.ObjectContext)1 DataContext (org.apache.cayenne.access.DataContext)1 Expression (org.apache.cayenne.exp.Expression)1