use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.
the class TestFind method testFindAssignment2Construction.
@Test
public void testFindAssignment2Construction() throws SchemaException, SAXException, IOException {
final String TEST_NAME = "testFindAssignment2ConstructionHowto";
System.out.println("===[ " + TEST_NAME + " ]===");
// GIVEN
ItemPath path = new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(USER_ASSIGNMENT_2_ID), new NameItemPathSegment(AssignmentType.F_ACCOUNT_CONSTRUCTION));
// WHEN
PrismProperty<AccountConstructionType> property = findUserProperty(path);
// THEN
assertEquals("Wrong property value (path=" + path + ")", "Just do it", property.getRealValue().getHowto());
}
use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.
the class TestPath method assertNormalizedPath.
private void assertNormalizedPath(ItemPath normalized, Object... expected) {
assertEquals("wrong path length", normalized.size(), expected.length);
for (int i = 0; i < normalized.size(); i += 2) {
ItemPathSegment nameSegment = normalized.getSegments().get(i);
assert nameSegment instanceof NameItemPathSegment : "Expected name segment but it was " + nameSegment.getClass();
QName name = ((NameItemPathSegment) nameSegment).getName();
assert name != null : "name is null";
assert name.getNamespaceURI().equals(NS) : "wrong namespace: " + name.getNamespaceURI();
assert name.getLocalPart().equals(expected[i]) : "wrong local name, expected " + expected[i] + ", was " + name.getLocalPart();
if (i + 1 < expected.length) {
ItemPathSegment idSegment = normalized.getSegments().get(i + 1);
assert idSegment instanceof IdItemPathSegment : "Expected is segment but it was " + nameSegment.getClass();
Long id = ((IdItemPathSegment) idSegment).getId();
assertId(id, (Long) expected[i + 1]);
}
}
}
use of com.evolveum.midpoint.prism.path.IdItemPathSegment 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.IdItemPathSegment 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.IdItemPathSegment 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);
}
Aggregations