use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl 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);
}
use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl 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");
}
use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl in project midpoint by Evolveum.
the class NotificationsTest method test930NotifierUsingNonexistentTransportDoesNotSendAnything.
@Test
public void test930NotifierUsingNonexistentTransportDoesNotSendAnything() throws Exception {
given("configuration with transport and notifier without recipient expression");
Collection<? extends ItemDelta<?, ?>> modifications = prismContext.deltaFor(SystemConfigurationType.class).item(SystemConfigurationType.F_NOTIFICATION_CONFIGURATION).replace(new NotificationConfigurationType(prismContext).handler(new EventHandlerType().generalNotifier(new GeneralNotifierType().transport("nonexistent")))).asItemDeltas();
OperationResult result = getTestOperationResult();
repositoryService.modifyObject(SystemConfigurationType.class, SYS_CONFIG_OID, modifications, result);
when("event without default recipient is sent to notification manager");
CustomEventImpl event = createCustomEvent();
// this will be used as default recipient
event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).emailAddress("user@example.com")));
notificationManager.processEvent(event, getTestTask(), result);
then("result is fatal error because transport can't be found");
assertThatOperationResult(result).isFatalError().hasMessage("Unknown transport named 'nonexistent'");
}
use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl 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);
}
use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl in project midpoint by Evolveum.
the class NotificationsTest method test910NotifierWithoutRecipientAndEventWithoutDefaultRecipientDoesNotSendAnything.
@Test
public void test910NotifierWithoutRecipientAndEventWithoutDefaultRecipientDoesNotSendAnything() throws Exception {
given("configuration with transport and notifier without recipient expression");
Collection<? extends ItemDelta<?, ?>> modifications = systemConfigModificationWithTestTransport("foo").item(SystemConfigurationType.F_NOTIFICATION_CONFIGURATION).replace(new NotificationConfigurationType(prismContext).handler(new EventHandlerType().generalNotifier(new GeneralNotifierType().transport("foo")))).asItemDeltas();
OperationResult result = getTestOperationResult();
repositoryService.modifyObject(SystemConfigurationType.class, SYS_CONFIG_OID, modifications, result);
TestMessageTransport testTransport = (TestMessageTransport) transportService.getTransport("foo");
assertThat(testTransport.getMessages()).isEmpty();
when("event without default recipient is sent to notification manager");
CustomEventImpl event = createCustomEvent();
// No requestee set, that would be taken as default recipient, see test100
notificationManager.processEvent(event, getTestTask(), result);
then("result is success, but no message was sent because of no recipients");
assertThatOperationResult(result).isSuccess().anySubResultMatches(s -> s.isNotApplicable() && s.getMessage().equals("No recipients"));
assertThat(testTransport.getMessages()).isEmpty();
}
Aggregations