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));
}
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));
}
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());
}
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));
}
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"));
}
Aggregations