Search in sources :

Example 1 with UserType

use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.

the class AbstractLexicalProcessorTest method testParseUserRoundTrip.

@Test
public void testParseUserRoundTrip() throws Exception {
    final String TEST_NAME = "testParseUserRoundTrip";
    displayTestTitle(TEST_NAME);
    // GIVEN
    LexicalProcessor<String> lexicalProcessor = createParser();
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    // WHEN (parse)
    RootXNode xnode = lexicalProcessor.read(getFileSource(USER_JACK_FILE_BASENAME), ParsingContext.createDefault());
    System.out.println("\nParsed xnode:");
    System.out.println(xnode.debugDump());
    PrismObject<UserType> user = prismContext.parserFor(xnode).parse();
    // THEN
    System.out.println("\nParsed user:");
    System.out.println(user.debugDump());
    assertUserJack(user, true);
    // WHEN (re-serialize to XNode)
    RootXNode serializedXNode = prismContext.xnodeSerializer().options(SerializationOptions.createSerializeCompositeObjects()).serialize(user);
    String serializedString = lexicalProcessor.write(serializedXNode, new QName(NS_FOO, "user"), null);
    // THEN
    System.out.println("\nXNode after re-serialization:");
    System.out.println(serializedXNode.debugDump());
    System.out.println("\nRe-serialized string:");
    System.out.println(serializedString);
    String whenSerialized = getWhenItemSerialized();
    assertTrue("Serialized form does not contain " + whenSerialized, serializedString.contains(whenSerialized));
    assertUserJackXNodeOrdering("serialized xnode", serializedXNode);
    validateUserSchema(serializedString, prismContext);
    // WHEN (re-parse)
    RootXNode reparsedXnode = lexicalProcessor.read(new ParserStringSource(serializedString), ParsingContext.createDefault());
    PrismObject<UserType> reparsedUser = prismContext.parserFor(reparsedXnode).parse();
    // THEN
    System.out.println("\nXNode after re-parsing:");
    System.out.println(reparsedXnode.debugDump());
    System.out.println("\nRe-parsed user:");
    System.out.println(reparsedUser.debugDump());
    assertUserJackXNodeOrdering("serialized xnode", reparsedXnode);
    ObjectDelta<UserType> diff = DiffUtil.diff(user, reparsedUser);
    System.out.println("\nDiff:");
    System.out.println(diff.debugDump());
    PrismObject accountRefObjOrig = findObjectFromAccountRef(user);
    PrismObject accountRefObjRe = findObjectFromAccountRef(reparsedUser);
    ObjectDelta<UserType> accountRefObjDiff = DiffUtil.diff(accountRefObjOrig, accountRefObjRe);
    System.out.println("\naccountRef object diff:");
    System.out.println(accountRefObjDiff.debugDump());
    assertTrue("Re-parsed object in accountRef does not match: " + accountRefObjDiff, accountRefObjDiff.isEmpty());
    assertTrue("Re-parsed user does not match: " + diff, diff.isEmpty());
}
Also used : QName(javax.xml.namespace.QName) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.prism.foo.UserType) Test(org.testng.annotations.Test)

Example 2 with UserType

use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.

the class TestDelta method createDeltaForFindItem.

private ObjectDelta<UserType> createDeltaForFindItem() throws SchemaException {
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddProperty(UserType.class, USER_FOO_OID, UserType.F_LOCALITY, PrismTestUtil.getPrismContext(), "Caribbean");
    userDelta.addModificationReplaceProperty(UserType.F_GIVEN_NAME, "Guybrush");
    ContainerDelta<ActivationType> activationDelta = userDelta.createContainerModification(new ItemPath(UserType.F_ACTIVATION));
    PrismContainerValue<ActivationType> activationCVal = new PrismContainerValue();
    activationDelta.addValueToAdd(activationCVal);
    PrismProperty<Boolean> enabledProperty = activationCVal.createProperty(ActivationType.F_ENABLED);
    enabledProperty.setRealValue(Boolean.TRUE);
    PrismProperty<XMLGregorianCalendar> validFromProperty = activationCVal.createProperty(ActivationType.F_VALID_FROM);
    validFromProperty.setRealValue(XmlTypeConverter.createXMLGregorianCalendar(20016, 5, 16, 19, 8, 33));
    userDelta.addModification(activationDelta);
    return userDelta;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ActivationType(com.evolveum.midpoint.prism.foo.ActivationType) UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 3 with UserType

use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.

the class TestDelta method testObjectDeltaFindItemDeltaModifyPropertyInContainer.

@Test
public void testObjectDeltaFindItemDeltaModifyPropertyInContainer() throws Exception {
    System.out.println("\n\n===[ testObjectDeltaFindItemDeltaModifyPropertyInContainer ]===\n");
    // GIVEN
    ObjectDelta<UserType> userDelta = createDeltaForFindItem();
    System.out.println("Object delta:\n" + userDelta.debugDump());
    ItemPath itemDeltaPath = new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ENABLED);
    // WHEN
    ItemDelta<PrismValue, ItemDefinition> itemDelta = userDelta.findItemDelta(itemDeltaPath);
    // THEN
    System.out.println("Item delta:\n" + (itemDelta == null ? "null" : itemDelta.debugDump()));
    PrismAsserts.assertInstanceOf(PropertyDelta.class, itemDelta);
    assertEquals(itemDeltaPath, itemDelta.getPath());
    PrismAsserts.assertPropertyValues("Wrong add values in " + itemDelta, ((PropertyDelta) itemDelta).getValuesToAdd(), Boolean.TRUE);
}
Also used : UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 4 with UserType

use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.

the class TestDelta method testDeltaComplex.

@Test
public void testDeltaComplex() throws Exception {
    System.out.println("\n\n===[ testDeltaComplex ]===\n");
    // GIVEN
    ObjectDelta<UserType> delta = ObjectDelta.createModificationAddProperty(UserType.class, USER_FOO_OID, UserType.F_FULL_NAME, PrismTestUtil.getPrismContext(), PrismTestUtil.createPolyString("Foo Bar"));
    PrismObjectDefinition<UserType> userTypeDefinition = getUserTypeDefinition();
    PrismContainerDefinition<ActivationType> activationDefinition = userTypeDefinition.findContainerDefinition(UserType.F_ACTIVATION);
    PrismContainer<ActivationType> activationContainer = activationDefinition.instantiate();
    PrismPropertyDefinition enabledDef = activationDefinition.findPropertyDefinition(ActivationType.F_ENABLED);
    PrismProperty<Boolean> enabledProperty = enabledDef.instantiate();
    enabledProperty.setRealValue(true);
    activationContainer.add(enabledProperty);
    delta.addModificationDeleteContainer(UserType.F_ACTIVATION, activationContainer.getValue().clone());
    PrismContainerDefinition<AssignmentType> assDef = userTypeDefinition.findContainerDefinition(UserType.F_ASSIGNMENT);
    PrismPropertyDefinition descDef = assDef.findPropertyDefinition(AssignmentType.F_DESCRIPTION);
    PrismContainerValue<AssignmentType> assVal1 = new PrismContainerValue<AssignmentType>(PrismTestUtil.getPrismContext());
    assVal1.setId(111L);
    PrismProperty<String> descProp1 = descDef.instantiate();
    descProp1.setRealValue("desc 1");
    assVal1.add(descProp1);
    PrismContainerValue<AssignmentType> assVal2 = new PrismContainerValue<AssignmentType>(PrismTestUtil.getPrismContext());
    assVal2.setId(222L);
    PrismProperty<String> descProp2 = descDef.instantiate();
    descProp2.setRealValue("desc 2");
    assVal2.add(descProp2);
    delta.addModificationAddContainer(UserType.F_ASSIGNMENT, assVal1, assVal2);
    System.out.println("Delta:");
    System.out.println(delta.debugDump());
    // WHEN, THEN
    PrismInternalTestUtil.assertVisitor(delta, 14);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_FULL_NAME), true, 2);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_ACTIVATION), true, 4);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ENABLED), true, 2);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_ASSIGNMENT), true, 7);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), IdItemPathSegment.WILDCARD), true, 6);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_FULL_NAME), false, 1);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_ACTIVATION), false, 1);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ENABLED), false, 1);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(UserType.F_ASSIGNMENT), false, 1);
    PrismInternalTestUtil.assertPathVisitor(delta, new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), IdItemPathSegment.WILDCARD), false, 2);
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ActivationType(com.evolveum.midpoint.prism.foo.ActivationType) 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 5 with UserType

use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.

the class TestDelta method testObjectDeltaFindItemDeltaModifyProperty.

@Test
public void testObjectDeltaFindItemDeltaModifyProperty() throws Exception {
    System.out.println("\n\n===[ testObjectDeltaFindItemDeltaModifyProperty ]===\n");
    // GIVEN
    ObjectDelta<UserType> userDelta = createDeltaForFindItem();
    ItemPath itemDeltaPath = new ItemPath(UserType.F_GIVEN_NAME);
    // WHEN
    ItemDelta<PrismValue, ItemDefinition> itemDelta = userDelta.findItemDelta(itemDeltaPath);
    // THEN
    PrismAsserts.assertInstanceOf(PropertyDelta.class, itemDelta);
    assertEquals(itemDeltaPath, itemDelta.getPath());
    PrismAsserts.assertPropertyValues("Wrong replace values in " + itemDelta, ((PropertyDelta) itemDelta).getValuesToReplace(), "Guybrush");
}
Also used : UserType(com.evolveum.midpoint.prism.foo.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

UserType (com.evolveum.midpoint.prism.foo.UserType)30 Test (org.testng.annotations.Test)27 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)14 QName (javax.xml.namespace.QName)10 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 AssignmentType (com.evolveum.midpoint.prism.foo.AssignmentType)7 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)7 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)6 ActivationType (com.evolveum.midpoint.prism.foo.ActivationType)4 PrismInternalTestUtil.constructInitializedPrismContext (com.evolveum.midpoint.prism.PrismInternalTestUtil.constructInitializedPrismContext)3 Document (org.w3c.dom.Document)3 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)2 SchemaRegistryImpl (com.evolveum.midpoint.prism.schema.SchemaRegistryImpl)2 RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 Element (org.w3c.dom.Element)2 AccountConstructionType (com.evolveum.midpoint.prism.foo.AccountConstructionType)1 AccountType (com.evolveum.midpoint.prism.foo.AccountType)1 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)1 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)1