Search in sources :

Example 11 with Message

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");
}
Also used : Message(com.evolveum.midpoint.notifications.api.transports.Message)

Example 12 with Message

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));
}
Also used : Message(com.evolveum.midpoint.notifications.api.transports.Message)

Example 13 with Message

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"));
}
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 14 with Message

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"));
}
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 15 with Message

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);
}
Also used : 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)

Aggregations

Message (com.evolveum.midpoint.notifications.api.transports.Message)49 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)41 Test (org.testng.annotations.Test)39 Task (com.evolveum.midpoint.task.api.Task)32 CustomEventImpl (com.evolveum.midpoint.notifications.impl.events.CustomEventImpl)8 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)8 ExecutionContext (com.evolveum.midpoint.model.impl.scripting.ExecutionContext)4 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 ArrayList (java.util.ArrayList)3 ProgressInformation (com.evolveum.midpoint.model.api.ProgressInformation)2 NotificationManager (com.evolveum.midpoint.notifications.api.NotificationManager)2 ModelEvent (com.evolveum.midpoint.notifications.api.events.ModelEvent)2 Transport (com.evolveum.midpoint.notifications.api.transports.Transport)2 TransportService (com.evolveum.midpoint.notifications.api.transports.TransportService)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 S_ItemEntry (com.evolveum.midpoint.prism.delta.builder.S_ItemEntry)2 ExpressionVariables (com.evolveum.midpoint.repo.common.expression.ExpressionVariables)2