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());
}
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());
}
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());
}
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());
}
}
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()));
}
});
}
Aggregations