use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class SearchIterativeTest method test103SimpleSequentialIterationWithCustomPagingLarge.
@Test
public void test103SimpleSequentialIterationWithCustomPagingLarge() throws Exception {
OperationResult result = new OperationResult("test103SimpleSequentialIterationWithCustomPagingLarge");
final List<PrismObject<UserType>> objects = new ArrayList<>();
ResultHandler<UserType> handler = (object, parentResult) -> {
objects.add(object);
return true;
};
SearchOpAsserter searchOpAsserter = new SearchOpAsserter();
OpAsserter countOpAsserter = new OpAsserter(RepositoryService.OP_COUNT_OBJECTS);
ObjectQuery query = prismContext.queryFactory().createQuery(prismContext.queryFactory().createPaging(1, null));
repositoryService.searchObjectsIterative(UserType.class, query, handler, null, true, result);
result.recomputeStatus();
// repo had to switch to simple paging
countOpAsserter.assertIncrement(1);
searchOpAsserter.assertIncrement(COUNT / BATCH);
assertTrue(result.isSuccess());
assertObjects(objects, COUNT - 1);
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class SearchTest method iterateGeneral.
private void iterateGeneral(int offset, int size, int batch, final String... names) throws Exception {
OperationResult result = new OperationResult("search general");
final List<PrismObject<?>> objects = new ArrayList<>();
ResultHandler<UserType> handler = new ResultHandler<>() {
private int index = 0;
@Override
public boolean handle(PrismObject<UserType> object, OperationResult parentResult) {
objects.add(object);
assertEquals("Incorrect object name was read", names[index++], object.asObjectable().getName().getOrig());
return true;
}
};
SqlRepositoryConfiguration config = ((SqlRepositoryServiceImpl) repositoryService).sqlConfiguration();
int oldBatchSize = config.getIterativeSearchByPagingBatchSize();
config.setIterativeSearchByPagingBatchSize(batch);
logger.trace(">>>>>> iterateGeneral: offset = " + offset + ", size = " + size + ", batch = " + batch + " <<<<<<");
ObjectQuery query = prismContext.queryFactory().createQuery();
query.setPaging(prismContext.queryFactory().createPaging(offset, size, ObjectType.F_NAME, OrderDirection.ASCENDING));
repositoryService.searchObjectsIterative(UserType.class, query, handler, null, false, result);
result.recomputeStatus();
config.setIterativeSearchByPagingBatchSize(oldBatchSize);
assertTrue(result.isSuccess());
assertEquals(size, objects.size());
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class SearchTest method test930IterateAndModify.
/**
* See MID-5474 (just a quick attempt to replicate)
*/
@Test
public void test930IterateAndModify() throws Exception {
OperationResult result = new OperationResult("iterateAndModify");
AtomicInteger count = new AtomicInteger(0);
ResultHandler<UserType> handler = (object, parentResult) -> {
try {
System.out.println("Modifying " + object);
List<ItemDelta<?, ?>> itemDeltas = prismContext.deltaFor(UserType.class).item(UserType.F_DESCRIPTION).replace("desc1").asItemDeltas();
repositoryService.modifyObject(UserType.class, object.getOid(), itemDeltas, parentResult);
System.out.println("OK");
count.incrementAndGet();
return true;
} catch (ObjectNotFoundException | SchemaException | ObjectAlreadyExistsException e) {
throw new SystemException(e.getMessage(), e);
}
};
ObjectQuery query = prismContext.queryFor(UserType.class).item(UserType.F_NAME).eqPoly("atestuserX00002").matchingOrig().build();
repositoryService.searchObjectsIterative(UserType.class, query, handler, null, true, result);
result.recomputeStatus();
assertTrue(result.isSuccess());
assertEquals(1, count.get());
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class SearchIterativeTest method test101SequentialIterationWithSmallResult.
// MID-5339
@Test
public void test101SequentialIterationWithSmallResult() throws Exception {
OperationResult result = new OperationResult("test101SequentialIterationWithSmallResult");
final List<PrismObject<UserType>> objects = new ArrayList<>();
ResultHandler<UserType> handler = (object, parentResult) -> {
objects.add(object);
return true;
};
SearchOpAsserter asserter = new SearchOpAsserter();
ObjectQuery query = prismContext.queryFor(UserType.class).item(UserType.F_COST_CENTER).eq(String.valueOf(BASE)).build();
repositoryService.searchObjectsIterative(UserType.class, query, handler, null, true, result);
result.recomputeStatus();
asserter.assertIncrement(1);
assertTrue(result.isSuccess());
assertObjects(objects, 1);
}
use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.
the class SearchIterativeTest method test105SimpleNonSequentialIteration.
@Test
public void test105SimpleNonSequentialIteration() throws Exception {
OperationResult result = new OperationResult("test105SimpleNonSequentialIteration");
final List<PrismObject<UserType>> objects = new ArrayList<>();
ResultHandler<UserType> handler = (object, parentResult) -> {
objects.add(object);
return true;
};
SearchOpAsserter searchOpAsserter = new SearchOpAsserter();
OpAsserter countOpAsserter = new OpAsserter(RepositoryService.OP_COUNT_OBJECTS);
repositoryService.searchObjectsIterative(UserType.class, null, handler, null, false, result);
result.recomputeStatus();
countOpAsserter.assertIncrement(1);
searchOpAsserter.assertIncrement(COUNT / BATCH);
assertTrue(result.isSuccess());
assertObjects(objects, COUNT);
}
Aggregations