Search in sources :

Example 26 with IdItemPathSegment

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

Example 27 with IdItemPathSegment

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]);
        }
    }
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) QName(javax.xml.namespace.QName) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment)

Example 28 with IdItemPathSegment

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));
}
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 29 with IdItemPathSegment

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
}
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 30 with IdItemPathSegment

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);
}
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)

Aggregations

IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)35 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)30 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)27 Test (org.testng.annotations.Test)17 QName (javax.xml.namespace.QName)8 UserType (com.evolveum.midpoint.prism.foo.UserType)6 ItemPathSegment (com.evolveum.midpoint.prism.path.ItemPathSegment)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)5 AssignmentType (com.evolveum.midpoint.prism.foo.AssignmentType)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)3 ObjectReferencePathSegment (com.evolveum.midpoint.prism.path.ObjectReferencePathSegment)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)2 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)2 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)2