Search in sources :

Example 11 with CustomEventImpl

use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl in project midpoint by Evolveum.

the class NotificationsTest method test200RecipientExpressionReturningFocus.

@Test
public void test200RecipientExpressionReturningFocus() throws Exception {
    OperationResult result = getTestOperationResult();
    given("configuration with notifier's recipient expression returning focus object");
    // 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(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 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");
    Message message = getSingleMessage(testTransport);
    assertThat(message).isNotNull();
    assertThat(message.getTo()).containsExactlyInAnyOrder("user@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)

Example 12 with CustomEventImpl

use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl in project midpoint by Evolveum.

the class NotificationsTest method test150NotifierWithLocalizedMessageTemplate.

@Test
public void test150NotifierWithLocalizedMessageTemplate() throws Exception {
    OperationResult result = getTestOperationResult();
    given("localized message template");
    String objectName = "messageTemplate" + getTestNumber();
    String templateOid = repositoryService.addObject(new MessageTemplateType(prismContext).name(objectName).defaultContent(new MessageTemplateContentType(prismContext).bodyExpression(velocityExpression("template-body-default"))).localizedContent(new LocalizedMessageTemplateContentType(prismContext).language("sk").bodyExpression(velocityExpression("template-body-sk"))).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")));
    testTransport.clearMessages();
    notificationManager.processEvent(event, getTestTask(), result);
    then("transport sends the message with default template content");
    Message message = getSingleMessage(testTransport);
    assertThat(message.getTo()).containsExactlyInAnyOrder("user@example.com");
    assertThat(message.getBody()).isEqualTo("template-body-default");
    // now when-then for sk language
    when("event is sent to notification manager, 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("transport sends the message with template content for 'sk' language");
    message = getSingleMessage(testTransport);
    assertThat(message.getTo()).containsExactlyInAnyOrder("user2@example.com");
    assertThat(message.getBody()).isEqualTo("template-body-sk");
    // now when-then for other language
    when("event is sent to notification manager, recipient has other language set");
    event = createCustomEvent();
    event.setRequestee(new SimpleObjectRefImpl(notificationFunctions, new UserType(prismContext).emailAddress("user3@example.com").preferredLanguage("uk")));
    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.getTo()).containsExactlyInAnyOrder("user3@example.com");
    assertThat(message.getBody()).isEqualTo("template-body-default");
}
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)

Example 13 with CustomEventImpl

use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl in project midpoint by Evolveum.

the class NotificationsTest method test930NotifierUsingNonexistentTransportDoesNotSendAnything.

@Test
public void test930NotifierUsingNonexistentTransportDoesNotSendAnything() throws Exception {
    given("configuration with transport and notifier without recipient expression");
    Collection<? extends ItemDelta<?, ?>> modifications = prismContext.deltaFor(SystemConfigurationType.class).item(SystemConfigurationType.F_NOTIFICATION_CONFIGURATION).replace(new NotificationConfigurationType(prismContext).handler(new EventHandlerType().generalNotifier(new GeneralNotifierType().transport("nonexistent")))).asItemDeltas();
    OperationResult result = getTestOperationResult();
    repositoryService.modifyObject(SystemConfigurationType.class, SYS_CONFIG_OID, modifications, result);
    when("event without 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 fatal error because transport can't be found");
    assertThatOperationResult(result).isFatalError().hasMessage("Unknown transport named 'nonexistent'");
}
Also used : 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 CustomEventImpl

use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl in project midpoint by Evolveum.

the class NotificationsTest method test100CustomTransportSendingNotificationMessage.

@Test
public void test100CustomTransportSendingNotificationMessage() throws Exception {
    OperationResult result = getTestOperationResult();
    given("configuration with custom transport and some notifier");
    // 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().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();
    // 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");
    Message message = getSingleMessage(testTransport);
    assertThat(message).isNotNull();
    assertThat(message.getTo()).containsExactlyInAnyOrder("user@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)

Example 15 with CustomEventImpl

use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl in project midpoint by Evolveum.

the class NotificationsTest method test910NotifierWithoutRecipientAndEventWithoutDefaultRecipientDoesNotSendAnything.

@Test
public void test910NotifierWithoutRecipientAndEventWithoutDefaultRecipientDoesNotSendAnything() throws Exception {
    given("configuration with transport and notifier without recipient 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 without default recipient is sent to notification manager");
    CustomEventImpl event = createCustomEvent();
    // No requestee set, that would be taken as default recipient, see test100
    notificationManager.processEvent(event, getTestTask(), result);
    then("result is success, but no message was sent because of no recipients");
    assertThatOperationResult(result).isSuccess().anySubResultMatches(s -> s.isNotApplicable() && s.getMessage().equals("No recipients"));
    assertThat(testTransport.getMessages()).isEmpty();
}
Also used : 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

CustomEventImpl (com.evolveum.midpoint.notifications.impl.events.CustomEventImpl)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)17 Test (org.testng.annotations.Test)17 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)12 Message (com.evolveum.midpoint.notifications.api.transports.Message)8 Task (com.evolveum.midpoint.task.api.Task)7 Event (com.evolveum.midpoint.notifications.api.events.Event)5 NotificationManager (com.evolveum.midpoint.notifications.api.NotificationManager)2 TransportService (com.evolveum.midpoint.notifications.api.transports.TransportService)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 S_ItemEntry (com.evolveum.midpoint.prism.delta.builder.S_ItemEntry)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 SimpleExpressionUtil (com.evolveum.midpoint.schema.util.SimpleExpressionUtil)2 LightweightIdentifier (com.evolveum.midpoint.task.api.LightweightIdentifier)2 LightweightIdentifierGenerator (com.evolveum.midpoint.task.api.LightweightIdentifierGenerator)2 CustomMessageTransport (com.evolveum.midpoint.transport.impl.CustomMessageTransport)2 FileMessageTransport (com.evolveum.midpoint.transport.impl.FileMessageTransport)2 MailMessageTransport (com.evolveum.midpoint.transport.impl.MailMessageTransport)2 SmsMessageTransport (com.evolveum.midpoint.transport.impl.SmsMessageTransport)2