use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method assertHasDummyTransportMessageContaining.
protected void assertHasDummyTransportMessageContaining(String name, String expectedBodySubstring) {
List<Message> messages = dummyTransport.getMessages("dummy:" + name);
assertNotNull("No messages recorded in dummy transport '" + name + "'", messages);
for (Message message : messages) {
if (message.getBody() != null && message.getBody().contains(expectedBodySubstring)) {
return;
}
}
fail("Notifier " + name + " message body containing '" + expectedBodySubstring + "' not found");
}
use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method assertSingleDummyTransportMessageContaining.
protected void assertSingleDummyTransportMessageContaining(String name, String expectedSubstring) {
List<Message> messages = dummyTransport.getMessages("dummy:" + name);
assertNotNull("No messages recorded in dummy transport '" + name + "'", messages);
if (messages.size() != 1) {
fail("Invalid number of messages recorded in dummy transport '" + name + "', expected: 1, actual: " + messages.size());
}
Message message = messages.get(0);
assertTrue("Notifier " + name + " message body does not contain text: " + expectedSubstring + ", it is:\n" + message.getBody(), message.getBody().contains(expectedSubstring));
}
use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.
the class NotificationsTest method test120NotifierWithMessageTemplateReferenceAndOverridingContentParts.
@Test
public void test120NotifierWithMessageTemplateReferenceAndOverridingContentParts() 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("template-body")).contentType("text/plain").attachment(new NotificationMessageAttachmentType().contentType("text/plain").content("attachment1"))).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)).subjectExpression(velocityExpression("notifier-subject")).bodyExpression(velocityExpression("notifier-body")).attachment(new NotificationMessageAttachmentType().contentType("text/plain").content("attachment2")).transport("test")))).asItemDeltas();
repositoryService.modifyObject(SystemConfigurationType.class, SYS_CONFIG_OID, modifications, result);
assertThat(((TestMessageTransport) transportService.getTransport("test")).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 with content from notifier overriding the declared template parts");
Message message = getSingleMessage(((TestMessageTransport) transportService.getTransport("test")));
assertThat(message).isNotNull();
assertThat(message.getTo()).containsExactlyInAnyOrder("user@example.com");
assertThat(message.getBody()).isEqualTo("notifier-body");
assertThat(message.getSubject()).isEqualTo("notifier-subject");
assertThat(message.getAttachments()).hasSize(2).anyMatch(a -> getRawValue(a.getContent()).equals("attachment1")).anyMatch(a -> getRawValue(a.getContent()).equals("attachment2"));
}
use of com.evolveum.midpoint.notifications.api.transports.Message 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.api.transports.Message 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);
}
Aggregations