use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.
the class PrismInternalTestUtil method assertUserJack.
public static void assertUserJack(PrismObject<UserType> user, boolean expectRawInConstructions) throws SchemaException {
user.checkConsistence();
user.assertDefinitions("test");
assertUserJackContent(user, expectRawInConstructions);
assertUserJackExtension(user);
assertVisitor(user, 71);
assertPathVisitor(user, new ItemPath(UserType.F_ASSIGNMENT), true, 9);
assertPathVisitor(user, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(USER_ASSIGNMENT_1_ID)), true, 3);
assertPathVisitor(user, new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ENABLED), true, 2);
assertPathVisitor(user, new ItemPath(UserType.F_EXTENSION), true, 15);
assertPathVisitor(user, new ItemPath(UserType.F_ASSIGNMENT), false, 1);
assertPathVisitor(user, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(USER_ASSIGNMENT_1_ID)), false, 1);
assertPathVisitor(user, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), IdItemPathSegment.WILDCARD), false, 2);
assertPathVisitor(user, new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ENABLED), false, 1);
assertPathVisitor(user, new ItemPath(UserType.F_EXTENSION), false, 1);
assertPathVisitor(user, new ItemPath(new NameItemPathSegment(UserType.F_EXTENSION), NameItemPathSegment.WILDCARD), false, 5);
}
use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.
the class TestCompare method testDiffJackLiteral.
/**
* Parse original jack and modified Jack. Diff and assert if the resulting
* delta is OK.
* This is literal diff. All the changes should be part of the resulting delta.
*/
@Test
public void testDiffJackLiteral() throws Exception {
System.out.println("===[ testDiffJackLiteral ]===");
// GIVEN
PrismContext prismContext = constructInitializedPrismContext();
PrismObject<UserType> jackOriginal = prismContext.parseObject(getFile(USER_JACK_FILE_BASENAME));
PrismObject<UserType> jackModified = prismContext.parseObject(getFile(USER_JACK_MODIFIED_FILE_BASENAME));
// WHEN
ObjectDelta<UserType> jackDelta = jackOriginal.diff(jackModified, true, true);
// THEN
System.out.println("Jack delta:");
System.out.println(jackDelta.debugDump());
jackDelta.assertDefinitions();
jackDelta.checkConsistence(true, true, true);
assertEquals("Wrong delta type", ChangeType.MODIFY, jackDelta.getChangeType());
assertEquals("Wrong delta OID", USER_JACK_OID, jackDelta.getOid());
assertEquals("Wrong number of modificaitions", 10, jackDelta.getModifications().size());
PrismAsserts.assertPropertyReplace(jackDelta, USER_FULLNAME_QNAME, "Jack Sparrow");
PrismAsserts.assertPropertyDelete(jackDelta, new ItemPath(USER_EXTENSION_QNAME, EXTENSION_MULTI_ELEMENT), "dva");
PrismAsserts.assertPropertyAdd(jackDelta, new ItemPath(USER_EXTENSION_QNAME, EXTENSION_MULTI_ELEMENT), "osem");
// TODO: assert BAR
PrismAsserts.assertPropertyDelete(jackDelta, USER_ADDITIONALNAMES_QNAME, "Captain");
PrismAsserts.assertPropertyAdd(jackDelta, USER_LOCALITY_QNAME, "World's End");
PrismAsserts.assertPropertyReplace(jackDelta, USER_ENABLED_PATH, false);
PrismAsserts.assertPropertyDelete(jackDelta, USER_VALID_FROM_PATH, USER_JACK_VALID_FROM);
PrismAsserts.assertPropertyReplace(jackDelta, new ItemPath(new NameItemPathSegment(USER_ASSIGNMENT_QNAME), new IdItemPathSegment(USER_ASSIGNMENT_2_ID), new NameItemPathSegment(USER_DESCRIPTION_QNAME)), "Assignment II");
ContainerDelta<?> assignment3Delta = PrismAsserts.assertContainerAddGetContainerDelta(jackDelta, new ItemPath(USER_ASSIGNMENT_QNAME));
PrismContainerValue<?> assignment3DeltaAddValue = assignment3Delta.getValuesToAdd().iterator().next();
assertEquals("Assignment 3 wrong ID", USER_ASSIGNMENT_3_ID, assignment3DeltaAddValue.getId());
// TODO assert assignment[i1112]/accountConstruction
}
use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.
the class TestSchemaDelta method testDeleteUserAssignmentActivationSameNullIdApplyToObject.
@Test
public void testDeleteUserAssignmentActivationSameNullIdApplyToObject() throws Exception {
final String TEST_NAME = "testDeleteUserAssignmentActivationSameNullIdApplyToObject";
displayTestTile(TEST_NAME);
// GIVEN
PrismObject<UserType> user = PrismTestUtil.parseObject(USER_JACK_FILE);
//Delta
ActivationType activationType = new ActivationType();
activationType.setAdministrativeStatus(ActivationStatusType.ENABLED);
// No container ID
ObjectDelta<UserType> userDelta = ObjectDelta.createModificationDeleteContainer(UserType.class, USER_JACK_OID, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(USER_JACK_ASSIGNMENT_ID), new NameItemPathSegment(AssignmentType.F_ACTIVATION)), getPrismContext(), activationType);
// WHEN
userDelta.applyTo(user);
// THEN
System.out.println("User after delta application:");
System.out.println(user.debugDump());
assertEquals("Wrong OID", USER_JACK_OID, user.getOid());
PrismAsserts.assertPropertyValue(user, UserType.F_NAME, PrismTestUtil.createPolyString(USER_JACK_NAME));
PrismContainer<AssignmentType> assignmentContainer = user.findContainer(RoleType.F_ASSIGNMENT);
assertNotNull("No assignment", assignmentContainer);
assertEquals("Unexpected number of assignment values", 1, assignmentContainer.size());
PrismContainerValue<AssignmentType> assignmentValue = assignmentContainer.getValues().iterator().next();
AssignmentType assignment = assignmentValue.asContainerable();
ActivationType assignmentActivation = assignment.getActivation();
// activation should be gone (the error is that it is empty and not gone)
assertNull("Assignment activation is not gone", assignmentActivation);
ActivationType activation = user.asObjectable().getActivation();
assertNotNull("Activation missing", activation);
assertEquals("Wrong activation administrativeStatus", ActivationStatusType.ENABLED, activation.getAdministrativeStatus());
}
use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.
the class TestAbstractAssignmentEvaluator method test120DirectExpressionReplaceDescription.
@Test
public void test120DirectExpressionReplaceDescription() throws Exception {
final String TEST_NAME = "test120DirectExpressionReplaceDescription";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> user = userTypeJack.asPrismObject().clone();
AssignmentType assignmentType = unmarshallValueFromFile(ASSIGNMENT_DIRECT_EXPRESSION_FILE, AssignmentType.class);
user.asObjectable().getAssignment().add(assignmentType.clone());
ItemPath path = new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(123L), new NameItemPathSegment(AssignmentType.F_DESCRIPTION));
ObjectDelta<UserType> userDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_JACK_OID, path, prismContext, "captain");
ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(user, userDelta, null);
userOdo.recompute();
AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
assignmentIdi.setSubItemDeltas(userDelta.getModifications());
assignmentIdi.recompute();
// WHEN
TestUtil.displayWhen(TEST_NAME);
EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, "testDirect", task, result);
evaluatedAssignment.evaluateConstructions(userOdo, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertNotNull(evaluatedAssignment);
display("Evaluated assignment", evaluatedAssignment);
assertEquals(1, evaluatedAssignment.getConstructionTriple().size());
PrismAsserts.assertParentConsistency(user);
Construction<UserType> construction = evaluatedAssignment.getConstructionTriple().getZeroSet().iterator().next();
assertNotNull("No object class definition in construction", construction.getRefinedObjectClassDefinition());
assertEquals(1, construction.getAttributeMappings().size());
Mapping<PrismPropertyValue<String>, PrismPropertyDefinition<String>> attributeMapping = (Mapping<PrismPropertyValue<String>, PrismPropertyDefinition<String>>) construction.getAttributeMappings().iterator().next();
PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = attributeMapping.getOutputTriple();
PrismAsserts.assertTripleNoZero(outputTriple);
PrismAsserts.assertTriplePlus(outputTriple, "The best captain the world has ever seen");
PrismAsserts.assertTripleMinus(outputTriple, "The best pirate the world has ever seen");
// the same using other words
assertConstruction(evaluatedAssignment, ZERO, "title", ZERO);
assertConstruction(evaluatedAssignment, ZERO, "title", PLUS, "The best captain the world has ever seen");
assertConstruction(evaluatedAssignment, ZERO, "title", MINUS, "The best pirate the world has ever seen");
assertNoConstruction(evaluatedAssignment, PLUS, "title");
assertNoConstruction(evaluatedAssignment, MINUS, "title");
assertEquals("Wrong number of admin GUI configs", 0, evaluatedAssignment.getAdminGuiConfigurations().size());
}
use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.
the class ItemDelta method accept.
// TODO think if estimated old values have to be visited as well
@Override
public void accept(Visitor visitor, ItemPath path, boolean recursive) {
if (path == null || path.isEmpty()) {
if (recursive) {
accept(visitor);
} else {
visitor.visit(this);
}
} else {
IdItemPathSegment idSegment = ItemPath.getFirstIdSegment(path);
ItemPath rest = ItemPath.pathRestStartingWithName(path);
if (idSegment == null || idSegment.isWildcard()) {
// visit all values
if (getValuesToAdd() != null) {
for (V pval : getValuesToAdd()) {
pval.accept(visitor, rest, recursive);
}
}
if (getValuesToDelete() != null) {
for (V pval : getValuesToDelete()) {
pval.accept(visitor, rest, recursive);
}
}
if (getValuesToReplace() != null) {
for (V pval : getValuesToReplace()) {
pval.accept(visitor, rest, recursive);
}
}
} else {
Long id = idSegment.getId();
acceptSet(getValuesToAdd(), id, visitor, rest, recursive);
acceptSet(getValuesToDelete(), id, visitor, rest, recursive);
acceptSet(getValuesToReplace(), id, visitor, rest, recursive);
}
}
}
Aggregations