use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.
the class TestModelServiceContract method test100ModifyUserAddAccount.
@Test
public void test100ModifyUserAddAccount() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
getDummyResource().resetBreakMode();
XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();
when();
modifyUserAddAccount(USER_JACK_OID, ACCOUNT_JACK_DUMMY_FILE, task, result);
then();
assertSuccess(result);
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);
// Check accountRef
PrismObject<UserType> userAfter = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
display("User jack after", userAfter);
assertUserJack(userAfter);
UserType userJackType = userAfter.asObjectable();
assertEquals("Unexpected number of accountRefs", 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, SelectorOptions.createCollection(GetOperationOptions.createRaw()), result);
/*
TODO for new repo - why does it complain about raw when there is raw above?
java.lang.IllegalStateException: Raw value PPV([raw], raw element: XNode(primitive:parser ValueParser(DOM-less, Caribbean, namespace declarations)))
in item PP({.../resource/instance/10000000-0000-0000-0000-000000000004}location):[PPV([raw], raw element: XNode(primitive:parser ValueParser(DOM-less, Caribbean, namespace declarations)))]
(attributes/location in shadow:3a727816-70f7-4301-98ab-c1a0020d1ea2(jack))
*/
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
DummyAccount dummyAccount = assertDefaultDummyAccount("jack", "Jack Sparrow", true);
displayDumpable("dummyAccount after", dummyAccount);
assertDummyScriptsAdd(userAfter, accountModel, getDummyResourceType());
// Check audit
displayDumpable("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
// lastProvisioningTimestamp, add account, link
dummyAuditService.assertExecutionDeltas(3);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class);
dummyAuditService.assertTarget(USER_JACK_OID);
dummyAuditService.assertExecutionSuccess();
notificationManager.setDisabled(true);
// Check notifications
checkDummyTransportMessages(NOTIFIER_ACCOUNT_PASSWORD_NAME, 1);
checkDummyTransportMessages("userPasswordNotifier", 0);
checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 1);
checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 1);
checkDummyTransportMessages("simpleUserNotifier", 0);
checkDummyTransportMessages("simpleUserNotifier-ADD", 0);
List<Message> messages = dummyTransport.getMessages("dummy:accountPasswordNotifier");
// number of messages was already checked
Message message = messages.get(0);
assertEquals("Invalid list of recipients", Collections.singletonList("recipient@evolveum.com"), message.getTo());
assertTrue("No account name in account password notification", message.getBody().contains("Password for account jack on Dummy Resource is:"));
assertSteadyResources();
}
use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.
the class TestNotifications method test400StringAttachment.
@Test
public void test400StringAttachment() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.FULL);
when();
PrismObject<UserType> user = new UserType(prismContext).name("testStringAttachmentUser").asPrismObject();
addObject(user);
then();
result.computeStatus();
TestUtil.assertSuccess("addObject result", result);
// Check notifications
displayDumpable("Notifications", dummyTransport);
notificationManager.setDisabled(true);
checkDummyTransportMessages("string-attachment", 1);
Message message = dummyTransport.getMessages("dummy:string-attachment").get(0);
assertEquals("Wrong # of attachments", 1, message.getAttachments().size());
assertEquals("Wrong contentType of attachment", "text/plain", message.getAttachments().get(0).getContentType());
Object content = RawType.getValue(message.getAttachments().get(0).getContent());
assertEquals("Wrong content of attachments", "Hello world", content);
assertEquals("Wrong fileName of attachments", "plain.txt", 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 test430ExpressionAttachment.
@Test
public void test430ExpressionAttachment() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.FULL);
when();
PrismObject<UserType> user = new UserType(prismContext).name("testExpressionAttachmentUser").asPrismObject();
addObject(user);
then();
result.computeStatus();
TestUtil.assertSuccess("addObject result", result);
// Check notifications
displayDumpable("Notifications", dummyTransport);
notificationManager.setDisabled(true);
checkDummyTransportMessages("expression-attachment", 1);
Message message = dummyTransport.getMessages("dummy:expression-attachment").get(0);
assertEquals("Wrong # of attachments", 1, message.getAttachments().size());
assertEquals("Wrong contentType of attachment", "text/html", message.getAttachments().get(0).getContentType());
assertEquals("Wrong content of attachments", "<!DOCTYPE html><html><body>Hello World!</body></html>", message.getAttachments().get(0).getContent());
assertEquals("Wrong fileName of attachments", "hello_world.html", 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 test420AttachmentFromFile.
@Test
public void test420AttachmentFromFile() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.FULL);
when();
PrismObject<UserType> user = new UserType(prismContext).name("testAttachmentFromFileUser").asPrismObject();
addObject(user);
then();
result.computeStatus();
TestUtil.assertSuccess("addObject result", result);
// Check notifications
displayDumpable("Notifications", dummyTransport);
notificationManager.setDisabled(true);
checkDummyTransportMessages("attachment-from-file", 1);
Message message = dummyTransport.getMessages("dummy:attachment-from-file").get(0);
assertEquals("Wrong # of attachments", 1, message.getAttachments().size());
assertEquals("Wrong contentType of attachment", "image/png", message.getAttachments().get(0).getContentType());
assertEquals("Wrong fileName of attachments", "alf.png", message.getAttachments().get(0).getFileName());
assertEquals("Wrong fileName of attachments", "/home/user/example.png", message.getAttachments().get(0).getContentFromFile());
assertNull("Wrong fileName of attachments", message.getAttachments().get(0).getContent());
}
use of com.evolveum.midpoint.notifications.api.transports.Message in project midpoint by Evolveum.
the class AbstractBasicScriptingTest method test430NotificationAboutJackType2.
@Test
public void test430NotificationAboutJackType2() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
ScriptingExpressionType expression = parseScriptingExpression(NOTIFICATION_ABOUT_JACK_TYPE2);
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", "1", m.getBody());
assertEquals("Wrong message subject", "Ad hoc notification 2", m.getSubject());
checkDummyTransportMessages("CustomType2", 1);
m = dummyTransport.getMessages("dummy:CustomType2").get(0);
assertEquals("Wrong message body", "POV:user:c0c010c0-d34d-b33f-f00d-111111111111(jack)", m.getBody());
assertEquals("Wrong message subject", "Failure notification of type 2", m.getSubject());
}
Aggregations