use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl in project midpoint by Evolveum.
the class NotificationsTest method test110NotifierWithMessageTemplateReference.
@Test
public void test110NotifierWithMessageTemplateReference() throws Exception {
OperationResult result = getTestOperationResult();
given("message template");
String objectName = "messageTemplate" + getTestNumber();
String templateOid = repositoryService.addObject(new MessageTemplateType(prismContext).name(objectName).defaultContent(new MessageTemplateContentType(prismContext).subjectExpression(velocityExpression("template-subject")).bodyExpression(velocityExpression("Hi $requestee.name, channel: $!event.channel")).attachment(new NotificationMessageAttachmentType().contentType("text/plain").content("some-text"))).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");
CustomEventImpl event = createCustomEvent();
// This is used as default recipient, no recipient results in no message.
event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).name("John").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("Hi John, channel: test-channel");
assertThat(message.getSubject()).isEqualTo("template-subject");
}
use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl in project midpoint by Evolveum.
the class TestNotifications method test300CheckVariables.
@Test
public void test300CheckVariables() {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
prepareNotifications();
when();
Event event = new CustomEventImpl(lightweightIdentifierGenerator, "check-variables", null, "hello world", EventOperationType.ADD, EventStatusType.SUCCESS, null);
notificationManager.processEvent(event, task, result);
then();
result.computeStatus();
TestUtil.assertSuccess("processEvent result", result);
displayAllNotifications();
assertSingleDummyTransportMessage("check-variables", "variables ok");
}
Aggregations