use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class TestRecomputeTask method test100RecomputeAll.
@Test
public void test100RecomputeAll() throws Exception {
final String TEST_NAME = "test100RecomputeAll";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
// Preconditions
assertUsers(5);
assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
// Do some ordinary operations
assignRole(USER_GUYBRUSH_OID, ROLE_PIRATE_OID, task, result);
assignRole(USER_JACK_OID, ROLE_JUDGE_OID, task, result);
addObject(USER_HERMAN_FILE);
assignRole(USER_HERMAN_OID, ROLE_JUDGE_OID, task, result);
result.computeStatus();
TestUtil.assertSuccess(result);
// Now do something evil
// change definition of role "pirate". midPoint will not recompute automatically
// the recompute task should do it
// One simple change
modifyRoleAddConstruction(ROLE_JUDGE_OID, 1111L, RESOURCE_DUMMY_RED_OID);
// More complicated change
PrismObject<RoleType> rolePirate = modelService.getObject(RoleType.class, ROLE_PIRATE_OID, null, task, result);
ItemPath attrItemPath = new ItemPath(new NameItemPathSegment(RoleType.F_INDUCEMENT), new IdItemPathSegment(1111L), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION), new IdItemPathSegment(60004L), new NameItemPathSegment(ConstructionType.F_ATTRIBUTE));
PrismProperty<ResourceAttributeDefinitionType> attributeProperty = rolePirate.findProperty(attrItemPath);
assertNotNull("No attribute property in " + rolePirate);
PrismPropertyValue<ResourceAttributeDefinitionType> oldAttrPVal = null;
for (PrismPropertyValue<ResourceAttributeDefinitionType> pval : attributeProperty.getValues()) {
ResourceAttributeDefinitionType attrType = pval.getValue();
if (ItemPathUtil.getOnlySegmentQName(attrType.getRef()).getLocalPart().equals(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME)) {
oldAttrPVal = pval;
}
}
assertNotNull("Definition for weapon attribute not found in " + rolePirate);
PrismPropertyValue<ResourceAttributeDefinitionType> newAttrPVal = oldAttrPVal.clone();
JAXBElement<?> cutlassExpressionEvalJaxbElement = newAttrPVal.getValue().getOutbound().getExpression().getExpressionEvaluator().get(0);
RawType cutlassValueEvaluator = (RawType) cutlassExpressionEvalJaxbElement.getValue();
RawType daggerValueEvaluator = new RawType(new PrimitiveXNode<String>("dagger"), prismContext);
JAXBElement<?> daggerExpressionEvalJaxbElement = new JAXBElement<Object>(SchemaConstants.C_VALUE, Object.class, daggerValueEvaluator);
newAttrPVal.getValue().getOutbound().getExpression().getExpressionEvaluator().add(daggerExpressionEvalJaxbElement);
newAttrPVal.getValue().getOutbound().setStrength(MappingStrengthType.STRONG);
ObjectDelta<RoleType> rolePirateDelta = ObjectDelta.createModificationDeleteProperty(RoleType.class, ROLE_PIRATE_OID, attrItemPath, prismContext, oldAttrPVal.getValue());
IntegrationTestTools.displayJaxb("AAAAAAAAAAA", newAttrPVal.getValue(), ConstructionType.F_ATTRIBUTE);
display("BBBBBB", newAttrPVal.getValue().toString());
rolePirateDelta.addModificationAddProperty(attrItemPath, newAttrPVal.getValue());
display("Role pirate delta", rolePirateDelta);
modelService.executeChanges(MiscSchemaUtil.createCollection(rolePirateDelta), null, task, result);
displayRoles(task, result);
assertDummyAccount(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", true);
assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User jack (before)", userJack);
assertDummyAccount(null, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
result.computeStatus();
TestUtil.assertSuccess(result);
// WHEN
TestUtil.displayWhen(TEST_NAME);
addObject(TASK_USER_RECOMPUTE_FILE);
dummyAuditService.clear();
waitForTaskStart(TASK_USER_RECOMPUTE_OID, false);
// WHEN
TestUtil.displayWhen(TEST_NAME);
waitForTaskFinish(TASK_USER_RECOMPUTE_OID, true, 40000);
// THEN
TestUtil.displayThen(TEST_NAME);
List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, null, null, task, result);
display("Users after recompute", users);
assertDummyAccount(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", true);
assertDummyAccountAttribute(null, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "cutlass", "dagger");
assertNoDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
userJack = getUser(USER_JACK_OID);
display("User jack (after)", userJack);
assertNoDummyAccount(null, ACCOUNT_JACK_DUMMY_USERNAME);
assertDummyAccount(RESOURCE_DUMMY_RED_NAME, ACCOUNT_JACK_DUMMY_USERNAME, "Jack Sparrow", true);
assertUsers(6);
// Check audit
display("Audit", dummyAuditService);
List<AuditEventRecord> auditRecords = dummyAuditService.getRecords();
int i = 0;
int modifications = 0;
for (; i < (auditRecords.size() - 1); i += 2) {
AuditEventRecord requestRecord = auditRecords.get(i);
assertNotNull("No request audit record (" + i + ")", requestRecord);
assertEquals("Got this instead of request audit record (" + i + "): " + requestRecord, AuditEventStage.REQUEST, requestRecord.getEventStage());
assertTrue("Unexpected delta in request audit record " + requestRecord, requestRecord.getDeltas() == null || requestRecord.getDeltas().isEmpty());
AuditEventRecord executionRecord = auditRecords.get(i + 1);
assertNotNull("No execution audit record (" + i + ")", executionRecord);
assertEquals("Got this instead of execution audit record (" + i + "): " + executionRecord, AuditEventStage.EXECUTION, executionRecord.getEventStage());
assertTrue("Empty deltas in execution audit record " + executionRecord, executionRecord.getDeltas() != null && !executionRecord.getDeltas().isEmpty());
modifications++;
// check next records
while (i < (auditRecords.size() - 2)) {
AuditEventRecord nextRecord = auditRecords.get(i + 2);
if (nextRecord.getEventStage() == AuditEventStage.EXECUTION) {
// more than one execution record is OK
i++;
} else {
break;
}
}
}
assertEquals("Unexpected number of audit modifications", 6, modifications);
deleteObject(TaskType.class, TASK_USER_RECOMPUTE_OID, task, result);
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class TestValidityRecomputeTask method test146BarbossaDisableBothRedAssignments.
@Test
public void test146BarbossaDisableBothRedAssignments() throws Exception {
final String TEST_NAME = "test146BarbossaDisableBothRedAssignments";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TestValidityRecomputeTask.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
AssignmentType judgeAssignment = getUserAssignment(USER_BARBOSSA_OID, ROLE_RED_JUDGE_OID);
AssignmentType sailorAssignment = getUserAssignment(USER_BARBOSSA_OID, ROLE_RED_SAILOR_OID);
ObjectDelta<UserType> objectDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_BARBOSSA_OID, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(judgeAssignment.getId()), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_ADMINISTRATIVE_STATUS)), prismContext, ActivationStatusType.DISABLED);
objectDelta.addModificationReplaceProperty(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(sailorAssignment.getId()), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_ADMINISTRATIVE_STATUS)), ActivationStatusType.DISABLED);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(MiscSchemaUtil.createCollection(objectDelta), null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
assertDummyAccount(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, false);
// WHEN
TestUtil.displayWhen(TEST_NAME);
waitForTaskNextRunAssertSuccess(TASK_VALIDITY_SCANNER_OID, true);
// THEN
TestUtil.displayThen(TEST_NAME);
assertDummyAccount(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, false);
assertNoDummyAccountAttribute(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME);
assertNoDummyAccountAttribute(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME);
PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
display("User after", user);
assertLinks(user, 1);
MidPointPrincipal principal = userProfileService.getPrincipal(user);
assertNotAuthorized(principal, AUTZ_PUNISH_URL);
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class TestValidityRecomputeTask method test149BarbossaDisableBothRedAssignmentsUnassign.
/**
* Unassign disabled assignments.
*/
@Test
public void test149BarbossaDisableBothRedAssignmentsUnassign() throws Exception {
final String TEST_NAME = "test149BarbossaDisableBothRedAssignmentsUnassign";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TestValidityRecomputeTask.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
AssignmentType judgeAssignment = getUserAssignment(USER_BARBOSSA_OID, ROLE_RED_JUDGE_OID);
AssignmentType judgeAssignmentLight = new AssignmentType();
judgeAssignmentLight.setId(judgeAssignment.getId());
AssignmentType sailorAssignment = getUserAssignment(USER_BARBOSSA_OID, ROLE_RED_SAILOR_OID);
AssignmentType sailorAssignmentLight = new AssignmentType();
sailorAssignmentLight.setId(sailorAssignment.getId());
ObjectDelta<UserType> objectDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_BARBOSSA_OID, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(judgeAssignment.getId()), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_ADMINISTRATIVE_STATUS)), prismContext, ActivationStatusType.DISABLED);
objectDelta.addModificationReplaceProperty(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(sailorAssignment.getId()), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_ADMINISTRATIVE_STATUS)), ActivationStatusType.DISABLED);
modelService.executeChanges(MiscSchemaUtil.createCollection(objectDelta), null, task, result);
assertNoDummyAccount(null, USER_BARBOSSA_USERNAME);
waitForTaskNextRunAssertSuccess(TASK_VALIDITY_SCANNER_OID, true);
assertNoDummyAccount(null, USER_BARBOSSA_USERNAME);
PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
display("User after", user);
assertLinks(user, 1);
MidPointPrincipal principal = userProfileService.getPrincipal(user);
assertNotAuthorized(principal, AUTZ_PUNISH_URL);
objectDelta = ObjectDelta.createModificationDeleteContainer(UserType.class, USER_BARBOSSA_OID, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT)), prismContext, judgeAssignmentLight);
objectDelta.addModificationDeleteContainer(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT)), sailorAssignmentLight);
display("Unassign delta", objectDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(MiscSchemaUtil.createCollection(objectDelta), null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
assertDummyAccount(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, false);
// to be on the safe side
assertNoDummyAccount(null, USER_BARBOSSA_USERNAME);
// WHEN
TestUtil.displayWhen(TEST_NAME);
waitForTaskNextRunAssertSuccess(TASK_VALIDITY_SCANNER_OID, true);
// THEN
TestUtil.displayThen(TEST_NAME);
assertDummyAccount(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, false);
assertNoDummyAccountAttribute(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME);
assertNoDummyAccountAttribute(RESOURCE_DUMMY_RED_NAME, USER_BARBOSSA_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME);
// to be on the safe side
assertNoDummyAccount(null, USER_BARBOSSA_USERNAME);
user = getUser(USER_BARBOSSA_OID);
display("User after", user);
assertLinks(user, 1);
assertNoAssignments(user);
principal = userProfileService.getPrincipal(user);
assertNotAuthorized(principal, AUTZ_PUNISH_URL);
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class TestValidityRecomputeTask method test125JackDeleteAdministrativeStatusAssignmentJudge.
@Test
public void test125JackDeleteAdministrativeStatusAssignmentJudge() throws Exception {
final String TEST_NAME = "test125JackDeleteAdministrativeStatusAssignmentJudge";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TestValidityRecomputeTask.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assertDummyAccount(null, USER_JACK_USERNAME);
AssignmentType judgeAssignment = getJudgeAssignment(USER_JACK_OID);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modifyObjectDeleteProperty(UserType.class, USER_JACK_OID, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(judgeAssignment.getId()), new NameItemPathSegment(AssignmentType.F_ACTIVATION), new NameItemPathSegment(ActivationType.F_ADMINISTRATIVE_STATUS)), task, result, ActivationStatusType.ENABLED);
// THEN
TestUtil.displayThen(TEST_NAME);
PrismObject<UserType> user = getUser(USER_JACK_OID);
display("User after", user);
assertDummyAccount(null, USER_JACK_USERNAME);
assert11xUserOk(user);
}
Aggregations