use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class TestPath method testPathCompare.
@Test
public void testPathCompare() throws Exception {
System.out.println("\n\n===[ testPathCompare ]===\n");
// GIVEN
ItemPath pathFoo = new ItemPath(new QName(NS, "foo"));
ItemPath pathFooNull = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment());
ItemPath pathFoo123 = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment(123L));
ItemPath pathFooBar = new ItemPath(new QName(NS, "foo"), new QName(NS, "bar"));
ItemPath pathFooBarBaz = new ItemPath(new QName(NS, "foo"), new QName(NS, "bar"), new QName(NS, "baz"));
ItemPath pathFooNullBar = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment(), new NameItemPathSegment(new QName(NS, "bar")));
ItemPath pathZoo = new ItemPath(new QName(NS, "zoo"));
List<ItemPath> onlyEmpty = Collections.singletonList(ItemPath.EMPTY_PATH);
List<ItemPath> onlyFoo = Collections.singletonList(pathFoo);
List<ItemPath> onlyFooBar = Collections.singletonList(pathFooBar);
// WHEN, THEN
assertTrue(pathFoo.isSubPath(pathFooNull));
assertFalse(pathFoo.equivalent(pathFoo123));
assertFalse(pathFooNull.equivalent(pathFoo123));
assertTrue(pathFoo.isSubPath(pathFooBar));
assertTrue(pathFooBar.isSuperPath(pathFoo));
assertTrue(pathFooBar.equivalent(pathFooNullBar));
assertTrue(ItemPath.EMPTY_PATH.isSubPath(pathFoo));
assertFalse(pathFoo.isSubPath(ItemPath.EMPTY_PATH));
assertTrue(ItemPath.containsSubpathOrEquivalent(onlyEmpty, pathFoo));
assertTrue(ItemPath.containsSubpath(onlyEmpty, pathFoo));
assertFalse(ItemPath.containsSuperpathOrEquivalent(onlyEmpty, pathFoo));
assertFalse(ItemPath.containsSuperpath(onlyEmpty, pathFoo));
assertTrue(ItemPath.containsSubpathOrEquivalent(onlyEmpty, ItemPath.EMPTY_PATH));
assertFalse(ItemPath.containsSubpath(onlyEmpty, ItemPath.EMPTY_PATH));
assertTrue(ItemPath.containsSuperpathOrEquivalent(onlyEmpty, ItemPath.EMPTY_PATH));
assertFalse(ItemPath.containsSuperpath(onlyEmpty, ItemPath.EMPTY_PATH));
assertTrue(ItemPath.containsSubpathOrEquivalent(onlyFoo, pathFoo));
assertFalse(ItemPath.containsSubpath(onlyFoo, pathFoo));
assertTrue(ItemPath.containsSuperpathOrEquivalent(onlyFoo, pathFoo));
assertFalse(ItemPath.containsSuperpath(onlyFoo, pathFoo));
assertFalse(ItemPath.containsSubpathOrEquivalent(onlyFoo, ItemPath.EMPTY_PATH));
assertFalse(ItemPath.containsSubpath(onlyFoo, ItemPath.EMPTY_PATH));
assertTrue(ItemPath.containsSuperpathOrEquivalent(onlyFoo, ItemPath.EMPTY_PATH));
assertTrue(ItemPath.containsSuperpath(onlyFoo, ItemPath.EMPTY_PATH));
assertFalse(ItemPath.containsSubpathOrEquivalent(onlyFoo, pathZoo));
assertFalse(ItemPath.containsSubpath(onlyFoo, pathZoo));
assertFalse(ItemPath.containsSuperpathOrEquivalent(onlyFoo, pathZoo));
assertFalse(ItemPath.containsSuperpath(onlyFoo, pathZoo));
assertFalse(ItemPath.containsSubpathOrEquivalent(onlyFooBar, pathFoo));
assertFalse(ItemPath.containsSubpath(onlyFooBar, pathFoo));
assertTrue(ItemPath.containsSuperpathOrEquivalent(onlyFooBar, pathFoo));
assertTrue(ItemPath.containsSuperpath(onlyFooBar, pathFoo));
assertTrue(ItemPath.containsSubpathOrEquivalent(onlyFooBar, pathFooBarBaz));
assertTrue(ItemPath.containsSubpath(onlyFooBar, pathFooBarBaz));
assertFalse(ItemPath.containsSuperpathOrEquivalent(onlyFooBar, pathFooBarBaz));
assertFalse(ItemPath.containsSuperpath(onlyFooBar, pathFooBarBaz));
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class TestDelta method testAddAssignmentActivationDifferentNullIdApplyToObject.
@Test
public void testAddAssignmentActivationDifferentNullIdApplyToObject() throws Exception {
System.out.println("\n\n===[ testAddAssignmentActivationDifferentNullIdApplyToObject ]===\n");
// GIVEN
// User
PrismObject<UserType> user = createUser();
//Delta
PrismContainerValue<ActivationType> activationValue = new PrismContainerValue<ActivationType>(PrismTestUtil.getPrismContext());
// The value id is null
activationValue.setPropertyRealValue(ActivationType.F_ENABLED, true, PrismTestUtil.getPrismContext());
ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddContainer(UserType.class, USER_FOO_OID, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), // We really need ID here. Otherwise it would not be clear to which assignment to add
new IdItemPathSegment(123L), new NameItemPathSegment(AssignmentType.F_ACTIVATION)), PrismTestUtil.getPrismContext(), activationValue);
// WHEN
userDelta.applyTo(user);
// THEN
System.out.println("User after delta application:");
System.out.println(user.debugDump());
assertEquals("Wrong OID", USER_FOO_OID, user.getOid());
PrismAsserts.assertPropertyValue(user, UserType.F_ADDITIONAL_NAMES, PrismTestUtil.createPolyString("foobar"));
PrismContainer<AssignmentType> assignment = user.findContainer(UserType.F_ASSIGNMENT);
assertNotNull("No assignment", assignment);
assertEquals("Unexpected number of assignment values", 1, assignment.size());
// TODO
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment in project midpoint by Evolveum.
the class TestDelta method testDeltaPaths.
@Test
public void testDeltaPaths() throws Exception {
System.out.println("\n\n===[ testDeltaPaths ]===\n");
PrismPropertyDefinition<String> descDefinition = new PrismPropertyDefinitionImpl<>(UserType.F_DESCRIPTION, DOMUtil.XSD_STRING, PrismTestUtil.getPrismContext());
PropertyDelta<String> delta1 = new PropertyDelta<String>(descDefinition, PrismTestUtil.getPrismContext());
delta1.addValueToAdd(new PrismPropertyValue<String>("add1"));
assertPath(delta1, new ItemPath(UserType.F_DESCRIPTION));
PrismReferenceDefinitionImpl referenceDefinition = new PrismReferenceDefinitionImpl(UserType.F_PARENT_ORG_REF, OBJECT_REFERENCE_TYPE_QNAME, PrismTestUtil.getPrismContext());
ReferenceDelta delta2 = new ReferenceDelta(referenceDefinition, PrismTestUtil.getPrismContext());
delta2.addValueToAdd(new PrismReferenceValue("oid1"));
assertPath(delta2, new ItemPath(UserType.F_PARENT_ORG_REF));
PrismContainerValue<AssignmentType> assignmentValue1 = new PrismContainerValue<AssignmentType>(PrismTestUtil.getPrismContext());
// The value id is null
assignmentValue1.setPropertyRealValue(AssignmentType.F_DESCRIPTION, "jamalalicha patlama paprtala", PrismTestUtil.getPrismContext());
ObjectDelta<UserType> assObjDelta1 = ObjectDelta.createModificationAddContainer(UserType.class, USER_FOO_OID, UserType.F_ASSIGNMENT, PrismTestUtil.getPrismContext(), assignmentValue1);
ItemDelta<?, ?> assDelta1 = assObjDelta1.getModifications().iterator().next();
assertPath(assDelta1, new ItemPath(UserType.F_ASSIGNMENT));
PrismContainerValue<AssignmentType> assignmentValue2 = new PrismContainerValue<AssignmentType>(PrismTestUtil.getPrismContext());
assignmentValue1.setId(USER_ASSIGNMENT_1_ID);
assignmentValue1.setPropertyRealValue(AssignmentType.F_DESCRIPTION, "jamalalicha patlama paprtala", PrismTestUtil.getPrismContext());
ObjectDelta<UserType> assObjDelta2 = ObjectDelta.createModificationAddContainer(UserType.class, USER_FOO_OID, UserType.F_ASSIGNMENT, PrismTestUtil.getPrismContext(), assignmentValue2);
ItemDelta<?, ?> assDelta2 = assObjDelta2.getModifications().iterator().next();
assertPath(assDelta2, new ItemPath(UserType.F_ASSIGNMENT));
PrismPropertyDefinition<String> assDescDefinition = new PrismPropertyDefinitionImpl<>(AssignmentType.F_DESCRIPTION, DOMUtil.XSD_STRING, PrismTestUtil.getPrismContext());
ItemPath itemPathAssDescNoId = new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_DESCRIPTION);
PropertyDelta<String> propDelta2 = new PropertyDelta<String>(itemPathAssDescNoId, descDefinition, PrismTestUtil.getPrismContext());
assertPath(propDelta2, itemPathAssDescNoId);
ItemPath itemPathAssDesc1Id = new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(USER_ASSIGNMENT_1_ID), new NameItemPathSegment(AssignmentType.F_DESCRIPTION));
PropertyDelta<String> propDelta3 = new PropertyDelta<String>(itemPathAssDesc1Id, descDefinition, PrismTestUtil.getPrismContext());
assertPath(propDelta3, itemPathAssDesc1Id);
}
use of com.evolveum.midpoint.prism.path.NameItemPathSegment 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.NameItemPathSegment 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
}
Aggregations