Search in sources :

Example 46 with Message

use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.

the class TestStrings method test250ApproverAssignment.

// endregion
// region Other
@Test
public void test250ApproverAssignment() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    dummyTransport.clearMessages();
    when();
    assignRole(USER_BOB.oid, ROLE_A_TEST_1.oid, SchemaConstants.ORG_APPROVER, task, task.getResult());
    then();
    assertNull("bob has assigned role \"a-test-1\" as an approver", getUserAssignment(USER_BOB.oid, ROLE_A_TEST_1.oid, SchemaConstants.ORG_APPROVER));
    List<CaseWorkItemType> workItems = getWorkItems(task, result);
    displayWorkItems("Work item after start", workItems);
    CaseType aCase = CaseWorkItemUtil.getCaseRequired(workItems.get(0));
    display("aCase", aCase);
    ApprovalSchemaType schema = aCase.getApprovalContext().getApprovalSchema();
    assertEquals("Wrong # of approval levels", 3, schema.getStage().size());
    assertApprovalLevel(schema, 1, "Line managers", "P5D", 2);
    assertApprovalLevel(schema, 2, "Security", "P7D", 1);
    assertApprovalLevel(schema, 3, "Role approvers (all)", "P5D", 2);
    assertStage(aCase, 1, 3, "Line managers", null);
    List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
    List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
    List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
    display("work items lifecycle notifications", lifecycleMessages);
    display("work items allocation notifications", allocationMessages);
    display("processes notifications", processMessages);
    displayDumpable("audit", dummyAuditService);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Message(com.evolveum.midpoint.notifications.api.transports.Message) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 47 with Message

use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.

the class TestStrings method test222FormApproveByCheese.

/**
 * Cheese approves, filling-in a form.
 */
@Test
public void test222FormApproveByCheese() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    dummyTransport.clearMessages();
    given();
    login(userAdministrator);
    SearchResultList<CaseWorkItemType> workItems = getWorkItems(task, result);
    CaseWorkItemType workItem = sortByOriginalAssignee(workItems).get(USER_CHEESE.oid);
    assertNotNull("No work item for cheese", workItem);
    when();
    PrismObject<UserType> cheese = getUserFromRepo(USER_CHEESE.oid);
    login(cheese);
    ObjectDelta<UserType> formDelta = prismContext.deltaFor(UserType.class).item(UserType.F_DESCRIPTION).replace("Hello").asObjectDelta(USER_BOB.oid);
    caseService.completeWorkItem(WorkItemId.of(workItem), ApprovalUtils.createApproveOutput(prismContext).comment("OK. LeChuck"), formDelta, task, result);
    then();
    login(userAdministrator);
    workItems = getWorkItems(task, result);
    displayWorkItems("Work item after 2nd approval", workItems);
    assertEquals("Wrong # of work items after 2nd approval", 0, workItems.size());
    CaseType aCase = getCase(CaseWorkItemUtil.getCaseRequired(workItem).getOid());
    display("aCase after 2nd approval", aCase);
    assertStage(aCase, 2, 2, "Role approvers (first)", null);
    // notifications
    List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
    List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
    List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
    display("work items lifecycle notifications", lifecycleMessages);
    display("work items allocation notifications", allocationMessages);
    display("processes notifications", processMessages);
    // audit
    displayDumpable("audit", dummyAuditService);
    List<AuditEventRecord> records = dummyAuditService.getRecords();
    if (records.size() != 4 && records.size() != 5) {
        fail("Wrong # of audit records: " + records.size() + " (expected 4 or 5)");
    }
    AuditEventRecord record = records.get(0);
    Collection<ObjectDeltaOperation<? extends ObjectType>> deltas = record.getDeltas();
    assertEquals("Wrong # of deltas in audit record", 1, deltas.size());
    ObjectDeltaOperation<? extends ObjectType> delta = deltas.iterator().next();
    assertEquals("Wrong # of modifications in audit record delta", 2, delta.getObjectDelta().getModifications().size());
    ItemDelta<?, ?> itemDelta = delta.getObjectDelta().getModifications().stream().filter(d -> UserType.F_DESCRIPTION.equivalent(d.getPath())).findFirst().orElse(null);
    assertNotNull("No user.description item delta found", itemDelta);
    assertEquals("Wrong value in delta", "Hello", itemDelta.getValuesToReplace().iterator().next().getRealValue());
    // record #1, #2: cancellation of work items of other approvers
    // record #3: finishing process execution
    // optional #4: asynchronous execution in task
    CaseType rootCase = getCase(aCase.getParentRef().getOid());
    waitForCaseClose(rootCase, CASE_WAIT_TIMEOUT);
    assertAssignedRole(getUser(USER_BOB.oid), ROLE_A_TEST_4.oid);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Message(com.evolveum.midpoint.notifications.api.transports.Message) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) Test(org.testng.annotations.Test)

Example 48 with Message

use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.

the class TestStrings method test108SimpleAssignmentApproveByChef.

/**
 * User `chef` approves the assignment.
 *
 * The case will be closed, and the assignment created.
 */
@Test
public void test108SimpleAssignmentApproveByChef() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    given();
    login(userAdministrator);
    List<CaseWorkItemType> workItems = getWorkItems(task, result);
    Map<String, CaseWorkItemType> workItemsMap = sortByOriginalAssignee(workItems);
    when();
    login(getUser(USER_CHEF.oid));
    WorkItemId workItemId = WorkItemId.of(workItemsMap.get(USER_CHEF.oid));
    caseService.completeWorkItem(workItemId, ApprovalUtils.createApproveOutput(prismContext).comment("OK. Chef."), task, result);
    then();
    login(userAdministrator);
    workItems = getWorkItems(task, result);
    displayWorkItems("Work item after 4th approval", workItems);
    assertEquals("Wrong # of work items on level 3", 0, workItems.size());
    CaseType aCase = getCase(workItemId.caseOid);
    display("case after 4th approval", aCase);
    CaseType parentCase = getCase(aCase.getParentRef().getOid());
    waitForCaseClose(parentCase);
    assertAssignedRole(getUser(USER_BOB.oid), ROLE_A_TEST_1.oid);
    assertTriggers(aCase, 0);
    List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
    List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
    List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
    display("work items lifecycle notifications", lifecycleMessages);
    display("work items allocation notifications", allocationMessages);
    display("processes notifications", processMessages);
    dummyTransport.clearMessages();
    assertEquals("Wrong # of work items lifecycle messages", 1, lifecycleMessages.size());
    assertEquals("Wrong # of work items allocation messages", 1, allocationMessages.size());
    assertEquals("Wrong # of process messages", 1, processMessages.size());
    assertMessage(lifecycleMessages.get(0), "chef@evolveum.com", "Work item has been completed", "Work item: Assigning role \"a-test-1\" to user \"Ghost Pirate Bob\"", "Role approvers (all) (3/3)", "Allocated to: Scumm Bar Chef (chef)", "Carried out by: Scumm Bar Chef (chef)", "Result: Approved", "^Deadline:");
    assertMessage(allocationMessages.get(0), "chef@evolveum.com", "Work item has been completed", "Work item: Assigning role \"a-test-1\" to user \"Ghost Pirate Bob\"", "Role approvers (all) (3/3)", "Allocated to: Scumm Bar Chef (chef)", "Carried out by: Scumm Bar Chef (chef)", "Result: Approved", "^Deadline:");
    assertMessage(processMessages.get(0), "administrator@evolveum.com", "An approval case has been closed", "Case name: Assigning role \"a-test-1\" to user \"Ghost Pirate Bob\"", "Result: Approved");
    displayDumpable("audit", dummyAuditService);
// TODO after audit is OK
// List<AuditEventRecord> workItemEvents = filter(getParamAuditRecords(
// AuditingConstants.AUDIT_WORK_ITEM_ID, workItemId.asString(), task, result), AuditEventStage.EXECUTION);
// assertAuditReferenceValue(workItemEvents, AuditingConstants.AUDIT_OBJECT, userBobOid, UserType.COMPLEX_TYPE, "bob");
// assertAuditTarget(workItemEvents.get(0), userBobOid, UserType.COMPLEX_TYPE, "bob");
// assertAuditReferenceValue(workItemEvents.get(0), AuditingConstants.AUDIT_TARGET, roleATest1Oid, RoleType.COMPLEX_TYPE, "a-test-1");
// TODO other items
// List<AuditEventRecord> processEvents = filter(getParamAuditRecords(
// AuditingConstants.AUDIT_PROCESS_INSTANCE_ID, wfTask.asObjectable().getApprovalContext().getCaseOid(), task, result),
// AuditEventType.WORKFLOW_PROCESS_INSTANCE, AuditEventStage.EXECUTION);
// assertAuditReferenceValue(processEvents, AuditingConstants.AUDIT_OBJECT, userBobOid, UserType.COMPLEX_TYPE, "bob");
// assertAuditTarget(processEvents.get(0), userBobOid, UserType.COMPLEX_TYPE, "bob");
// assertAuditReferenceValue(processEvents.get(0), AuditingConstants.AUDIT_TARGET, roleATest1Oid, RoleType.COMPLEX_TYPE, "a-test-1");
// TODO other items
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Message(com.evolveum.midpoint.notifications.api.transports.Message) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 49 with Message

use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.

the class TestStrings method test106SimpleAssignmentApproveByCheese.

/**
 * User `cheese` (role approver) approves the assignment.
 *
 * The case remains in stage 3, because there's one more approver (all must approve).
 */
@Test
public void test106SimpleAssignmentApproveByCheese() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    dummyTransport.clearMessages();
    given();
    login(userAdministrator);
    List<CaseWorkItemType> workItems = getWorkItems(task, result);
    Map<String, CaseWorkItemType> workItemsMap = sortByOriginalAssignee(workItems);
    when();
    login(getUser(USER_CHEESE.oid));
    caseService.completeWorkItem(WorkItemId.of(workItemsMap.get(USER_CHEESE.oid)), ApprovalUtils.createApproveOutput(prismContext).comment("OK. Cheese."), task, result);
    then();
    login(userAdministrator);
    workItems = getWorkItems(task, result);
    displayWorkItems("Work item after 3rd approval", workItems);
    assertEquals("Wrong # of work items on level 3", 1, workItems.size());
    workItemsMap = sortByOriginalAssignee(workItems);
    CaseType aCase = CaseWorkItemUtil.getCaseRequired(workItems.get(0));
    display("case after 3rd approval", aCase);
    assertStage(aCase, 3, 3, "Role approvers (all)", null);
    assertTriggers(aCase, 2);
    assertNotNull("chef is not an approver", workItemsMap.get(USER_CHEF.oid));
    List<Message> lifecycleMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_LIFECYCLE);
    List<Message> allocationMessages = dummyTransport.getMessages(DUMMY_WORK_ITEM_ALLOCATION);
    List<Message> processMessages = dummyTransport.getMessages(DUMMY_PROCESS);
    display("work items lifecycle notifications", lifecycleMessages);
    display("work items allocation notifications", allocationMessages);
    display("processes notifications", processMessages);
    dummyTransport.clearMessages();
    assertEquals("Wrong # of work items lifecycle messages", 1, lifecycleMessages.size());
    assertEquals("Wrong # of work items allocation messages", 1, allocationMessages.size());
    assertNull("process messages", processMessages);
    assertMessage(lifecycleMessages.get(0), "cheese@evolveum.com", "Work item has been completed", "Work item: Assigning role \"a-test-1\" to user \"Ghost Pirate Bob\"", "Role approvers (all) (3/3)", "Allocated to: Ignatius Cheese (cheese)", "Carried out by: Ignatius Cheese (cheese)", "Result: Approved", "^Deadline:");
    assertMessage(allocationMessages.get(0), "cheese@evolveum.com", "Work item has been completed", "Work item: Assigning role \"a-test-1\" to user \"Ghost Pirate Bob\"", "Role approvers (all) (3/3)", "Allocated to: Ignatius Cheese (cheese)", "Carried out by: Ignatius Cheese (cheese)", "Result: Approved", "^Deadline:");
    displayDumpable("audit", dummyAuditService);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Message(com.evolveum.midpoint.notifications.api.transports.Message) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Aggregations

Message (com.evolveum.midpoint.notifications.api.transports.Message)49 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)41 Test (org.testng.annotations.Test)39 Task (com.evolveum.midpoint.task.api.Task)32 CustomEventImpl (com.evolveum.midpoint.notifications.impl.events.CustomEventImpl)8 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)8 ExecutionContext (com.evolveum.midpoint.model.impl.scripting.ExecutionContext)4 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 ArrayList (java.util.ArrayList)3 ProgressInformation (com.evolveum.midpoint.model.api.ProgressInformation)2 NotificationManager (com.evolveum.midpoint.notifications.api.NotificationManager)2 ModelEvent (com.evolveum.midpoint.notifications.api.events.ModelEvent)2 Transport (com.evolveum.midpoint.notifications.api.transports.Transport)2 TransportService (com.evolveum.midpoint.notifications.api.transports.TransportService)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 S_ItemEntry (com.evolveum.midpoint.prism.delta.builder.S_ItemEntry)2 ExpressionVariables (com.evolveum.midpoint.repo.common.expression.ExpressionVariables)2