use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class TestModelCrudService method test119ModifyUserDeleteAccount.
@Test
public void test119ModifyUserDeleteAccount() throws Exception {
TestUtil.displayTestTile(this, "test119ModifyUserDeleteAccount");
// GIVEN
Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test119ModifyUserDeleteAccount");
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
account.setOid(accountOid);
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
PrismReferenceValue accountRefVal = new PrismReferenceValue();
accountRefVal.setObject(account);
ReferenceDelta accountDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), account);
modifications.add(accountDelta);
// WHEN
modelCrudService.modifyObject(UserType.class, USER_JACK_OID, modifications, null, task, result);
// THEN
// 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 accountRefs", 0, userJackType.getLinkRef().size());
// Check is shadow is gone
try {
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
AssertJUnit.fail("Shadow " + accountOid + " still exists");
} catch (ObjectNotFoundException e) {
// This is OK
}
// Check if dummy resource account is gone
assertNoDummyAccount("jack");
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class TestNotifications method test119ModifyUserDeleteAccount.
@Test
public void test119ModifyUserDeleteAccount() throws Exception {
final String TEST_NAME = "test119ModifyUserDeleteAccount";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestNotifications.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
account.setOid(accountJackOid);
ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
ReferenceDelta accountDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), account);
userDelta.addModification(accountDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result, 2);
assertShadowFetchOperationCountIncrement(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", 0, userJackType.getLinkRef().size());
// Check is shadow is gone
try {
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
AssertJUnit.fail("Shadow " + accountJackOid + " still exists");
} catch (ObjectNotFoundException e) {
// This is OK
}
// Check if dummy resource account is gone
assertNoDummyAccount("jack");
assertDummyScriptsDelete();
// Check notifications
display("Notifications", dummyTransport);
notificationManager.setDisabled(true);
checkDummyTransportMessages("accountPasswordNotifier", 0);
checkDummyTransportMessages("userPasswordNotifier", 0);
checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 1);
checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 0);
checkDummyTransportMessages("simpleAccountNotifier-DELETE-SUCCESS", 1);
checkDummyTransportMessages("simpleUserNotifier", 0);
checkDummyTransportMessages("simpleUserNotifier-ADD", 0);
String expected = "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" + "Account: jack\n" + "\n" + "The account has been successfully removed from the resource.\n" + "\n" + "Channel: ";
assertEquals("Wrong message body", expected, dummyTransport.getMessages("dummy:simpleAccountNotifier-DELETE-SUCCESS").get(0).getBody());
assertSteadyResources();
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class TestRoleEntitlement method test108ModifyRoleAddEntitlementAgain.
@Test
public void test108ModifyRoleAddEntitlementAgain() throws Exception {
final String TEST_NAME = "test108ModifyRoleAddEntitlementAgain";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestRoleEntitlement.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<ShadowType> group = PrismTestUtil.parseObject(GROUP_PIRATE_DUMMY_FILE);
ObjectDelta<RoleType> roleDelta = ObjectDelta.createEmptyModifyDelta(RoleType.class, ROLE_PIRATE_OID, prismContext);
PrismReferenceValue linkRefVal = new PrismReferenceValue();
linkRefVal.setObject(group);
ReferenceDelta groupDelta = ReferenceDelta.createModificationAdd(RoleType.F_LINK_REF, getRoleDefinition(), linkRefVal);
roleDelta.addModification(groupDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(roleDelta);
dummyAuditService.clear();
try {
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
assert false : "Expected executeChanges operation to fail but it has obviously succeeded";
} catch (SchemaException e) {
// This is expected
e.printStackTrace();
// THEN
String message = e.getMessage();
assertMessageContains(message, "already contains entitlement");
assertMessageContains(message, "group");
}
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertRecords(2);
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertTarget(ROLE_PIRATE_OID);
dummyAuditService.assertExecutionOutcome(OperationResultStatus.FATAL_ERROR);
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class TestOrgStruct method test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment.
// this test should generate a SchemaException (modifying targetRef in assignment should be prohibited)
@Test
public void test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment() throws Exception {
final String TEST_NAME = "test412JackChangeMinistryOfOffenseMemberToManagerByModifyingAssignment";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestOrgStruct.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> jack = getUser(USER_JACK_OID);
Long id = findAssignmentIdForTarget(jack, ORG_MINISTRY_OF_OFFENSE_OID);
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
PrismReferenceDefinition referenceDefinition = getUserDefinition().findItemDefinition(new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF), PrismReferenceDefinition.class);
ReferenceDelta referenceDelta = new ReferenceDelta(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_TARGET_REF)), referenceDefinition, prismContext);
PrismReferenceValue oldValue = new PrismReferenceValue(ORG_MINISTRY_OF_OFFENSE_OID, OrgType.COMPLEX_TYPE);
PrismReferenceValue newValue = new PrismReferenceValue(ORG_MINISTRY_OF_OFFENSE_OID, OrgType.COMPLEX_TYPE);
newValue.setRelation(SchemaConstants.ORG_MANAGER);
referenceDelta.addValueToDelete(oldValue);
referenceDelta.addValueToAdd(newValue);
modifications.add(referenceDelta);
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
try {
modelService.executeChanges(deltas, null, task, result);
AssertJUnit.fail("executeChanges should fail but it did not.");
} catch (SchemaException e) {
// ok!
} catch (Exception e) {
AssertJUnit.fail("executeChanges failed in the wrong way (expected SchemaException): " + e);
}
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method createModifyUserUnlinkAccount.
protected ObjectDelta<UserType> createModifyUserUnlinkAccount(String userOid, PrismObject<ResourceType> resource) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
String accountOid = getLinkRefOid(userOid, resource.getOid());
ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext);
PrismReferenceValue accountRefVal = new PrismReferenceValue();
accountRefVal.setOid(accountOid);
ReferenceDelta accountDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
userDelta.addModification(accountDelta);
return userDelta;
}
Aggregations