Search in sources :

Example 1 with IdItemPathSegment

use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.

the class TestDiff method testContainerDiffModificationsDesciption.

@Test
public void testContainerDiffModificationsDesciption() throws Exception {
    System.out.println("\n\n===[ testContainerDiffModificationsDesciption ]===\n");
    // GIVEN
    PrismObjectDefinition<UserType> userDef = getUserTypeDefinition();
    PrismContainerDefinition<AssignmentType> assignmentContDef = userDef.findContainerDefinition(UserType.F_ASSIGNMENT);
    PrismContainer<AssignmentType> ass1 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass1cval = ass1.createNewValue();
    ass1cval.setId(1L);
    ass1cval.setPropertyRealValue(AssignmentType.F_DESCRIPTION, "blah blah", PrismTestUtil.getPrismContext());
    PrismContainer<AssignmentType> ass2 = assignmentContDef.instantiate();
    PrismContainerValue<AssignmentType> ass2cval = ass2.createNewValue();
    ass2cval.setId(1L);
    ass2cval.setPropertyRealValue(AssignmentType.F_DESCRIPTION, "chamalalia patlama paprtala", PrismTestUtil.getPrismContext());
    // WHEN
    Collection<? extends ItemDelta> modifications = ass1.diffModifications(ass2);
    // THEN
    assertNotNull(modifications);
    System.out.println(DebugUtil.debugDump(modifications));
    assertEquals("Unexpected number of midifications", 1, modifications.size());
    PrismAsserts.assertPropertyReplace(modifications, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(1L), new NameItemPathSegment(AssignmentType.F_DESCRIPTION)), "chamalalia patlama paprtala");
    ItemDelta.checkConsistence(modifications);
}
Also used : 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 2 with IdItemPathSegment

use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.

the class TestPath method testPathRemainder.

@Test
public void testPathRemainder() throws Exception {
    System.out.println("\n\n===[ testPathRemainder ]===\n");
    // GIVEN
    ItemPath pathFoo = new ItemPath(new QName(NS, "foo"));
    ItemPath pathBar = new ItemPath(new QName(NS, "bar"));
    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 pathFooNullBar = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment(), new NameItemPathSegment(new QName(NS, "bar")));
    // WHEN
    ItemPath remainder1 = pathFooBar.remainder(pathFooNull);
    // THEN
    assertEquals("Remainder fooBar, fooNull", pathBar, remainder1);
}
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 3 with IdItemPathSegment

use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.

the class TestFind method testFindAssignment1Description.

@Test
public void testFindAssignment1Description() throws SchemaException, SAXException, IOException {
    final String TEST_NAME = "testFindAssignment1Description";
    System.out.println("===[ " + TEST_NAME + " ]===");
    // GIVEN
    ItemPath path = new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(USER_ASSIGNMENT_1_ID), new NameItemPathSegment(AssignmentType.F_DESCRIPTION));
    // WHEN
    PrismProperty<String> property = findUserProperty(path);
    // THEN
    assertEquals("Wrong property value (path=" + path + ")", "Assignment 1", property.getRealValue());
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 4 with IdItemPathSegment

use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.

the class TestPath method testPathNormalize.

@Test
public void testPathNormalize() throws Exception {
    System.out.println("\n\n===[ testPathNormalize ]===\n");
    // GIVEN
    ItemPath path1 = new ItemPath(new QName(NS, "foo"), new QName(NS, "bar"));
    ItemPath path2 = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment(123L), new NameItemPathSegment(new QName(NS, "bar")));
    ItemPath path22 = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment(123L), new NameItemPathSegment(new QName(NS, "bar")), new IdItemPathSegment(null));
    ItemPath path3 = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment(123L), new NameItemPathSegment(new QName(NS, "bar")), new IdItemPathSegment(333L));
    ItemPath path4 = new ItemPath(new QName(NS, "x"));
    ItemPath path5 = new ItemPath(new NameItemPathSegment(new QName(NS, "foo")), new IdItemPathSegment(123L));
    ItemPath pathE = new ItemPath();
    // WHEN
    ItemPath normalized1 = path1.normalize();
    ItemPath normalized2 = path2.normalize();
    ItemPath normalized22 = path22.normalize();
    ItemPath normalized3 = path3.normalize();
    ItemPath normalized4 = path4.normalize();
    ItemPath normalized5 = path5.normalize();
    ItemPath normalizedE = pathE.normalize();
    // THEN
    System.out.println("Normalized path 1:" + normalized1);
    System.out.println("Normalized path 2:" + normalized2);
    System.out.println("Normalized path 22:" + normalized22);
    System.out.println("Normalized path 3:" + normalized3);
    System.out.println("Normalized path 4:" + normalized4);
    System.out.println("Normalized path 5:" + normalized5);
    System.out.println("Normalized path E:" + normalizedE);
    assertNormalizedPath(normalized1, "foo", null, "bar");
    assertNormalizedPath(normalized2, "foo", 123L, "bar");
    assertNormalizedPath(normalized22, "foo", 123L, "bar", null);
    assertNormalizedPath(normalized3, "foo", 123L, "bar", 333L);
    assertNormalizedPath(normalized4, "x");
    assertNormalizedPath(normalized5, "foo", 123L);
    assert normalizedE.isEmpty() : "normalizedE is not empty";
}
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 5 with IdItemPathSegment

use of com.evolveum.midpoint.prism.path.IdItemPathSegment in project midpoint by Evolveum.

the class PrismInternalTestUtil method assertUserJackContent.

public static void assertUserJackContent(PrismObject<UserType> user, boolean expectRawInConstructions) throws SchemaException {
    assertEquals("Wrong oid", USER_JACK_OID, user.getOid());
    assertEquals("Wrong version", "42", user.getVersion());
    PrismAsserts.assertObjectDefinition(user.getDefinition(), USER_QNAME, USER_TYPE_QNAME, UserType.class);
    PrismAsserts.assertParentConsistency(user);
    assertPropertyValue(user, "fullName", "cpt. Jack Sparrow");
    assertPropertyDefinition(user, "fullName", DOMUtil.XSD_STRING, 1, 1);
    assertPropertyValue(user, "givenName", "Jack");
    assertPropertyDefinition(user, "givenName", DOMUtil.XSD_STRING, 0, 1);
    assertPropertyValue(user, "familyName", "Sparrow");
    assertPropertyDefinition(user, "familyName", DOMUtil.XSD_STRING, 0, 1);
    assertPropertyValue(user, "name", new PolyString("jack", "jack"));
    assertPropertyDefinition(user, "name", PolyStringType.COMPLEX_TYPE, 0, 1);
    assertPropertyValue(user, "special", "got it!");
    assertPropertyDefinition(user, "special", DOMUtil.XSD_STRING, 0, 1);
    assertPropertyValue(user, "polyName", new PolyString("Džek Sperou", "dzek sperou"));
    assertPropertyDefinition(user, "polyName", PolyStringType.COMPLEX_TYPE, 0, 1);
    ItemPath enabledPath = USER_ENABLED_PATH;
    PrismProperty<Boolean> enabledProperty1 = user.findProperty(enabledPath);
    assertNotNull("No enabled property", enabledProperty1);
    PrismAsserts.assertDefinition(enabledProperty1.getDefinition(), USER_ENABLED_QNAME, DOMUtil.XSD_BOOLEAN, 0, 1);
    assertNotNull("Property " + enabledPath + " not found", enabledProperty1);
    PrismAsserts.assertPropertyValue(enabledProperty1, true);
    PrismProperty<XMLGregorianCalendar> validFromProperty = user.findProperty(USER_VALID_FROM_PATH);
    assertNotNull("Property " + USER_VALID_FROM_PATH + " not found", validFromProperty);
    PrismAsserts.assertPropertyValue(validFromProperty, USER_JACK_VALID_FROM);
    QName actName = new QName(NS_FOO, "activation");
    // Use path
    ItemPath actPath = new ItemPath(actName);
    PrismContainer<ActivationType> actContainer1 = user.findContainer(actPath);
    assertContainerDefinition(actContainer1, "activation", ACTIVATION_TYPE_QNAME, 0, 1);
    assertNotNull("Property " + actPath + " not found", actContainer1);
    assertEquals("Wrong activation name", actName, actContainer1.getElementName());
    // Use name
    PrismContainer<ActivationType> actContainer2 = user.findContainer(actName);
    assertNotNull("Property " + actName + " not found", actContainer2);
    assertEquals("Wrong activation name", actName, actContainer2.getElementName());
    // Compare
    assertEquals("Eh?", actContainer1, actContainer2);
    PrismProperty<Boolean> enabledProperty2 = actContainer1.findProperty(new QName(NS_FOO, "enabled"));
    assertNotNull("Property enabled not found", enabledProperty2);
    PrismAsserts.assertPropertyValue(enabledProperty2, true);
    assertEquals("Eh?", enabledProperty1, enabledProperty2);
    QName assName = new QName(NS_FOO, "assignment");
    QName descriptionName = new QName(NS_FOO, "description");
    QName accountConstructionName = new QName(NS_FOO, "accountConstruction");
    PrismContainer<AssignmentType> assContainer = user.findContainer(assName);
    assertEquals("Wrong assignement values", 2, assContainer.getValues().size());
    PrismProperty<String> a2DescProperty = assContainer.getValue(USER_ASSIGNMENT_2_ID).findProperty(descriptionName);
    assertEquals("Wrong assigment 2 description", "Assignment 2", a2DescProperty.getValue().getValue());
    ItemPath a1Path = new ItemPath(new NameItemPathSegment(assName), new IdItemPathSegment(USER_ASSIGNMENT_1_ID), new NameItemPathSegment(descriptionName));
    PrismProperty a1Property = user.findProperty(a1Path);
    assertNotNull("Property " + a1Path + " not found", a1Property);
    PrismAsserts.assertPropertyValue(a1Property, "Assignment 1");
    ItemPath a2Path = new ItemPath(new NameItemPathSegment(assName), new IdItemPathSegment(USER_ASSIGNMENT_2_ID), new NameItemPathSegment(accountConstructionName));
    PrismProperty a2Property = user.findProperty(a2Path);
    assertNotNull("Property " + a2Path + " not found", a2Property);
    AccountConstructionType accountConstructionType = (AccountConstructionType) a2Property.getRealValue();
    assertEquals("Wrong number of values in accountConstruction", 2, accountConstructionType.getValue().size());
    RawType value1 = accountConstructionType.getValue().get(0).clone();
    if (expectRawInConstructions) {
        assertNotNull("Value #1 has no XNode present", value1.getXnode());
        PrismPropertyDefinition value1def = new PrismPropertyDefinitionImpl(// element name
        new QName(NS_FOO, "dummy"), // type name
        DOMUtil.XSD_STRING, user.getPrismContext());
        PrismPropertyValue<String> prismValue1 = value1.getParsedValue(value1def, value1def.getName());
        assertEquals("Wrong value #1", "ABC", prismValue1.getValue());
    } else {
        assertNull("Value #1 has XNode present", value1.getXnode());
        assertEquals("Wrong value #1", "ABC", value1.getParsedRealValue(String.class));
    }
    RawType value2 = accountConstructionType.getValue().get(1).clone();
    assertNotNull("Value #2 has no XNode present", value2.getXnode());
    PrismValue prismValue2 = value2.getParsedValue(user.getDefinition(), user.getDefinition().getName());
    PrismContainerValue<UserType> prismUserValue2 = (PrismContainerValue<UserType>) prismValue2;
    assertEquals("Wrong value #2", "Nobody", prismUserValue2.findProperty(new QName(NS_FOO, "fullName")).getRealValue());
    PrismReference accountRef = user.findReference(USER_ACCOUNTREF_QNAME);
    assertNotNull("Reference " + USER_ACCOUNTREF_QNAME + " not found", accountRef);
    assertEquals("Wrong number of accountRef values", 3, accountRef.getValues().size());
    PrismAsserts.assertReferenceValue(accountRef, "c0c010c0-d34d-b33f-f00d-aaaaaaaa1111");
    PrismAsserts.assertReferenceValue(accountRef, "c0c010c0-d34d-b33f-f00d-aaaaaaaa1112");
    PrismAsserts.assertReferenceValue(accountRef, "c0c010c0-d34d-b33f-f00d-aaaaaaaa1113");
    PrismReferenceValue accountRefVal2 = accountRef.findValueByOid("c0c010c0-d34d-b33f-f00d-aaaaaaaa1112");
    assertEquals("Wrong oid for accountRef", "c0c010c0-d34d-b33f-f00d-aaaaaaaa1112", accountRefVal2.getOid());
    assertEquals("Wrong accountRef description", "This is a reference with a filter", accountRefVal2.getDescription());
    assertNotNull("No filter in accountRef", accountRefVal2.getFilter());
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) AccountConstructionType(com.evolveum.midpoint.prism.foo.AccountConstructionType) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) QName(javax.xml.namespace.QName) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ActivationType(com.evolveum.midpoint.prism.foo.ActivationType) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AssignmentType(com.evolveum.midpoint.prism.foo.AssignmentType) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

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