Search in sources :

Example 6 with PaintingInfo

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

the class CDOOne2OneDepIT method testRollbackDependent.

@Test
public void testRollbackDependent() {
    Artist a1 = newArtist();
    Painting p1 = newPainting();
    // needed to save without errors
    p1.setToArtist(a1);
    context.commitChanges();
    PaintingInfo info = context.newObject(PaintingInfo.class);
    info.setTextReview("XXX");
    p1.setToPaintingInfo(info);
    assertSame(info, p1.getToPaintingInfo());
    context.rollbackChanges();
    assertNull(p1.getToPaintingInfo());
}
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 7 with PaintingInfo

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

the class CDOOneDep2OneIT method testNewAdd1.

@Test
public void testNewAdd1() throws Exception {
    Artist a1 = newArtist();
    PaintingInfo pi1 = newPaintingInfo();
    Painting p1 = newPainting();
    // needed to save without errors
    p1.setToArtist(a1);
    // *** TESTING THIS ***
    pi1.setPainting(p1);
    // test before save
    assertSame(pi1, p1.getToPaintingInfo());
    assertSame(p1, pi1.getPainting());
    // do save
    context.commitChanges();
    context = context1;
    // test database data
    PaintingInfo pi2 = fetchPaintingInfo();
    Painting p2 = pi2.getPainting();
    assertNotNull(p2);
    assertEquals(paintingName, p2.getPaintingTitle());
}
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) ByteArrayTypeTest(org.apache.cayenne.access.types.ByteArrayTypeTest)

Example 8 with PaintingInfo

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

the class CDOOneDep2OneIT method testReplace.

@Test
public void testReplace() throws Exception {
    String altPaintingName = "alt painting";
    PaintingInfo pi1 = newPaintingInfo();
    Painting p1 = newPainting();
    p1.setPaintingTitle(altPaintingName);
    pi1.setPainting(p1);
    assertTrue(context.hasChanges());
    // do save
    context.commitChanges();
    context = context1;
    // test database data
    PaintingInfo pi2 = fetchPaintingInfo();
    Painting p21 = pi2.getPainting();
    assertNotNull(p21);
    assertEquals(altPaintingName, p21.getPaintingTitle());
    assertSame(pi2, p21.getToPaintingInfo());
    ByteArrayTypeTest.assertByteArraysEqual(paintingImage, p21.getToPaintingInfo().getImageBlob());
    Painting p22 = newPainting();
    // *** TESTING THIS ***
    pi2.setPainting(p22);
    // test before save
    assertNull(p21.getToPaintingInfo());
    assertSame(pi2, p22.getToPaintingInfo());
    assertSame(p22, pi2.getPainting());
    assertEquals(PersistenceState.MODIFIED, pi2.getPersistenceState());
    // do save II
    context.commitChanges();
    ObjectId pi2oid = pi2.getObjectId();
    context = context1;
    PaintingInfo pi3 = fetchPaintingInfo();
    Painting p3 = pi3.getPainting();
    assertNotNull(p3);
    assertEquals(paintingName, p3.getPaintingTitle());
    assertSame(pi3, p3.getToPaintingInfo());
    // test that object id was updated.
    assertEquals(pi2oid, pi3.getObjectId());
}
Also used : PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test) ByteArrayTypeTest(org.apache.cayenne.access.types.ByteArrayTypeTest)

Example 9 with PaintingInfo

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

the class DataContextPrefetchExtras1IT method testPrefetchToOne.

@Test
public void testPrefetchToOne() throws Exception {
    createDataSet();
    SelectQuery query = new SelectQuery(Painting.class);
    query.addPrefetch(Painting.TO_PAINTING_INFO.disjoint());
    List<Painting> objects = context.performQuery(query);
    assertTrue(!objects.isEmpty());
    for (Painting p : objects) {
        PaintingInfo pi = p.getToPaintingInfo();
        assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
        assertEquals(PersistenceState.COMMITTED, pi.getPersistenceState());
    }
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 10 with PaintingInfo

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

the class DataContextPrefetchIT method testPrefetchToOneWithBackRelationship_Joint.

@Test
public void testPrefetchToOneWithBackRelationship_Joint() throws Exception {
    createArtistWithTwoPaintingsAndTwoInfosDataSet();
    SelectQuery<Painting> query = new SelectQuery<Painting>(Painting.class);
    query.andQualifier(Painting.PAINTING_TITLE.eq("p_artist2"));
    query.addPrefetch(Painting.TO_PAINTING_INFO.joint());
    query.addPrefetch(Painting.TO_PAINTING_INFO.dot(PaintingInfo.PAINTING).joint());
    final List<Painting> results = context.select(query);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(1, results.size());
            Painting p0 = results.get(0);
            PaintingInfo pi0 = (PaintingInfo) p0.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
            assertNotNull(pi0);
            assertNotNull(pi0.readPropertyDirectly(PaintingInfo.PAINTING.getName()));
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) 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