Search in sources :

Example 16 with ResultHandler

use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.

the class SearchIterativeTest method test104SimpleSequentialIterationWithCustomPagingSmall.

@Test
public void test104SimpleSequentialIterationWithCustomPagingSmall() throws Exception {
    OperationResult result = new OperationResult("test104SimpleSequentialIterationWithCustomPagingSmall");
    final List<PrismObject<UserType>> objects = new ArrayList<>();
    ResultHandler<UserType> handler = (object, parentResult) -> {
        objects.add(object);
        return true;
    };
    SearchOpAsserter asserter = new SearchOpAsserter();
    ObjectQuery query = prismContext.queryFactory().createQuery(prismContext.queryFactory().createPaging(1, 200));
    repositoryService.searchObjectsIterative(UserType.class, query, handler, null, true, result);
    result.recomputeStatus();
    // if we are under limit of FETCH_ALL
    asserter.assertIncrement(1);
    assertTrue(result.isSuccess());
    assertObjects(objects, 200);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) AssertJUnit(org.testng.AssertJUnit) OP_SEARCH_OBJECTS(com.evolveum.midpoint.repo.api.RepositoryService.OP_SEARCH_OBJECTS) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PrismObject(com.evolveum.midpoint.prism.PrismObject) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) ArrayList(java.util.ArrayList) List(java.util.List) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObject(com.evolveum.midpoint.prism.PrismObject) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 17 with ResultHandler

use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.

the class SearchIterativeTest method test110DeleteAll.

@Test
public void test110DeleteAll() throws Exception {
    OperationResult result = new OperationResult("test110DeleteAll");
    final List<PrismObject<UserType>> objects = new ArrayList<>();
    ResultHandler<UserType> handler = (object, parentResult) -> {
        objects.add(object);
        try {
            repositoryService.deleteObject(UserType.class, object.getOid(), parentResult);
        } catch (ObjectNotFoundException e) {
            throw new SystemException(e);
        }
        return true;
    };
    repositoryService.searchObjectsIterative(UserType.class, null, handler, null, true, result);
    result.recomputeStatus();
    assertTrue(result.isSuccess());
    assertObjects(objects, COUNT);
    int count = repositoryService.countObjects(UserType.class, null, null, result);
    assertEquals("Wrong # of objects after operation", 0, count);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) AssertJUnit(org.testng.AssertJUnit) OP_SEARCH_OBJECTS(com.evolveum.midpoint.repo.api.RepositoryService.OP_SEARCH_OBJECTS) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PrismObject(com.evolveum.midpoint.prism.PrismObject) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) ArrayList(java.util.ArrayList) List(java.util.List) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 18 with ResultHandler

use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.

the class SearchTest method test100IterateEmptySet.

@Test
public void test100IterateEmptySet() throws Exception {
    OperationResult result = new OperationResult("search empty");
    ResultHandler<UserType> handler = (object, parentResult) -> {
        fail();
        return false;
    };
    ObjectQuery query = prismContext.queryFor(UserType.class).item(UserType.F_NAME).eqPoly("asdf", "asdf").matchingStrict().build();
    repositoryService.searchObjectsIterative(UserType.class, query, handler, null, false, result);
    result.recomputeStatus();
    assertTrue(result.isSuccess());
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) AssertJUnit(org.testng.AssertJUnit) java.util(java.util) RepoModifyOptions.createForceReindex(com.evolveum.midpoint.repo.api.RepoModifyOptions.createForceReindex) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) F_NAME(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType.F_NAME) Test(org.testng.annotations.Test) DatatypeFactory(javax.xml.datatype.DatatypeFactory) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) Collections.emptySet(java.util.Collections.emptySet) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) OrderDirection(com.evolveum.midpoint.prism.query.OrderDirection) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) SystemException(com.evolveum.midpoint.util.exception.SystemException) ContextConfiguration(org.springframework.test.context.ContextConfiguration) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 19 with ResultHandler

use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.

the class AbstractLdapConnTest method singleInfernoSearch.

private void singleInfernoSearch(ObjectQuery query, int expectedNumberOfResults, Integer offset, Integer maxSize, String sortAttrName, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    ObjectPaging paging = prismContext.queryFactory().createPaging(offset, maxSize);
    paging.setOrdering(getAttributePath(resource, sortAttrName), OrderDirection.ASCENDING);
    query.setPaging(paging);
    final MutableInt count = new MutableInt();
    ResultHandler<ShadowType> handler = (object, parentResult) -> {
        count.increment();
        return true;
    };
    modelService.searchObjectsIterative(ShadowType.class, query, handler, null, task, result);
    assertEquals("Unexpected number of search results", expectedNumberOfResults, count.intValue());
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ReconciliationLauncher(com.evolveum.midpoint.model.impl.sync.tasks.recon.ReconciliationLauncher) AssertJUnit(org.testng.AssertJUnit) MutableInt(org.apache.commons.lang3.mutable.MutableInt) Listeners(org.testng.annotations.Listeners) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.testng.annotations.Test) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) IntegrationTestTools(com.evolveum.midpoint.test.IntegrationTestTools) TestUtil(com.evolveum.midpoint.test.util.TestUtil) Entry(org.apache.directory.api.ldap.model.entry.Entry) ObjectQueryUtil(com.evolveum.midpoint.schema.util.ObjectQueryUtil) PATH_CREDENTIALS_PASSWORD_VALUE(com.evolveum.midpoint.schema.constants.SchemaConstants.PATH_CREDENTIALS_PASSWORD_VALUE) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) InternalCounters(com.evolveum.midpoint.schema.internals.InternalCounters) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ClassMode(org.springframework.test.annotation.DirtiesContext.ClassMode) Collection(java.util.Collection) IOException(java.io.IOException) MiscUtil(com.evolveum.midpoint.util.MiscUtil) PrismObject(com.evolveum.midpoint.prism.PrismObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Task(com.evolveum.midpoint.task.api.Task) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) OrderDirection(com.evolveum.midpoint.prism.query.OrderDirection) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) ShadowUtil(com.evolveum.midpoint.schema.util.ShadowUtil) ContextConfiguration(org.springframework.test.context.ContextConfiguration) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) MutableInt(org.apache.commons.lang3.mutable.MutableInt)

Example 20 with ResultHandler

use of com.evolveum.midpoint.schema.ResultHandler in project midpoint by Evolveum.

the class AbstractLdapHierarchyTest method reconcileAllUsers.

protected void reconcileAllUsers() throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    final Task task = getTestTask();
    OperationResult result = task.getResult();
    ResultHandler<UserType> handler = (object, parentResult) -> {
        try {
            display("reconciling " + object);
            reconcileUser(object.getOid(), task, parentResult);
        } catch (SchemaException | PolicyViolationException | ExpressionEvaluationException | ObjectNotFoundException | ObjectAlreadyExistsException | CommunicationException | ConfigurationException | SecurityViolationException e) {
            throw new SystemException(e.getMessage(), e);
        }
        return true;
    };
    display("Reconciling all users");
    modelService.searchObjectsIterative(UserType.class, null, handler, null, task, result);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) Entry(org.opends.server.types.Entry) PrismTestUtil(com.evolveum.midpoint.prism.util.PrismTestUtil) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) TestUtil(com.evolveum.midpoint.test.util.TestUtil) DirectoryException(org.opends.server.types.DirectoryException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) AfterClass(org.testng.annotations.AfterClass) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ClassMode(org.springframework.test.annotation.DirtiesContext.ClassMode) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) File(java.io.File) OpenDJController(com.evolveum.midpoint.test.ldap.OpenDJController) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) AssertJUnit.assertNotNull(org.testng.AssertJUnit.assertNotNull) AbstractLdapTest(com.evolveum.midpoint.testing.story.ldap.AbstractLdapTest) QName(javax.xml.namespace.QName) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

ResultHandler (com.evolveum.midpoint.schema.ResultHandler)54 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)53 PrismObject (com.evolveum.midpoint.prism.PrismObject)39 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)33 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)29 Test (org.testng.annotations.Test)29 ArrayList (java.util.ArrayList)24 SystemException (com.evolveum.midpoint.util.exception.SystemException)23 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)22 Task (com.evolveum.midpoint.task.api.Task)19 QName (javax.xml.namespace.QName)19 DirtiesContext (org.springframework.test.annotation.DirtiesContext)19 ContextConfiguration (org.springframework.test.context.ContextConfiguration)19 AssertJUnit (org.testng.AssertJUnit)17 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)16 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)16 List (java.util.List)16 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)15 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)14 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)13