use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.
the class TestNotifications method test410ByteAttachment.
@Test
public void test410ByteAttachment() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.FULL);
when();
PrismObject<UserType> user = new UserType(prismContext).name("testByteAttachmentUser").asPrismObject();
addObject(user);
then();
result.computeStatus();
TestUtil.assertSuccess("addObject result", result);
// Check notifications
displayDumpable("Notifications", dummyTransport);
notificationManager.setDisabled(true);
checkDummyTransportMessages("byte-attachment", 1);
Message message = dummyTransport.getMessages("dummy:byte-attachment").get(0);
assertEquals("Wrong # of attachments", 1, message.getAttachments().size());
assertEquals("Wrong contentType of attachment", "image/jpeg", message.getAttachments().get(0).getContentType());
String origJPEGString = "/9j/4AAQSkZJRgABAQEAYABgAAD/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAEAAAAAAAD/2wBDAAIBAQ" + "IBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAw" + "YMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAAFAAUDASIAAhEBAxEB/8" + "QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBka" + "EII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJip" + "KTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQ" + "EBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUv" + "AVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJ" + "maoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDg/hn471" + "A6fqljY22i28kWq3V9NPNayTNcG6fzlU4lU/uwfLBJOVVeFxyUUV5OXcXZxSw8YU8RJLXRW6tt9O55nEnhZwnicxqVsRgKcpPlu2" + "m3pFJat9Ekl5H/2Q==";
byte[] origJPEG = Base64.getDecoder().decode(origJPEGString);
Object content = RawType.getValue(message.getAttachments().get(0).getContent());
if (!(content instanceof byte[]) || !Arrays.equals(origJPEG, (byte[]) content)) {
throw new AssertionError("Wrong content of attachments expected:" + Arrays.toString(origJPEG) + " but was:" + content);
}
assertEquals("Wrong fileName of attachments", "alf.jpg", message.getAttachments().get(0).getFileName());
assertNull("Wrong fileName of attachments", message.getAttachments().get(0).getContentFromFile());
}
use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.
the class TestNotifications method test100ModifyUserAddAccount.
@Test
public void test100ModifyUserAddAccount() throws Exception {
given();
Task task = taskManager.createTaskInstance(TestNotifications.class.getName() + ".test100ModifyUserAddAccount");
task.setChannel(SchemaConstants.CHANNEL_USER_URI);
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();
when();
ObjectDelta<UserType> userDelta = createAddAccountDelta(USER_JACK_OID, ACCOUNT_JACK_DUMMY_FILE);
// This is to test for MID-5849. The applicability checking was not correct, so it passed even if there we no items
// to show in the notification.
userDelta.addModification(deltaFor(UserType.class).item(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_METADATA, MetadataType.F_CREATE_CHANNEL).replace("dummy").asItemDelta());
executeChanges(userDelta, null, task, result);
then();
result.computeStatus();
TestUtil.assertSuccess(result);
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);
// Check accountRef
PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
assertUserJack(userJack);
UserType userJackType = userJack.asObjectable();
assertEquals("Unexpected number of linkRefs", 1, userJackType.getLinkRef().size());
ObjectReferenceType accountRefType = userJackType.getLinkRef().get(0);
accountJackOid = accountRefType.getOid();
assertFalse("No accountRef oid", StringUtils.isBlank(accountJackOid));
PrismReferenceValue accountRefValue = accountRefType.asReferenceValue();
assertEquals("OID mismatch in accountRefValue", accountJackOid, accountRefValue.getOid());
assertNull("Unexpected object in accountRefValue", accountRefValue.getObject());
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
assertDummyAccountShadowRepo(accountShadow, accountJackOid, "jack");
assertEnableTimestampShadow(accountShadow, startTime, endTime);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountJackOid, "jack", "Jack Sparrow");
// Check account in dummy resource
assertDefaultDummyAccount("jack", "Jack Sparrow", true);
notificationManager.setDisabled(true);
// Check notifications
displayDumpable("Dummy transport messages", dummyTransport);
checkDummyTransportMessages("accountPasswordNotifier", 1);
checkDummyTransportMessages("userPasswordNotifier", 0);
checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 1);
checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
checkDummyTransportMessages("simpleAccountNotifier-IN-PROGRESS", 0);
checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 1);
checkDummyTransportMessages("simpleUserNotifier", 0);
checkDummyTransportMessages("simpleUserNotifier-ADD", 0);
List<Message> pwdMessages = dummyTransport.getMessages("dummy:accountPasswordNotifier");
// number of messages was already checked
Message pwdMessage = pwdMessages.get(0);
assertEquals("Invalid list of recipients", singletonList("recipient@evolveum.com"), pwdMessage.getTo());
assertEquals("Wrong message body", "Password for account jack on Dummy Resource is: deadmentellnotales", pwdMessage.getBody());
List<Message> addMessages = dummyTransport.getMessages("dummy:simpleAccountNotifier-ADD-SUCCESS");
// number of messages was already checked
Message addMessage = addMessages.get(0);
assertEquals("Invalid list of recipients", singletonList("recipient@evolveum.com"), addMessage.getTo());
assertEquals("Wrong message body", "Notification about account-related operation\n" + "\n" + "Owner: Jack Sparrow (jack, oid c0c010c0-d34d-b33f-f00d-111111111111)\n" + "Resource: Dummy Resource (oid 10000000-0000-0000-0000-000000000004)\n" + "\n" + "An account has been successfully created on the resource with attributes:\n" + " - UID: jack\n" + " - Username: jack\n" + " - Location: Caribbean\n" + " - Quote: Arr!\n" + " - Drink: rum\n" + " - Weapon: rum\n" + " - Full Name: Jack Sparrow\n" + " - Password:\n" + " - Value: (protected string)\n" + " - Administrative status: ENABLED\n" + "\n" + "Channel: http://midpoint.evolveum.com/xml/ns/public/common/channels-3#user", addMessage.getBody());
assertSteadyResources();
}
use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.
the class AbstractBasicScriptingTest method test420NotificationAboutJack.
@Test
public void test420NotificationAboutJack() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
ScriptingExpressionType expression = parseScriptingExpression(NOTIFICATION_ABOUT_JACK);
prepareNotifications();
when();
ExecutionContext output = evaluator.evaluateExpression(expression, task, result);
then();
dumpOutput(output, result);
assertSuccess(result);
assertOutputData(output, 1, OperationResultStatus.SUCCESS);
assertEquals("Produced 1 event(s)\n", output.getConsoleOutput());
displayDumpable("Dummy transport", dummyTransport);
checkDummyTransportMessages("Custom", 1);
Message m = dummyTransport.getMessages("dummy:Custom").get(0);
assertEquals("Wrong message body", "jack/" + USER_JACK_OID, m.getBody());
assertEquals("Wrong message subject", "Ad hoc notification", m.getSubject());
}
use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.
the class TestEscalation method test220Reject.
/**
* After 5 days, the case should be auto-rejected.
*/
@Test
public void test220Reject() throws Exception {
given();
login(userAdministrator);
dummyAuditService.clear();
dummyTransport.clearMessages();
clock.resetOverride();
// at 5D there's a deadline with auto-rejection
clock.overrideDuration("P5DT2H");
when();
waitForTaskNextRun(TASK_TRIGGER_SCANNER_OID, true, 20000, true);
then();
// @formatter:off
var approvalCase = assertCase(approvalCaseOid, "after").display().displayXml().assertClosed().assertStageNumber(1).triggers().assertTriggers(0).end().workItems().forOriginalAssignee(USER_BOB_OID).assertClosed().assertEscalationLevelNumber(1).end().forOriginalAssignee(USER_BOBEK_OID).assertClosed().assertEscalationLevelNumber(1).end().end().getObjectable();
// @formatter:on
Map<String, WorkItemCompletionEventType> eventMap = new HashMap<>();
for (CaseEventType event : approvalCase.getEvent()) {
if (event instanceof WorkItemCompletionEventType) {
WorkItemCompletionEventType c = (WorkItemCompletionEventType) event;
eventMap.put(c.getExternalWorkItemId(), c);
assertNotNull("No result in " + c, c.getOutput());
assertEquals("Wrong outcome in " + c, WorkItemOutcomeType.REJECT, ApprovalUtils.fromUri(c.getOutput().getOutcome()));
assertNotNull("No cause in " + c, c.getCause());
assertEquals("Wrong cause type in " + c, WorkItemEventCauseTypeType.TIMED_ACTION, c.getCause().getType());
assertEquals("Wrong cause name in " + c, "auto-reject", c.getCause().getName());
assertEquals("Wrong cause display name in " + c, "Automatic rejection at deadline", c.getCause().getDisplayName());
}
}
displayValue("completion event map", eventMap);
assertEquals("Wrong # of work item completion events in case history", 2, eventMap.size());
displayCollection("audit records", dummyAuditService.getRecords());
List<AuditEventRecord> workItemAuditRecords = dummyAuditService.getRecordsOfType(AuditEventType.WORK_ITEM);
assertEquals("Wrong # of work item audit records", 2, workItemAuditRecords.size());
for (AuditEventRecord r : workItemAuditRecords) {
assertEquals("Wrong causeType in " + r, Collections.singleton("timedAction"), r.getPropertyValues(AuditingConstants.AUDIT_CAUSE_TYPE));
assertEquals("Wrong causeName in " + r, Collections.singleton("auto-reject"), r.getPropertyValues(AuditingConstants.AUDIT_CAUSE_NAME));
assertEquals("Wrong causeDisplayName in " + r, Collections.singleton("Automatic rejection at deadline"), r.getPropertyValues(AuditingConstants.AUDIT_CAUSE_DISPLAY_NAME));
assertEquals("Wrong result in " + r, "Rejected", r.getResult());
}
displayCollection("notifications - process", dummyTransport.getMessages("dummy:simpleWorkflowNotifier-Processes"));
List<Message> notifications = dummyTransport.getMessages("dummy:simpleWorkflowNotifier-WorkItems");
displayCollection("notifications - work items", notifications);
for (Message notification : notifications) {
assertContains(notification, "Reason: Automatic rejection at deadline (timed action)");
assertContains(notification, "Result: Rejected");
}
}
use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method assertSingleDummyTransportMessage.
protected void assertSingleDummyTransportMessage(String name, String expectedBody) {
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);
assertEquals("Unexpected notifier " + name + " message body", expectedBody, message.getBody());
}
Aggregations