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