Search in sources :

Example 36 with ResultHandler

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

the class TestDummy method test195SearchOnAndOffResource.

/**
     * Search with query that queries both the repository and the resource.
     * We cannot do this. This should fail.
     * MID-2822
     */
@Test
public void test195SearchOnAndOffResource() throws Exception {
    final String TEST_NAME = "test195SearchOnAndOffResource";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestDummy.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    ObjectQuery query = createOnOffQuery();
    ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {

        @Override
        public boolean handle(PrismObject<ShadowType> object, OperationResult parentResult) {
            AssertJUnit.fail("Handler called: " + object);
            return false;
        }
    };
    try {
        // WHEN
        provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, task, result);
        AssertJUnit.fail("unexpected success");
    } catch (SchemaException e) {
        // This is expected
        display("Expected exception", e);
    }
    // THEN
    result.computeStatus();
    TestUtil.assertFailure(result);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 37 with ResultHandler

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

the class TestDummy method test112SeachIterativeKindIntent.

@Test
public void test112SeachIterativeKindIntent() throws Exception {
    final String TEST_NAME = "test112SeachIterativeKindIntent";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    ObjectQuery query = ObjectQueryUtil.createResourceAndKindIntent(RESOURCE_DUMMY_OID, ShadowKindType.ACCOUNT, "default", prismContext);
    display("query", query);
    final List<PrismObject<ShadowType>> foundObjects = new ArrayList<PrismObject<ShadowType>>();
    ResultHandler<ShadowType> handler = new ResultHandler<ShadowType>() {

        @Override
        public boolean handle(PrismObject<ShadowType> object, OperationResult parentResult) {
            foundObjects.add(object);
            return true;
        }
    };
    rememberShadowFetchOperationCount();
    // WHEN
    provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, null, result);
    // THEN
    result.computeStatus();
    display("searchObjectsIterative result", result);
    TestUtil.assertSuccess(result);
    assertShadowFetchOperationCountIncrement(1);
    display("Found shadows", foundObjects);
    assertEquals(4, foundObjects.size());
    checkConsistency(foundObjects);
    // MID-1640
    assertProtected(foundObjects, 1);
    assertSteadyResource();
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Example 38 with ResultHandler

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

the class PageDebugDownloadBehaviour method dumpObjectsToStream.

private void dumpObjectsToStream(final Writer writer, OperationResult result) throws Exception {
    final PageBase page = getPage();
    ResultHandler handler = (object, parentResult) -> {
        try {
            String xml = page.getPrismContext().xmlSerializer().options(createSerializeForExport()).serialize(object);
            writer.write('\t');
            writer.write(xml);
            writer.write('\n');
        } catch (IOException | SchemaException ex) {
            throw new SystemException(ex.getMessage(), ex);
        }
        return true;
    };
    ModelService service = page.getModelService();
    GetOperationOptionsBuilder optionsBuilder = page.getSchemaService().getOperationOptionsBuilder().raw().resolveNames();
    if (showAllItems) {
        optionsBuilder = optionsBuilder.retrieve();
    }
    service.searchObjectsIterative(type, query, handler, optionsBuilder.build(), page.createSimpleTask(OPERATION_SEARCH_OBJECT), result);
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) LocalDateTime(java.time.LocalDateTime) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) StringUtils(org.apache.commons.lang3.StringUtils) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) WebApplicationConfiguration(com.evolveum.midpoint.web.security.WebApplicationConfiguration) SchemaConstantsGenerated(com.evolveum.midpoint.schema.SchemaConstantsGenerated) RestartResponseException(org.apache.wicket.RestartResponseException) ZipEntry(java.util.zip.ZipEntry) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) WebComponentUtil(com.evolveum.midpoint.gui.api.util.WebComponentUtil) Files(org.apache.wicket.util.file.Files) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) PageDebugList(com.evolveum.midpoint.web.page.admin.configuration.PageDebugList) ModelService(com.evolveum.midpoint.model.api.ModelService) File(org.apache.wicket.util.file.File) java.io(java.io) SerializationOptions.createSerializeForExport(com.evolveum.midpoint.prism.SerializationOptions.createSerializeForExport) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) SystemException(com.evolveum.midpoint.util.exception.SystemException) DateTimeFormatter(java.time.format.DateTimeFormatter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) AjaxDownloadBehaviorFromFile(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromFile) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) SystemException(com.evolveum.midpoint.util.exception.SystemException) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) ModelService(com.evolveum.midpoint.model.api.ModelService)

Example 39 with ResultHandler

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);
}
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 40 with ResultHandler

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);
}
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) Test(org.testng.annotations.Test)

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