Search in sources :

Example 16 with Message

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

the class NotificationsTest method test300MessageTransportUsingRecipientAddressExpression.

@Test
public void test300MessageTransportUsingRecipientAddressExpression() throws Exception {
    OperationResult result = getTestOperationResult();
    given("configuration with transport using recipient address expression");
    // velocity template without any placeholders
    String messageBody = "This is message body";
    Collection<? extends ItemDelta<?, ?>> modifications = prismContext.deltaFor(SystemConfigurationType.class).item(SystemConfigurationType.F_MESSAGE_TRANSPORT_CONFIGURATION).replace(new MessageTransportConfigurationType(prismContext).customTransport(new CustomTransportConfigurationType(prismContext).name("test").recipientAddressExpression(groovyExpression("this.binding.variables.each {k,v -> println \"$k = $v\"};\n" + "return 'xxx' + recipient.emailAddress")).type(TestMessageTransport.class.getName()))).item(SystemConfigurationType.F_NOTIFICATION_CONFIGURATION).replace(new NotificationConfigurationType(prismContext).handler(new EventHandlerType().generalNotifier(new GeneralNotifierType().recipientExpression(groovyExpression("return requestee")).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 with requestee is sent to notification manager");
    CustomEventImpl event = createCustomEvent();
    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();
    and("address is based on notifier/recipientExpression -> transport/recipientAddressExpression chain");
    assertThat(message.getTo()).containsExactlyInAnyOrder("xxxuser@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)

Example 17 with Message

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

the class NotificationsTest method test200RecipientExpressionReturningFocus.

@Test
public void test200RecipientExpressionReturningFocus() throws Exception {
    OperationResult result = getTestOperationResult();
    given("configuration with notifier's recipient expression returning focus object");
    // 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().recipientExpression(groovyExpression("return requestee")).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)

Example 18 with Message

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

the class NotificationsTest method test150NotifierWithLocalizedMessageTemplate.

@Test
public void test150NotifierWithLocalizedMessageTemplate() throws Exception {
    OperationResult result = getTestOperationResult();
    given("localized message template");
    String objectName = "messageTemplate" + getTestNumber();
    String templateOid = repositoryService.addObject(new MessageTemplateType(prismContext).name(objectName).defaultContent(new MessageTemplateContentType(prismContext).bodyExpression(velocityExpression("template-body-default"))).localizedContent(new LocalizedMessageTemplateContentType(prismContext).language("sk").bodyExpression(velocityExpression("template-body-sk"))).asPrismObject(), null, result);
    and("configuration with transport and notifier using the template");
    Collection<? extends ItemDelta<?, ?>> modifications = systemConfigModificationWithTestTransport("test").item(SystemConfigurationType.F_NOTIFICATION_CONFIGURATION).replace(new NotificationConfigurationType(prismContext).handler(new EventHandlerType().generalNotifier(new GeneralNotifierType().messageTemplateRef(createObjectReference(templateOid, MessageTemplateType.COMPLEX_TYPE, null)).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, recipient has no language set");
    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")));
    testTransport.clearMessages();
    notificationManager.processEvent(event, getTestTask(), result);
    then("transport sends the message with default template content");
    Message message = getSingleMessage(testTransport);
    assertThat(message.getTo()).containsExactlyInAnyOrder("user@example.com");
    assertThat(message.getBody()).isEqualTo("template-body-default");
    // now when-then for sk language
    when("event is sent to notification manager, recipient has 'sk' language set");
    event = createCustomEvent();
    event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).emailAddress("user2@example.com").preferredLanguage("sk")));
    testTransport.clearMessages();
    notificationManager.processEvent(event, getTestTask(), result);
    then("transport sends the message with template content for 'sk' language");
    message = getSingleMessage(testTransport);
    assertThat(message.getTo()).containsExactlyInAnyOrder("user2@example.com");
    assertThat(message.getBody()).isEqualTo("template-body-sk");
    // now when-then for other language
    when("event is sent to notification manager, recipient has other language set");
    event = createCustomEvent();
    event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).emailAddress("user3@example.com").preferredLanguage("uk")));
    testTransport.clearMessages();
    notificationManager.processEvent(event, getTestTask(), result);
    then("transport sends the message with default template content, because no localized content for specified language is found");
    message = getSingleMessage(testTransport);
    assertThat(message.getTo()).containsExactlyInAnyOrder("user3@example.com");
    assertThat(message.getBody()).isEqualTo("template-body-default");
}
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)

Example 19 with Message

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

the class TestStrings method test204SixDaysLater.

/**
 * This is after 6 days (T+6D): On 5th day, the escalation takes place.
 *
 * Here we check that.
 *
 * There should be one work item, assigned to both `guybrush` (the original assignee), and `cheese` (the new one).
 */
@Test
public void test204SixDaysLater() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    dummyTransport.clearMessages();
    when();
    clock.resetOverride();
    clock.overrideDuration("P6D");
    waitForTaskNextRun(TASK_TRIGGER_SCANNER_OID, true, 20000, true);
    then();
    List<CaseWorkItemType> workItems = getWorkItems(task, result);
    displayWorkItems("Work items after timed escalation", workItems);
    assertEquals("Wrong # of work items after timed escalation", 1, workItems.size());
    CaseType aCase = CaseWorkItemUtil.getCaseRequired(workItems.get(0));
    display("aCase after timed escalation", aCase);
    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();
    // asserts - work item
    CaseWorkItemType workItem = workItems.get(0);
    PrismAsserts.assertReferenceValues(ref(workItem.getAssigneeRef()), USER_GUYBRUSH.oid, USER_CHEESE.oid);
    PrismAsserts.assertDuration("Wrong duration between now and deadline", "P9D", System.currentTimeMillis(), workItem.getDeadline(), null);
    PrismAsserts.assertReferenceValue(ref(workItem.getOriginalAssigneeRef()), USER_GUYBRUSH.oid);
    assertEquals("Wrong stage #", (Integer) 1, workItem.getStageNumber());
    assertEquals("Wrong escalation level #", 1, WorkItemTypeUtil.getEscalationLevelNumber(workItem));
    assertEquals("Wrong escalation level name", "Line manager escalation", WorkItemTypeUtil.getEscalationLevelName(workItem));
    List<CaseEventType> events = assertEvents(aCase, 2);
    assertEscalationEvent(events.get(1), userAdministrator.getOid(), USER_GUYBRUSH.oid, 1, Collections.singletonList(USER_GUYBRUSH.oid), Collections.singletonList(USER_CHEESE.oid), WorkItemDelegationMethodType.ADD_ASSIGNEES, 1, "Line manager escalation");
    // asserts - notifications
    assertNull("lifecycle messages", lifecycleMessages);
    assertNull("process messages", processMessages);
    assertEquals("Wrong # of work items allocation messages", 3, allocationMessages.size());
    ArrayListValuedHashMap<String, Message> sorted = sortByRecipients(allocationMessages);
    assertMessage(sorted.get("guybrush@evolveum.com").get(0), "guybrush@evolveum.com", "Work item has been escalated", "Work item: Assigning role \"a-test-1\" to user \"Carla the Swordmaster\"", "Stage: Line managers (1/3)", "Allocated to (before escalation): Guybrush Threepwood (guybrush)", "(in 5 days)");
    assertMessage(sorted.get("guybrush@evolveum.com").get(1), "guybrush@evolveum.com", "Work item has been allocated to you", "Work item: Assigning role \"a-test-1\" to user \"Carla the Swordmaster\"", "Stage: Line managers (1/3)", "Escalation level: Line manager escalation (1)", "|Allocated to (after escalation): Guybrush Threepwood (guybrush), Ignatius Cheese (cheese)|Allocated to (after escalation): Ignatius Cheese (cheese), Guybrush Threepwood (guybrush)", "(in 9 days)");
    assertMessage(sorted.get("cheese@evolveum.com").get(0), "cheese@evolveum.com", "Work item has been allocated to you", "Work item: Assigning role \"a-test-1\" to user \"Carla the Swordmaster\"", "Stage: Line managers (1/3)", "Escalation level: Line manager escalation (1)", "|Allocated to (after escalation): Guybrush Threepwood (guybrush), Ignatius Cheese (cheese)|Allocated to (after escalation): Ignatius Cheese (cheese), Guybrush Threepwood (guybrush)", "(in 9 days)");
    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 20 with Message

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

the class TestStrings method test200EscalatedApprovalStart.

// endregion
// region Testing escalation
/**
 * Role `a-test-1` is assigned to `carla`. The approval process is started.
 */
@Test
public void test200EscalatedApprovalStart() throws Exception {
    Task task = getTestTask();
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    dummyTransport.clearMessages();
    when();
    assignRole(USER_CARLA.oid, ROLE_A_TEST_1.oid, task, task.getResult());
    then();
    assertNotAssignedRole(getUser(USER_CARLA.oid), ROLE_A_TEST_1.oid);
    CaseWorkItemType workItem = getWorkItem(task, result);
    display("Work item", workItem);
    CaseType aCase = CaseWorkItemUtil.getCaseRequired(workItem);
    display("case", aCase);
    assertTriggers(aCase, 2);
    assertStage(aCase, 1, 3, "Line managers", null);
    assertAssignee(workItem, USER_GUYBRUSH.oid, USER_GUYBRUSH.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 messages", 1, lifecycleMessages.size());
    assertMessage(lifecycleMessages.get(0), "guybrush@evolveum.com", "A new work item has been created", "Stage: Line managers (1/3)", "Allocated to: Guybrush Threepwood (guybrush)");
    assertMessage(allocationMessages.get(0), "guybrush@evolveum.com", "Work item has been allocated to you", "Stage: Line managers (1/3)", "Allocated to: Guybrush Threepwood (guybrush)");
    assertEquals("Wrong # of work items allocation messages", 1, allocationMessages.size());
    // assertMessage(lifecycleMessages.get(0), "guybrush@evolveum.com", "A new work item has been created", "Stage: Line managers (1/3)", "Guybrush Threepwood (guybrush)");
    assertEquals("Wrong # of process messages", 1, processMessages.size());
    assertMessage(processMessages.get(0), "administrator@evolveum.com", "An approval case has been opened", "Case name: Assigning role \"a-test-1\" to user \"Carla the Swordmaster\"");
    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