Search in sources :

Example 36 with Message

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

the class TestRbac method test870AssignRoleScreaming.

@Test
public void test870AssignRoleScreaming() throws Exception {
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    notificationManager.setDisabled(false);
    Task task = getTestTask();
    OperationResult result = task.getResult();
    PrismObject<UserType> userJackBefore = getUser(USER_JACK_OID);
    display("user jack", userJackBefore);
    // WHEN
    when();
    assignRole(USER_JACK_OID, ROLE_SCREAMING_OID, getDefaultOptions(), task, result);
    // THEN
    then();
    assertSuccess(result);
    PrismObject<UserType> userJackAfter = getUser(USER_JACK_OID);
    display("user after", userJackAfter);
    displayDumpable("dummy transport", dummyTransport);
    List<Message> messages = dummyTransport.getMessages("dummy:policyRuleNotifier");
    assertNotNull("No notification messages", messages);
    assertEquals("Wrong # of notification messages", 1, messages.size());
}
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 37 with Message

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

the class TestEscalation method test110Escalate.

@Test
public void test110Escalate() throws Exception {
    login(getUserFromRepo(USER_ADMINISTRATOR_OID));
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    dummyTransport.clearMessages();
    // WHEN
    when();
    clock.resetOverride();
    // first escalation is at P1D
    clock.overrideDuration("P2D");
    waitForTaskNextRun(TASK_TRIGGER_SCANNER_OID, true, 20000, true);
    // THEN
    then();
    result.computeStatus();
    TestUtil.assertSuccess(result);
    List<AccessCertificationCaseType> caseList = queryHelper.searchCases(campaignOid, null, null, result);
    display("caseList", caseList);
    checkAllCasesSanity(caseList);
    AccessCertificationCaseType ceoCase = findCase(caseList, USER_JACK_OID, ROLE_CEO_OID);
    display("CEO case after escalation", ceoCase);
    AccessCertificationWorkItemType workItem = CertCampaignTypeUtil.findWorkItem(ceoCase, 1, 1, USER_ADMINISTRATOR_OID);
    assertObjectRefs("assignees", false, workItem.getAssigneeRef(), USER_JACK_OID, USER_ADMINISTRATOR_OID);
    assertEquals("Wrong originalAssignee OID", USER_ADMINISTRATOR_OID, workItem.getOriginalAssigneeRef().getOid());
    final WorkItemEscalationLevelType NEW_ESCALATION_LEVEL = new WorkItemEscalationLevelType().number(1).name("jack-level");
    assertEquals("Wrong escalation info", NEW_ESCALATION_LEVEL, workItem.getEscalationLevel());
    assertEquals("Wrong # of events", 1, ceoCase.getEvent().size());
    WorkItemEscalationEventType event = (WorkItemEscalationEventType) ceoCase.getEvent().get(0);
    assertNotNull("No timestamp in event", event.getTimestamp());
    assertEquals("Wrong initiatorRef OID", USER_ADMINISTRATOR_OID, event.getInitiatorRef().getOid());
    assertEquals("Wrong workItemId", workItem.getId(), event.getWorkItemId());
    assertObjectRefs("assigneeBefore", false, event.getAssigneeBefore(), USER_ADMINISTRATOR_OID);
    assertObjectRefs("delegatedTo", false, event.getDelegatedTo(), USER_JACK_OID);
    assertEquals("Wrong delegationMethod", WorkItemDelegationMethodType.ADD_ASSIGNEES, event.getDelegationMethod());
    assertEquals("Wrong new escalation level", NEW_ESCALATION_LEVEL, event.getNewEscalationLevel());
    AccessCertificationCaseType superuserCase = findCase(caseList, USER_ADMINISTRATOR_OID, ROLE_SUPERUSER_OID);
    AccessCertificationWorkItemType superuserWorkItem = CertCampaignTypeUtil.findWorkItem(superuserCase, 1, 1, USER_ADMINISTRATOR_OID);
    // noinspection SimplifiedTestNGAssertion
    assertEquals("Escalation info present even if it shouldn't be", null, superuserWorkItem.getEscalationLevel());
    AccessCertificationCampaignType campaign = getCampaignWithCases(campaignOid);
    // 1 reviewer per case (always administrator)
    assertPercentCompleteAll(campaign, Math.round(100.0f / 7.0f), Math.round(100.0f / 7.0f), Math.round(100.0f / 7.0f));
    AccessCertificationStageType currentStage = CertCampaignTypeUtil.getCurrentStage(campaign);
    assertNotNull(currentStage);
    assertEquals("Wrong new stage escalation level", NEW_ESCALATION_LEVEL, currentStage.getEscalationLevel());
    display("campaign after escalation", campaign);
    // completion + timed-action (P3D)
    assertEquals("Wrong # of triggers", 2, campaign.getTrigger().size());
    displayDumpable("dummy transport", dummyTransport);
    List<Message> messages = dummyTransport.getMessages("dummy:simpleReviewerNotifier");
    // original + new approver + deputy of administrator
    assertEquals("Wrong # of dummy notifications", 3, messages.size());
}
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 38 with Message

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

the class AbstractModelIntegrationTest method assertHasDummyTransportMessage.

protected void assertHasDummyTransportMessage(String name, String expectedBody) {
    List<Message> messages = dummyTransport.getMessages("dummy:" + name);
    assertNotNull("No messages recorded in dummy transport '" + name + "'", messages);
    for (Message message : messages) {
        if (expectedBody.equals(message.getBody())) {
            return;
        }
    }
    fail("Notifier " + name + " message body " + expectedBody + " not found");
}
Also used : Message(com.evolveum.midpoint.notifications.api.transports.Message)

Example 39 with Message

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

the class AbstractModelIntegrationTest method getDummyTransportMessageBody.

protected String getDummyTransportMessageBody(String name, int index) {
    List<Message> messages = dummyTransport.getMessages("dummy:" + name);
    Message message = messages.get(index);
    return message.getBody();
}
Also used : Message(com.evolveum.midpoint.notifications.api.transports.Message)

Example 40 with Message

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

the class NotificationsTest method test100CustomTransportSendingNotificationMessage.

@Test
public void test100CustomTransportSendingNotificationMessage() throws Exception {
    OperationResult result = getTestOperationResult();
    given("configuration with custom transport and some notifier");
    // velocity template without any placeholders
    String messageBody = "This is message body";
    Collection<? extends ItemDelta<?, ?>> modifications = systemConfigModificationWithTestTransport("test").item(SystemConfigurationType.F_NOTIFICATION_CONFIGURATION).replace(new NotificationConfigurationType(prismContext).handler(new EventHandlerType().generalNotifier(new GeneralNotifierType().bodyExpression(velocityExpression(messageBody)).transport("test")))).asItemDeltas();
    repositoryService.modifyObject(SystemConfigurationType.class, SYS_CONFIG_OID, modifications, result);
    TestMessageTransport testTransport = (TestMessageTransport) transportService.getTransport("test");
    assertThat(testTransport.getMessages()).isEmpty();
    when("event is sent to notification manager");
    CustomEventImpl event = createCustomEvent();
    // This is used as default recipient, no recipient results in no message.
    event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).emailAddress("user@example.com")));
    notificationManager.processEvent(event, getTestTask(), result);
    then("transport sends the message");
    Message message = getSingleMessage(testTransport);
    assertThat(message).isNotNull();
    assertThat(message.getTo()).containsExactlyInAnyOrder("user@example.com");
    assertThat(message.getBody()).isEqualTo(messageBody);
}
Also used : Message(com.evolveum.midpoint.notifications.api.transports.Message) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) 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