use of com.evolveum.midpoint.xml.ns._public.common.common_3.MessageTemplateContentType 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.xml.ns._public.common.common_3.MessageTemplateContentType 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.xml.ns._public.common.common_3.MessageTemplateContentType in project midpoint by Evolveum.
the class RepoCommonAddGetTest method test200MessageTemplate.
@Test
public void test200MessageTemplate() throws Exception {
OperationResult result = createOperationResult();
given("message template");
String objectName = "messageTemplate" + getTestNumber();
var messageTemplate = new MessageTemplateType(prismContext).name(objectName).defaultContent(new MessageTemplateContentType(prismContext).subjectExpression(velocityExpression("subject-prefix"))).localizedContent(new LocalizedMessageTemplateContentType(prismContext).language("sk_SK").subjectExpression(velocityExpression("Oné")));
when("adding it to the repository");
String oid = repositoryService.addObject(messageTemplate.asPrismObject(), null, result);
assertThatOperationResult(result).isSuccess();
then("it can be obtained using getObject");
MessageTemplateType objectFromRepo = repositoryService.getObject(MessageTemplateType.class, oid, null, result).asObjectable();
// not null implied by the contract
assertThat(objectFromRepo.getDefaultContent()).isNotNull();
ExpressionType subjectExpression = objectFromRepo.getDefaultContent().getSubjectExpression();
assertThat(subjectExpression).isNotNull();
assertThatOperationResult(result).isSuccess();
and("it can be deleted");
repositoryService.deleteObject(MessageTemplateType.class, oid, result);
assertThatOperationResult(result).isSuccess();
assertThatThrownBy(() -> repositoryService.getObject(MessageTemplateType.class, oid, null, result)).isInstanceOf(ObjectNotFoundException.class);
}
Aggregations