use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextLocalObjectIT method testLocalObject_TempId.
@Test
public void testLocalObject_TempId() throws Exception {
final Artist a1 = context1.newObject(Artist.class);
interceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Artist a = context2.localObject(a1);
assertNotNull(a);
assertEquals(a1.getObjectId(), a.getObjectId());
// FFE mist be thrown on attempt to read non-existing temp ID
try {
a.getArtistName();
fail("FaultFailureException wasn't thrown on attempt to " + "resolve HOLLOW object with temp id");
} catch (FaultFailureException e) {
// expected
}
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextLocalObjectIT method testLocalObject_InCache.
@Test
public void testLocalObject_InCache() throws Exception {
tArtist.insert(456, "Bla");
final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);
final Artist a2 = Cayenne.objectForPK(context2, Artist.class, 456);
interceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Artist a3 = context2.localObject(a1);
assertSame(a3, a2);
assertSame(context2, a3.getObjectContext());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextObjectIdQuery_PolymorphicIT method testPolymorphicSharedCache_AfterCayenneInsert.
@Test
public void testPolymorphicSharedCache_AfterCayenneInsert() throws SQLException {
// see CAY-2101... we are trying to get a snapshot from a new object in the shared cache, and then read this
// object via a relationship, so that shared cache is consulted
Employee e = context1.newObject(Employee.class);
e.setName("E1");
e.setSalary(1234.01f);
context1.commitChanges();
final ObjectIdQuery q1 = new ObjectIdQuery(new ObjectId("AbstractPerson", "PERSON_ID", Cayenne.intPKForObject(e)), false, ObjectIdQuery.CACHE);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
@Override
public void execute() {
// use different context to ensure we hit shared cache
AbstractPerson ap1 = (AbstractPerson) Cayenne.objectForQuery(context2, q1);
assertTrue(ap1 instanceof Employee);
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextPerformQueryAPIIT method testObjectQueryWithSharedCache.
@Test
public void testObjectQueryWithSharedCache() throws Exception {
createTwoArtists();
List<?> artists = context.performQuery("QueryWithSharedCache", true);
assertEquals(2, artists.size());
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
List<?> artists1 = context2.performQuery("QueryWithSharedCache", false);
assertEquals(2, artists1.size());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure 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