Search in sources :

Example 81 with TaskType

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

the class TestUserChangeApprovalLegacy method assertWfContextAfterRootTaskFinishes.

protected void assertWfContextAfterRootTaskFinishes(Task rootTask, List<Task> subtasks, OperationResult result, String... processNames) throws Exception {
    final Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(new ItemPath(F_WORKFLOW_CONTEXT, F_WORK_ITEM), createRetrieve());
    Task opTask = taskManager.createTaskInstance();
    TaskType rootTaskType = modelService.getObject(TaskType.class, rootTask.getOid(), options, opTask, result).asObjectable();
    assertTrue("unexpected process instance id in root task", rootTaskType.getWorkflowContext() == null || rootTaskType.getWorkflowContext().getProcessInstanceId() == null);
    assertEquals("Wrong # of wf subtasks w.r.t processNames (" + Arrays.asList(processNames) + ")", processNames.length, subtasks.size());
    int i = 0;
    for (Task subtask : subtasks) {
        TaskType subtaskType = modelService.getObject(TaskType.class, subtask.getOid(), options, opTask, result).asObjectable();
        display("Subtask #" + (i + 1) + ": ", subtaskType);
        assertNull("Unexpected fetch result in wf subtask: " + subtask, subtaskType.getFetchResult());
        WfContextType wfc = subtaskType.getWorkflowContext();
        assertNotNull("Missing workflow context in wf subtask: " + subtask, wfc);
        assertNotNull("No process ID in wf subtask: " + subtask, wfc.getProcessInstanceId());
        assertEquals("Wrong process ID name in subtask: " + subtask, processNames[i++], wfc.getProcessInstanceName());
        assertNotNull("Missing process start time in subtask: " + subtask, wfc.getStartTimestamp());
        assertNotNull("Missing process end time in subtask: " + subtask, wfc.getEndTimestamp());
        assertEquals("Wrong outcome", SchemaConstants.MODEL_APPROVAL_OUTCOME_APPROVE, wfc.getOutcome());
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) WfContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 82 with TaskType

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

the class TestParseTaskBulkAction method testParseTaskRoundtrip.

@Test
public void testParseTaskRoundtrip() throws Exception {
    System.out.println("===[ testParseTaskRoundtrip ]===");
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    PrismObject<TaskType> task = prismContext.parseObject(TASK_FILE);
    System.out.println("Parsed task:");
    System.out.println(task.debugDump());
    assertTask(task);
    // SERIALIZE
    String serializedTask = prismContext.serializeObjectToString(task, PrismContext.LANG_XML);
    System.out.println("serialized task:");
    System.out.println(serializedTask);
    // RE-PARSE
    RootXNode reparsedToXNode = prismContext.parserFor(serializedTask).xml().parseToXNode();
    System.out.println("Re-parsed task (to XNode):");
    System.out.println(reparsedToXNode.debugDump());
    // real reparse
    PrismObject<TaskType> reparsedTask = prismContext.parseObject(serializedTask);
    System.out.println("Re-parsed task:");
    System.out.println(reparsedTask.debugDump());
    // Cannot assert here. It will cause parsing of some of the raw values and diff will fail
    assertTask(reparsedTask);
    ObjectDelta<TaskType> objectDelta = task.diff(reparsedTask);
    System.out.println("Delta:");
    System.out.println(objectDelta.debugDump());
    assertTrue("Delta is not empty", objectDelta.isEmpty());
    PrismAsserts.assertEquivalent("Task re-parsed equivalence", task, reparsedTask);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) Test(org.testng.annotations.Test)

Example 83 with TaskType

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

the class TestReconScript method test005TestDryRunDelete.

@Test
public void test005TestDryRunDelete() throws Exception {
    final String TEST_NAME = "test005TestDryRunDelete";
    TestUtil.displayTestTile(this, TEST_NAME);
    PrismObject<TaskType> task = getTask(TASK_RECON_DUMMY_OID);
    OperationResult parentResult = new OperationResult(TEST_NAME);
    PropertyDelta dryRunDelta = PropertyDelta.createModificationReplaceProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_DRY_RUN), task.getDefinition(), true);
    Collection<PropertyDelta> modifications = new ArrayList<>();
    modifications.add(dryRunDelta);
    repositoryService.modifyObject(TaskType.class, TASK_RECON_DUMMY_OID, modifications, parentResult);
    getDummyResource().deleteAccountByName("beforeScript");
    waitForTaskStart(TASK_RECON_DUMMY_OID, false);
    waitForTaskNextRunAssertSuccess(TASK_RECON_DUMMY_OID, false);
    waitForTaskFinish(TASK_RECON_DUMMY_OID, false);
    PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, ACCOUNT_BEFORE_SCRIPT_OID, null, parentResult);
    AssertJUnit.assertNotNull(shadow);
    PrismObject<FocusType> user = repositoryService.searchShadowOwner(ACCOUNT_BEFORE_SCRIPT_OID, null, parentResult);
    AssertJUnit.assertNotNull("Owner for account " + shadow + " not found. Some probelm in dry run occured.", user);
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 84 with TaskType

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

the class TestStrangeCases method test410DeleteJack.

/**
     * Delete user jack. See that Jack's tasks are still there (although they may be broken)
     */
@Test
public void test410DeleteJack() throws Exception {
    final String TEST_NAME = "test410DeleteJack";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestStrangeCases.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    dummyAuditService.clear();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    deleteObject(UserType.class, USER_JACK_OID, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    assertSuccess(result);
    // Make sure the user is gone
    assertNoObject(UserType.class, USER_JACK_OID, task, result);
    List<PrismObject<TaskType>> objects = modelService.searchObjects(TaskType.class, null, null, task, result);
    display("Tasks", objects);
    assertEquals("Unexpected number of tastsk", 1, objects.size());
    PrismObject<TaskType> jackTask = null;
    for (PrismObject<TaskType> object : objects) {
        if (object.getOid().equals(TASK_MOCK_JACK_OID)) {
            jackTask = object;
        }
    }
    assertNotNull("Mock task not found (model)", jackTask);
    display("Jack's task (model)", jackTask);
//        ClusterStatusInformation clusterStatusInformation = taskManager.getRunningTasksClusterwide(result);
//        display("Cluster status", clusterStatusInformation);
//        TaskInfo jackTaskInfo = null;
//        Set<TaskInfo> taskInfos = clusterStatusInformation.getTasks();
//        for (TaskInfo taskInfo: taskInfos) {
//        	if (taskInfo.getOid().equals(TASK_MOCK_JACK_OID)) {
//        		jackTaskInfo = taskInfo;
//        	}
//        }
//        assertNotNull("Mock task not found (taskManager)", jackTaskInfo);
//        display("Jack's task (taskManager)", jackTaskInfo);
// TODO: check task status
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 85 with TaskType

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

the class TestStrangeCases method test401ListTasks.

@Test
public void test401ListTasks() throws Exception {
    final String TEST_NAME = "test401ListTasks";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestStrangeCases.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    dummyAuditService.clear();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    List<PrismObject<TaskType>> objects = modelService.searchObjects(TaskType.class, null, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    assertSuccess(result);
    display("Tasks", objects);
    assertEquals("Unexpected number of tasks", 1, objects.size());
    boolean found = false;
    for (PrismObject<TaskType> object : objects) {
        if (object.getOid().equals(TASK_MOCK_JACK_OID)) {
            found = true;
        }
    }
    assertTrue("Mock task not found (model)", found);
    //        ClusterStatusInformation clusterStatusInformation = taskManager.getRunningTasksClusterwide(result);
    //        display("Cluster status", clusterStatusInformation);
    //        TaskInfo jackTaskInfo = null;
    //        Set<TaskInfo> taskInfos = clusterStatusInformation.getTasks();
    //        for (TaskInfo taskInfo: taskInfos) {
    //        	if (taskInfo.getOid().equals(TASK_MOCK_JACK_OID)) {
    //        		jackTaskInfo = taskInfo;
    //        	}
    //        }
    //        assertNotNull("Mock task not found (taskManager)", jackTaskInfo);
    // Make sure that the tasks still runs
    waitForTaskFinish(TASK_MOCK_JACK_OID, false);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

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