Search in sources :

Example 6 with Message

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());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Message(com.evolveum.midpoint.notifications.api.transports.Message) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 7 with Message

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();
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Task(com.evolveum.midpoint.task.api.Task) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) Message(com.evolveum.midpoint.notifications.api.transports.Message) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 8 with Message

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());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) Message(com.evolveum.midpoint.notifications.api.transports.Message) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 9 with Message

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");
    }
}
Also used : Message(com.evolveum.midpoint.notifications.api.transports.Message) HashMap(java.util.HashMap) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) Test(org.testng.annotations.Test)

Example 10 with Message

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

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