use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.
the class TestPolyString method testRecompute.
@Test
public void testRecompute() throws Exception {
System.out.println("===[ testRecompute ]===");
// GIVEN
PrismContext ctx = constructInitializedPrismContext();
PrismObjectDefinition<UserType> userDefinition = getFooSchema(ctx).findObjectDefinitionByElementName(new QName(NS_FOO, "user"));
PrismObject<UserType> user = userDefinition.instantiate();
String orig = "Ľala ho papľuha";
PolyString polyName = new PolyString(orig);
PrismProperty<Object> polyNameProperty = user.findOrCreateProperty(USER_POLYNAME_QNAME);
// WHEN
polyNameProperty.setRealValue(polyName);
// THEN
assertEquals("Changed orig", orig, polyName.getOrig());
assertEquals("Wrong norm", "lala ho papluha", polyName.getNorm());
}
use of com.evolveum.midpoint.prism.foo.UserType 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.foo.UserType 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);
}
use of com.evolveum.midpoint.prism.foo.UserType 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
}
use of com.evolveum.midpoint.prism.foo.UserType in project midpoint by Evolveum.
the class AbstractLexicalProcessorTest method testParseUserToPrism.
@Test
public void testParseUserToPrism() throws Exception {
final String TEST_NAME = "testParseUserToPrism";
displayTestTitle(TEST_NAME);
// GIVEN
LexicalProcessor lexicalProcessor = createParser();
PrismContext prismContext = PrismTestUtil.getPrismContext();
// WHEN (parse to xnode)
RootXNode xnode = lexicalProcessor.read(getFileSource(USER_JACK_FILE_BASENAME), ParsingContext.createDefault());
System.out.println("XNode after parsing:");
System.out.println(xnode.debugDump());
// WHEN (parse to prism)
PrismObject<UserType> user = prismContext.parserFor(xnode).parse();
// THEN
System.out.println("Parsed user:");
System.out.println(user.debugDump());
assertUserJackXNodeOrdering("serialized xnode", xnode);
assertUserJack(user, true);
}
Aggregations