Search in sources :

Example 1 with LocalizedMessageTemplateContentType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageTemplateContentType 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"));
}
Also used : CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) SimpleExpressionUtil(com.evolveum.midpoint.schema.util.SimpleExpressionUtil) NotificationManager(com.evolveum.midpoint.notifications.api.NotificationManager) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) CustomMessageTransport(com.evolveum.midpoint.transport.impl.CustomMessageTransport) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MailMessageTransport(com.evolveum.midpoint.transport.impl.MailMessageTransport) FileMessageTransport(com.evolveum.midpoint.transport.impl.FileMessageTransport) LightweightIdentifier(com.evolveum.midpoint.task.api.LightweightIdentifier) TransportService(com.evolveum.midpoint.notifications.api.transports.TransportService) LightweightIdentifierGenerator(com.evolveum.midpoint.task.api.LightweightIdentifierGenerator) Collection(java.util.Collection) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) S_ItemEntry(com.evolveum.midpoint.prism.delta.builder.S_ItemEntry) Message(com.evolveum.midpoint.notifications.api.transports.Message) SmsMessageTransport(com.evolveum.midpoint.transport.impl.SmsMessageTransport) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NotNull(org.jetbrains.annotations.NotNull) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) Message(com.evolveum.midpoint.notifications.api.transports.Message) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

Example 2 with LocalizedMessageTemplateContentType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageTemplateContentType 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);
}
Also used : LocalizedMessageTemplateContentType(com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageTemplateContentType) MessageTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.MessageTemplateType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LocalizedMessageTemplateContentType(com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageTemplateContentType) MessageTemplateContentType(com.evolveum.midpoint.xml.ns._public.common.common_3.MessageTemplateContentType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) Test(org.testng.annotations.Test)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Test (org.testng.annotations.Test)2 NotificationManager (com.evolveum.midpoint.notifications.api.NotificationManager)1 Message (com.evolveum.midpoint.notifications.api.transports.Message)1 TransportService (com.evolveum.midpoint.notifications.api.transports.TransportService)1 CustomEventImpl (com.evolveum.midpoint.notifications.impl.events.CustomEventImpl)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 S_ItemEntry (com.evolveum.midpoint.prism.delta.builder.S_ItemEntry)1 SimpleExpressionUtil (com.evolveum.midpoint.schema.util.SimpleExpressionUtil)1 LightweightIdentifier (com.evolveum.midpoint.task.api.LightweightIdentifier)1 LightweightIdentifierGenerator (com.evolveum.midpoint.task.api.LightweightIdentifierGenerator)1 Task (com.evolveum.midpoint.task.api.Task)1 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)1 CustomMessageTransport (com.evolveum.midpoint.transport.impl.CustomMessageTransport)1 FileMessageTransport (com.evolveum.midpoint.transport.impl.FileMessageTransport)1 MailMessageTransport (com.evolveum.midpoint.transport.impl.MailMessageTransport)1 SmsMessageTransport (com.evolveum.midpoint.transport.impl.SmsMessageTransport)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)1