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());
}
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());
}
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");
}
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();
}
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);
}
Aggregations