use of org.apache.cayenne.cache.MockQueryCache in project cayenne by apache.
the class DataDomainQueryActionIT method testCachedQuery.
@Test
public void testCachedQuery() {
DataDomain domain = runtime.getDataDomain();
Painting p = context.newObject(Painting.class);
p.setPaintingTitle("sample");
SelectQuery query = new SelectQuery(Painting.class);
query.addPrefetch(Painting.TO_GALLERY.disjoint());
query.addPrefetch(Painting.TO_ARTIST.disjoint());
query.addOrdering(Painting.PAINTING_TITLE.asc());
query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
query.setPageSize(5);
QueryCache cache = domain.queryCache;
domain.queryCache = new MockQueryCache() {
@Override
public List<?> get(QueryMetadata metadata, QueryCacheEntryFactory factory) {
Object results = factory.createObject();
assertTrue("Query cache is not serializable.", results instanceof Serializable);
return null;
}
@SuppressWarnings("all")
@Override
public void put(QueryMetadata metadata, List results) {
assertTrue("Query cache is not serializable.", results instanceof Serializable);
}
};
DataDomainQueryAction action = new DataDomainQueryAction(context, domain, query);
action.execute();
domain.queryCache = cache;
}
Aggregations