Search in sources :

Example 1 with CustomEventImpl

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

the class TestNotifications method test215SendSmsUsingGeneralPost.

@Test
public void test215SendSmsUsingGeneralPost() {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    int messagesHandledOld = httpHandler.messagesHandled;
    when();
    Event event = new CustomEventImpl(lightweightIdentifierGenerator, "general-post", null, "hello world", EventOperationType.ADD, EventStatusType.SUCCESS, null);
    notificationManager.processEvent(event, task, result);
    then();
    result.computeStatus();
    TestUtil.assertSuccess("processEvent result", result);
    // 3 messages for 3 recipients
    assertThat(httpHandler.messagesHandled).isEqualTo(messagesHandledOld + 3);
    assertNotNull("No http request found", httpHandler.lastRequest);
    assertEquals("Wrong HTTP method", "POST", httpHandler.lastRequest.method);
    assertEquals("Wrong URI", "/send", httpHandler.lastRequest.uri.toString());
    assertEquals("Wrong Content-Type header", singletonList("application/x-www-form-urlencoded"), httpHandler.lastRequest.headers.get("content-type"));
    assertEquals("Wrong X-Custom header", singletonList("test"), httpHandler.lastRequest.headers.get("x-custom"));
    String username = "a9038321";
    String password = "5ecr3t";
    String expectedAuthorization = "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes(StandardCharsets.ISO_8859_1));
    assertEquals("Wrong Authorization header", singletonList(expectedAuthorization), httpHandler.lastRequest.headers.get("authorization"));
    // only the last recipient here
    assertEquals("Wrong 1st line of body", "Body=\"body\"&To=[%2B789]&From=from", httpHandler.lastRequest.body.get(0));
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Event(com.evolveum.midpoint.notifications.api.events.Event) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 2 with CustomEventImpl

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

the class TestNotifications method test220SendSmsViaProxy.

@Test
public void test220SendSmsViaProxy() {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    when();
    Event event = new CustomEventImpl(lightweightIdentifierGenerator, "get-via-proxy", null, "hello world via proxy", EventOperationType.ADD, EventStatusType.SUCCESS, null);
    notificationManager.processEvent(event, task, result);
    then();
    result.computeStatus();
    TestUtil.assertSuccess("processEvent result", result);
    assertNotNull("No http request found", httpHandler.lastRequest);
    assertEquals("Wrong HTTP method", "GET", httpHandler.lastRequest.method);
    assertTrue("Header proxy-connection not found in request headers", httpHandler.lastRequest.headers.containsKey("proxy-connection"));
    assertEquals("Wrong proxy-connection header", "Keep-Alive", httpHandler.lastRequest.headers.get("proxy-connection").get(0));
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Event(com.evolveum.midpoint.notifications.api.events.Event) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 3 with CustomEventImpl

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

the class TestNotifications method test200SendSmsUsingGet.

@Test
public void test200SendSmsUsingGet() {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    when();
    Event event = new CustomEventImpl(lightweightIdentifierGenerator, "get", null, "hello world", EventOperationType.ADD, EventStatusType.SUCCESS, null);
    notificationManager.processEvent(event, task, result);
    then();
    result.computeStatus();
    TestUtil.assertSuccess("processEvent result", result);
    assertNotNull("No http request found", httpHandler.lastRequest);
    assertEquals("Wrong HTTP method", "GET", httpHandler.lastRequest.method);
    assertEquals("Wrong URI", "/send?number=%2B421905123456&text=hello+world", httpHandler.lastRequest.uri.toString());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Event(com.evolveum.midpoint.notifications.api.events.Event) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 4 with CustomEventImpl

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

the class TestNotifications method test210SendSmsUsingPost.

@Test
public void test210SendSmsUsingPost() {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    when();
    Event event = new CustomEventImpl(lightweightIdentifierGenerator, "post", null, "hello world", EventOperationType.ADD, EventStatusType.SUCCESS, null);
    notificationManager.processEvent(event, task, result);
    then();
    result.computeStatus();
    TestUtil.assertSuccess("processEvent result", result);
    assertNotNull("No http request found", httpHandler.lastRequest);
    assertEquals("Wrong HTTP method", "POST", httpHandler.lastRequest.method);
    assertEquals("Wrong URI", "/send", httpHandler.lastRequest.uri.toString());
    assertEquals("Wrong Content-Type header", singletonList("application/x-www-form-urlencoded"), httpHandler.lastRequest.headers.get("content-type"));
    assertEquals("Wrong X-Custom header", singletonList("test"), httpHandler.lastRequest.headers.get("x-custom"));
    String username = "a9038321";
    String password = "5ecr3t";
    String expectedAuthorization = "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes(StandardCharsets.ISO_8859_1));
    assertEquals("Wrong Authorization header", singletonList(expectedAuthorization), httpHandler.lastRequest.headers.get("authorization"));
    assertEquals("Wrong 1st line of body", "Body=\"hello+world\"&To=%2B421905123456&From=%2B421999000999", httpHandler.lastRequest.body.get(0));
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Event(com.evolveum.midpoint.notifications.api.events.Event) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 5 with CustomEventImpl

use of com.evolveum.midpoint.notifications.impl.events.CustomEventImpl 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)

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