use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class ShallowMergeOperationIT method testMerge_Relationship.
@Test
public void testMerge_Relationship() throws Exception {
ObjectContext childContext = runtime.newContext(context);
final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
Artist _new = context.newObject(Artist.class);
final Painting _newP = context.newObject(Painting.class);
_new.addToPaintingArray(_newP);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Painting painting = op.merge(_newP);
assertEquals(PersistenceState.COMMITTED, painting.getPersistenceState());
assertNotNull(painting.getToArtist());
assertEquals(PersistenceState.COMMITTED, painting.getToArtist().getPersistenceState());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class SelectById_RunIT method testPrefetch.
@Test
public void testPrefetch() throws Exception {
createTwoArtists();
tPainting.insert(45, 3, "One");
tPainting.insert(48, 3, "Two");
final Artist a3 = SelectById.query(Artist.class, 3).prefetch(Artist.PAINTING_ARRAY.joint()).selectOne(context);
interceptor.runWithQueriesBlocked(new UnitTestClosure() {
@Override
public void execute() {
assertNotNull(a3);
assertEquals("artist3", a3.getArtistName());
assertEquals(2, a3.getPaintingArray().size());
a3.getPaintingArray().get(0).getPaintingTitle();
a3.getPaintingArray().get(1).getPaintingTitle();
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class EJBQLQueryIT method testCacheStrategy.
@Test
public void testCacheStrategy() throws Exception {
// insertValue();
createArtistsDataSet();
final String ejbql = "select a FROM Artist a";
EJBQLQuery query = new EJBQLQuery(ejbql);
query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
final List<Artist> artist1 = context.performQuery(query);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
List<Artist> artist2;
EJBQLQuery query1 = new EJBQLQuery(ejbql);
query1.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
artist2 = context.performQuery(query1);
assertEquals(artist1.get(0).getArtistName(), artist2.get(0).getArtistName());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class CayenneContextWithDataContextIT method testPrefetchingToManyEmpty.
@Test
public void testPrefetchingToManyEmpty() throws Exception {
createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable1.class);
q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
final List<ClientMtTable1> results = clientContext.performQuery(q);
clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
ClientMtTable1 o2 = results.get(1);
assertEquals(PersistenceState.COMMITTED, o2.getPersistenceState());
assertSame(clientContext, o2.getObjectContext());
List<ClientMtTable2> children2 = o2.getTable2Array();
assertFalse(((ValueHolder) children2).isFault());
assertEquals(0, children2.size());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class CayenneContextWithDataContextIT method testOIDQueryInterception.
@Test
public void testOIDQueryInterception() throws Exception {
final ClientMtTable1 o = clientContext.newObject(ClientMtTable1.class);
o.setGlobalAttribute1("aaa");
// fetch new
final ObjectIdQuery q1 = new ObjectIdQuery(o.getObjectId(), false, ObjectIdQuery.CACHE);
clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
List<?> objects = clientContext.performQuery(q1);
assertEquals(1, objects.size());
assertSame(o, objects.get(0));
}
});
clientContext.commitChanges();
// fetch committed
final ObjectIdQuery q2 = new ObjectIdQuery(o.getObjectId(), false, ObjectIdQuery.CACHE);
clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
List<?> objects = clientContext.performQuery(q2);
assertEquals(1, objects.size());
assertSame(o, objects.get(0));
}
});
}
Aggregations