Search in sources :

Example 91 with TaskType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.

the class TestImportRecon method test210ReconcileDummyBroken.

@Test
public void test210ReconcileDummyBroken() throws Exception {
    final String TEST_NAME = "test210ReconcileDummyBroken";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TestImportRecon.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    // Lets do some local changes on dummy resource ... 
    DummyAccount guybrushDummyAccount = getDummyResource().getAccountByUsername(ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
    // location has strong outbound mapping, this change should be corrected
    guybrushDummyAccount.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Phatt Island");
    // BREAK it!
    getDummyResource().setBreakMode(BreakMode.NETWORK);
    getDummyResource().purgeScriptHistory();
    dummyAuditService.clear();
    reconciliationTaskResultListener.clear();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    restartTask(TASK_RECONCILE_DUMMY_OID);
    waitForTaskFinish(TASK_RECONCILE_DUMMY_OID, false, DEFAULT_TASK_WAIT_TIMEOUT, true);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, null, null, task, result);
    display("Users after reconciliation (broken resource)", users);
    // Total error in the recon process. No reasonable result here.
    //        reconciliationTaskResultListener.assertResult(RESOURCE_DUMMY_OID, 0, 7, 1, 0);
    assertImportedUserByOid(USER_ADMINISTRATOR_OID);
    assertImportedUserByOid(USER_JACK_OID);
    assertImportedUserByOid(USER_BARBOSSA_OID);
    assertImportedUserByOid(USER_GUYBRUSH_OID, RESOURCE_DUMMY_OID);
    assertImportedUserByOid(USER_RAPP_OID, RESOURCE_DUMMY_OID, RESOURCE_DUMMY_LIME_OID);
    assertImportedUserByUsername(ACCOUNT_HERMAN_DUMMY_USERNAME, RESOURCE_DUMMY_OID);
    assertNoImporterUserByUsername(ACCOUNT_DAVIEJONES_DUMMY_USERNAME);
    assertNoImporterUserByUsername(ACCOUNT_CALYPSO_DUMMY_USERNAME);
    assertEquals("Unexpected number of users", 10, users.size());
    display("Dummy resource", getDummyResource().debugDump());
    display("Script history", getDummyResource().getScriptHistory());
    // no scripts
    IntegrationTestTools.assertScripts(getDummyResource().getScriptHistory());
    // Task result
    PrismObject<TaskType> reconTaskAfter = getTask(TASK_RECONCILE_DUMMY_OID);
    OperationResultType reconTaskResult = reconTaskAfter.asObjectable().getResult();
    display("Recon task result", reconTaskResult);
    TestUtil.assertFailure(reconTaskResult);
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertExecutionOutcome(OperationResultStatus.FATAL_ERROR);
    dummyAuditService.assertExecutionMessage();
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 92 with TaskType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.

the class TestImportRecon method test200ReconcileDummy.

@Test
public void test200ReconcileDummy() throws Exception {
    final String TEST_NAME = "test200ReconcileDummy";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TestImportRecon.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    // Lets do some local changes on dummy resource
    DummyAccount guybrushDummyAccount = getDummyResource().getAccountByUsername(ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
    // fullname has a normal outbound mapping, this change should NOT be corrected
    guybrushDummyAccount.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Dubrish Freepweed");
    // location has strong outbound mapping, this change should be corrected
    guybrushDummyAccount.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "The Forbidded Dodecahedron");
    // Weapon has a weak mapping, this change should be left as it is
    guybrushDummyAccount.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "Feather duster");
    // Drink is not tolerant. The extra values should be removed
    guybrushDummyAccount.addAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, "water");
    // Quote is tolerant. The extra values should stay as it is
    guybrushDummyAccount.addAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME, "I want to be a pirate!");
    // Calypso is protected, this should not reconcile
    DummyAccount calypsoDummyAccount = getDummyResource().getAccountByUsername(ACCOUNT_CALYPSO_DUMMY_USERNAME);
    calypsoDummyAccount.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Calypso");
    PrismObject<UserType> userRappBefore = getUser(USER_RAPP_OID);
    display("User rapp before", userRappBefore);
    PrismAsserts.assertPropertyValue(userRappBefore, UserType.F_ORGANIZATIONAL_UNIT, PrismTestUtil.createPolyString("The crew of The Elaine"));
    getDummyResource().purgeScriptHistory();
    dummyAuditService.clear();
    rememberShadowFetchOperationCount();
    reconciliationTaskResultListener.clear();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    importObjectFromFile(TASK_RECONCILE_DUMMY_SINGLE_FILE);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    waitForTaskFinish(TASK_RECONCILE_DUMMY_OID, false);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertShadowFetchOperationCountIncrement(3);
    reconciliationTaskResultListener.assertResult(RESOURCE_DUMMY_OID, 0, 7, 0, 0);
    List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, null, null, task, result);
    display("Users after import", users);
    assertImportedUserByOid(USER_ADMINISTRATOR_OID);
    assertImportedUserByOid(USER_JACK_OID);
    assertImportedUserByOid(USER_BARBOSSA_OID);
    assertImportedUserByOid(USER_GUYBRUSH_OID, RESOURCE_DUMMY_OID);
    // Guybrushes fullname should NOT be corrected back to real fullname
    assertDummyAccountAttribute(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Dubrish Freepweed");
    // Guybrushes location should be corrected back to real value
    assertDummyAccountAttribute(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Melee Island");
    // Guybrushes weapon should be left untouched
    assertDummyAccountAttribute(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "Feather duster");
    // Guybrushes drink should be corrected
    assertDummyAccountAttribute(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, "rum");
    // Guybrushes quotes should be left untouched
    assertDummyAccountAttribute(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME, "Arr!", "I want to be a pirate!");
    assertImportedUserByOid(USER_RAPP_OID, RESOURCE_DUMMY_OID, RESOURCE_DUMMY_LIME_OID);
    PrismObject<UserType> userRappAfter = getUser(USER_RAPP_OID);
    display("User rapp after", userRappAfter);
    PrismAsserts.assertPropertyValue(userRappAfter, UserType.F_ORGANIZATIONAL_UNIT, PrismTestUtil.createPolyString("The crew of The Elaine"));
    assertImportedUserByUsername(ACCOUNT_HERMAN_DUMMY_USERNAME, RESOURCE_DUMMY_OID);
    // These are protected accounts, they should not be imported
    assertNoImporterUserByUsername(ACCOUNT_DAVIEJONES_DUMMY_USERNAME);
    assertNoImporterUserByUsername(ACCOUNT_CALYPSO_DUMMY_USERNAME);
    // Calypso is protected account. Reconciliation should not touch it
    assertDummyAccountAttribute(null, ACCOUNT_CALYPSO_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Calypso");
    assertEquals("Unexpected number of users", 10, users.size());
    display("Dummy resource", getDummyResource().debugDump());
    display("Script history", getDummyResource().getScriptHistory());
    ArrayList<ProvisioningScriptSpec> scripts = new ArrayList<ProvisioningScriptSpec>();
    addReconScripts(scripts, ACCOUNT_HERMAN_DUMMY_USERNAME, "Herman Toothrot", false);
    addReconScripts(scripts, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", true);
    addReconScripts(scripts, ACCOUNT_ELAINE_DUMMY_USERNAME, "Elaine Marley", false);
    addReconScripts(scripts, USER_RAPP_USERNAME, USER_RAPP_FULLNAME, false);
    addReconScripts(scripts, ACCOUNT_STAN_NAME, ACCOUNT_STAN_FULLNAME, false);
    IntegrationTestTools.assertScripts(getDummyResource().getScriptHistory(), scripts.toArray(new ProvisioningScriptSpec[0]));
    assertReconAuditModifications(1, TASK_RECONCILE_DUMMY_OID);
    // Task result
    PrismObject<TaskType> reconTaskAfter = getTask(TASK_RECONCILE_DUMMY_OID);
    OperationResultType reconTaskResult = reconTaskAfter.asObjectable().getResult();
    display("Recon task result", reconTaskResult);
    TestUtil.assertSuccess(reconTaskResult);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ProvisioningScriptSpec(com.evolveum.midpoint.test.ProvisioningScriptSpec) PrismObject(com.evolveum.midpoint.prism.PrismObject) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 93 with TaskType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.

the class TestImportRecon method test910DeleteDummyAccounts.

@Test
public void test910DeleteDummyAccounts() throws Exception {
    final String TEST_NAME = "test910DeleteDummyAccounts";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TestImportRecon.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    // Preconditions
    assertUsers(18);
    dummyAuditService.clear();
    rememberShadowFetchOperationCount();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    importObjectFromFile(TASK_DELETE_DUMMY_ACCOUNTS_FILE);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    waitForTaskFinish(TASK_DELETE_DUMMY_ACCOUNTS_OID, true, 20000);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertShadowFetchOperationCountIncrement(2);
    PrismObject<TaskType> deleteTask = getTask(TASK_DELETE_DUMMY_ACCOUNTS_OID);
    OperationResultType deleteTaskResultType = deleteTask.asObjectable().getResult();
    display("Final delete task result", deleteTaskResultType);
    TestUtil.assertSuccess(deleteTaskResultType);
    OperationResult deleteTaskResult = OperationResult.createOperationResult(deleteTaskResultType);
    TestUtil.assertSuccess(deleteTaskResult);
    List<OperationResult> opExecResults = deleteTaskResult.findSubresults(ModelService.EXECUTE_CHANGES);
    assertEquals(1, opExecResults.size());
    OperationResult opExecResult = opExecResults.get(0);
    TestUtil.assertSuccess(opExecResult);
    assertEquals("Wrong exec operation count", 15, opExecResult.getCount());
    assertTrue("Too many subresults: " + deleteTaskResult.getSubresults().size(), deleteTaskResult.getSubresults().size() < 10);
    assertUsers(18);
    // two protected accounts
    assertDummyAccountShadows(2, true, task, result);
    assertDummyAccountShadows(2, false, task, result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 94 with TaskType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.

the class ProcessInstanceProvider method augmentTaskObject.

// doesn't throw any exceptions - these are logged and stored into the operation result
public <T extends ObjectType> void augmentTaskObject(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Task opTask, OperationResult parentResult) {
    final OperationResult result = parentResult.createSubresult(OPERATION_AUGMENT_TASK_OBJECT);
    result.addParam("object", ObjectTypeUtil.toShortString(object));
    result.addCollectionOfSerializablesAsParam("options", options);
    if (!(object.asObjectable() instanceof TaskType)) {
        result.recordNotApplicableIfUnknown();
        return;
    }
    final TaskType taskType = (TaskType) object.asObjectable();
    try {
        if (taskType.getWorkflowContext() == null) {
            return;
        }
        final String instanceId = taskType.getWorkflowContext().getProcessInstanceId();
        if (instanceId == null) {
            return;
        }
        final boolean retrieveWorkItems = SelectorOptions.hasToLoadPath(new ItemPath(F_WORKFLOW_CONTEXT, F_WORK_ITEM), options);
        if (!retrieveWorkItems) {
            // We assume that everything (except work items) is already stored in repo.
            return;
        }
        final List<WorkItemType> workItems = workItemProvider.getWorkItemsForProcessInstanceId(instanceId, result);
        taskType.getWorkflowContext().getWorkItem().addAll(CloneUtil.cloneCollectionMembers(workItems));
    } catch (RuntimeException e) {
        result.recordFatalError(e.getMessage(), e);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare wf-related information for {}", e, ObjectTypeUtil.toShortString(object));
    } finally {
        result.computeStatusIfUnknown();
    }
    if (!result.isSuccess()) {
        taskType.setFetchResult(result.createOperationResultType());
    }
}
Also used : TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) WorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType)

Example 95 with TaskType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.

the class ProcessInstanceManager method getProcessInstancesToKeep.

private Set<String> getProcessInstancesToKeep(OperationResult result) throws SchemaException {
    ObjectQuery query = QueryBuilder.queryFor(TaskType.class, prismContext).not().item(TaskType.F_WORKFLOW_CONTEXT, WfContextType.F_PROCESS_INSTANCE_ID).isNull().build();
    SearchResultList<PrismObject<TaskType>> tasks = taskManager.searchObjects(TaskType.class, query, null, result);
    return tasks.stream().map(t -> t.asObjectable().getWorkflowContext().getProcessInstanceId()).collect(Collectors.toSet());
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) java.util(java.util) WfContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType) TaskService(org.activiti.engine.TaskService) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WorkflowManager(com.evolveum.midpoint.wf.api.WorkflowManager) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) TaskManager(com.evolveum.midpoint.task.api.TaskManager) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) PrismContext(com.evolveum.midpoint.prism.PrismContext) CommonProcessVariableNames(com.evolveum.midpoint.wf.impl.processes.common.CommonProcessVariableNames) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoryService(org.activiti.engine.HistoryService) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) QueryBuilder(com.evolveum.midpoint.prism.query.builder.QueryBuilder) ActivitiEngine(com.evolveum.midpoint.wf.impl.activiti.ActivitiEngine) Component(org.springframework.stereotype.Component) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Aggregations

TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)88 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)63 Test (org.testng.annotations.Test)50 Task (com.evolveum.midpoint.task.api.Task)47 PrismObject (com.evolveum.midpoint.prism.PrismObject)30 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)25 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)23 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)19 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)16 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)15 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)15 ArrayList (java.util.ArrayList)14 QName (javax.xml.namespace.QName)13 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)11 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)10 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)8 Checker (com.evolveum.midpoint.test.Checker)8 ObjectChecker (com.evolveum.midpoint.test.ObjectChecker)8