@Test(groups = "integration.ejb3")
public void testParsingCriteriaQueryResults_3() throws Exception {
// Same test as above but makes sure pageoverrides default id search works. use different numbers just for variety
getTransactionManager().begin();
EntityManager entityMgr = getEntityManager();
final ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
//verify that all resource objects are actually parsed.
Map<String, Object> resourceNames = new HashMap<String, Object>();
int resourceCount = 423;
try {
final Subject subject = SessionTestHelper.createNewSubject(entityMgr, "testSubject");
Role roleWithSubject = SessionTestHelper.createNewRoleForSubject(entityMgr, subject, "role with subject");
roleWithSubject.addPermission(Permission.VIEW_RESOURCE);
ResourceGroup group = SessionTestHelper.createNewCompatibleGroupForRole(entityMgr, roleWithSubject,
"accessible group");
String tuid = "" + new Random().nextInt();
//create large number of resources
String prefix = "largeResultSet-" + tuid + "-";
System.out.println("-------- Creating " + resourceCount + " resource(s). This may take a while ....");
long start = System.currentTimeMillis();
for (int i = 0; i < resourceCount; i++) {
String name = prefix + i;
Resource r = SessionTestHelper.createNewResourceForGroup(entityMgr, group, name);
//store away each resource name/key
resourceNames.put(String.valueOf(r.getId()), name);
}
entityMgr.flush();
System.out.println("----------- Created " + resourceCount + " resource(s) in "
+ (System.currentTimeMillis() - start) + " ms.");
assert resourceNames.size() == resourceCount;//assert all resources loaded/created
//query the results and delete the resources, use default ID search
ResourceCriteria criteria = new ResourceCriteria();
criteria.addFilterName(prefix);
PageControl pc = new PageControl(0, 73);
criteria.setPageControl(pc);
assert pc.getOrderingFields().isEmpty() : "Should not have had any sorting defined";
//iterate over the results with CriteriaQuery
CriteriaQueryExecutor<Resource, ResourceCriteria> queryExecutor = new CriteriaQueryExecutor<Resource, ResourceCriteria>() {
@Override
public PageList<Resource> execute(ResourceCriteria criteria) {
return resourceManager.findResourcesByCriteria(subject, criteria);
}
};
//initiate first/(total depending on page size) request.
CriteriaQuery<Resource, ResourceCriteria> resources = new CriteriaQuery<Resource, ResourceCriteria>(