Search in sources :

Example 46 with NameItemPathSegment

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));
}
Also used : QName(javax.xml.namespace.QName) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 47 with NameItemPathSegment

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
}
Also used : ActivationType(com.evolveum.midpoint.prism.foo.ActivationType) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) AssignmentType(com.evolveum.midpoint.prism.foo.AssignmentType) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 48 with NameItemPathSegment

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);
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) AssignmentType(com.evolveum.midpoint.prism.foo.AssignmentType) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 49 with NameItemPathSegment

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);
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 50 with NameItemPathSegment

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
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)69 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)61 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)46 Test (org.testng.annotations.Test)35 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)22 QName (javax.xml.namespace.QName)20 Task (com.evolveum.midpoint.task.api.Task)19 ItemPathSegment (com.evolveum.midpoint.prism.path.ItemPathSegment)15 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)14 TestTriggerTask (com.evolveum.midpoint.model.intest.TestTriggerTask)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)10 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)10 UserType (com.evolveum.midpoint.prism.foo.UserType)7 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)7 AssignmentType (com.evolveum.midpoint.prism.foo.AssignmentType)6 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)6 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)5 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)4