use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl in project midpoint by Evolveum.
the class NotificationsTest method test160LocalizedMessageTemplateAttachmentInheritance.
@Test
public void test160LocalizedMessageTemplateAttachmentInheritance() throws Exception {
OperationResult result = getTestOperationResult();
given("localized message template with attachment");
String objectName = "messageTemplate" + getTestNumber();
String templateOid = repositoryService.addObject(new MessageTemplateType(prismContext).name(objectName).defaultContent(new MessageTemplateContentType(prismContext).bodyExpression(velocityExpression("template-body-default")).attachmentExpression(groovyExpression("def a = new com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationMessageAttachmentType();\n" + "a.setContentType(\"text/plain\");\n" + "a.setContent(\"default-content1\");\n" + "return a;")).attachment(new NotificationMessageAttachmentType().contentType("text/plain").content("default-content2"))).localizedContent(new LocalizedMessageTemplateContentType(prismContext).language("sk").bodyExpression(velocityExpression("template-body-sk")).attachment(new NotificationMessageAttachmentType().contentType("text/plain").content("sk-content2"))).localizedContent(new LocalizedMessageTemplateContentType(prismContext).language("cz").bodyExpression(velocityExpression("template-body-cz")).attachmentExpression(groovyExpression("def a = new com.evolveum.midpoint.xml.ns._public.common.common_3.NotificationMessageAttachmentType();\n" + "a.setContentType(\"text/plain\");\n" + "a.setContent(\"cz-content1\");\n" + "return a;"))).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")));
notificationManager.processEvent(event, getTestTask(), result);
then("transport sends the message with default template content");
Message message = getSingleMessage(testTransport);
assertThat(message.getAttachments()).hasSize(2).anyMatch(// from expression
a -> getRawValue(a.getContent()).equals("default-content1")).anyMatch(a -> getRawValue(a.getContent()).equals("default-content2"));
// now when-then for sk language (attachment expression inherited)
when("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("message uses attachment expression from default content");
message = getSingleMessage(testTransport);
assertThat(message.getAttachments()).hasSize(2).anyMatch(// from expression
a -> getRawValue(a.getContent()).equals("default-content1")).anyMatch(a -> getRawValue(a.getContent()).equals("sk-content2"));
// now when-then for cz language (attachment inherited)
when("event is sent to notification manager, recipient has 'cz' language set");
event = createCustomEvent();
event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).emailAddress("user3@example.com").preferredLanguage("cz")));
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.getAttachments()).hasSize(2).anyMatch(// from expression
a -> getRawValue(a.getContent()).equals("cz-content1")).anyMatch(a -> getRawValue(a.getContent()).equals("default-content2"));
}
use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl in project midpoint by Evolveum.
the class NotificationsTest method test210RecipientExpressionReturningLiteralValue.
@Test
public void test210RecipientExpressionReturningLiteralValue() throws Exception {
OperationResult result = getTestOperationResult();
given("configuration with notifier's recipient expression returning literal value");
// 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(literalExpression("literal@example.com")).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();
notificationManager.processEvent(event, getTestTask(), result);
then("transport sends the message");
Message message = getSingleMessage(testTransport);
assertThat(message).isNotNull();
assertThat(message.getTo()).containsExactlyInAnyOrder("literal@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 test920NotifierWithoutBodyDoesNotSendAnything.
@Test
public void test920NotifierWithoutBodyDoesNotSendAnything() throws Exception {
given("configuration with transport and notifier without body 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 with 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 success, but no message was sent because of empty body");
assertThatOperationResult(result).isSuccess().anySubResultMatches(s -> s.isNotApplicable() && s.getMessage().equals("No message body"));
assertThat(testTransport.getMessages()).isEmpty();
}
use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl 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);
}
use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl in project midpoint by Evolveum.
the class NotificationsTest method test900NotifierWithoutTransportDoesNotSendAnything.
@Test
public void test900NotifierWithoutTransportDoesNotSendAnything() throws Exception {
given("configuration with notifier without transport");
Collection<? extends ItemDelta<?, ?>> modifications = prismContext.deltaFor(SystemConfigurationType.class).item(SystemConfigurationType.F_NOTIFICATION_CONFIGURATION).replace(new NotificationConfigurationType(prismContext).handler(new EventHandlerType().generalNotifier(new GeneralNotifierType()))).asItemDeltas();
OperationResult result = getTestOperationResult();
repositoryService.modifyObject(SystemConfigurationType.class, SYS_CONFIG_OID, modifications, result);
when("event is sent to notification manager");
CustomEventImpl event = createCustomEvent();
notificationManager.processEvent(event, getTestTask(), result);
then("result is success, but no message was sent because there is no transport");
assertThatOperationResult(result).isSuccess().anySubResultMatches(s -> s.isNotApplicable() && s.getMessage().equals("No transports"));
}
Aggregations