Search in sources :

Example 6 with NameItemPathSegment

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

the class TestAbstractAssignmentEvaluator method test130DirectExpressionReplaceDescriptionFromNull.

@Test
public void test130DirectExpressionReplaceDescriptionFromNull() throws Exception {
    final String TEST_NAME = "test130DirectExpressionReplaceDescriptionFromNull";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> user = userTypeJack.asPrismObject().clone();
    AssignmentType assignmentType = unmarshallValueFromFile(ASSIGNMENT_DIRECT_EXPRESSION_FILE, AssignmentType.class);
    assignmentType.setDescription(null);
    user.asObjectable().getAssignment().add(assignmentType.clone());
    //		// We need to make sure that the assignment has a parent
    //		PrismContainerDefinition<AssignmentType> assignmentContainerDefinition = user.getDefinition().findContainerDefinition(UserType.F_ASSIGNMENT);
    //		PrismContainer<AssignmentType> assignmentContainer = assignmentContainerDefinition.instantiate();
    //		assignmentContainer.add(assignmentType.asPrismContainerValue().clone());
    ItemPath path = new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(123L), new NameItemPathSegment(AssignmentType.F_DESCRIPTION));
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_JACK_OID, path, prismContext, "sailor");
    ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(user, userDelta, null);
    userOdo.recompute();
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
    assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
    assignmentIdi.setSubItemDeltas(userDelta.getModifications());
    assignmentIdi.recompute();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, "testDirect", task, result);
    evaluatedAssignment.evaluateConstructions(userOdo, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(evaluatedAssignment);
    display("Evaluated assignment", evaluatedAssignment);
    assertEquals(1, evaluatedAssignment.getConstructionTriple().size());
    PrismAsserts.assertParentConsistency(user);
    Construction<UserType> construction = evaluatedAssignment.getConstructionTriple().getZeroSet().iterator().next();
    assertNotNull("No object class definition in construction", construction.getRefinedObjectClassDefinition());
    assertEquals(1, construction.getAttributeMappings().size());
    PrismValueDeltaSetTripleProducer<PrismPropertyValue<String>, PrismPropertyDefinition<String>> attributeMapping = (PrismValueDeltaSetTripleProducer<PrismPropertyValue<String>, PrismPropertyDefinition<String>>) construction.getAttributeMappings().iterator().next();
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = attributeMapping.getOutputTriple();
    PrismAsserts.assertTripleNoZero(outputTriple);
    PrismAsserts.assertTriplePlus(outputTriple, "The best sailor the world has ever seen");
    PrismAsserts.assertTripleMinus(outputTriple, "The best man the world has ever seen");
    // the same using other words
    assertConstruction(evaluatedAssignment, ZERO, "title", ZERO);
    assertConstruction(evaluatedAssignment, ZERO, "title", PLUS, "The best sailor the world has ever seen");
    assertConstruction(evaluatedAssignment, ZERO, "title", MINUS, "The best man the world has ever seen");
    assertNoConstruction(evaluatedAssignment, PLUS, "title");
    assertNoConstruction(evaluatedAssignment, MINUS, "title");
    assertEquals("Wrong number of admin GUI configs", 0, evaluatedAssignment.getAdminGuiConfigurations().size());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) PrismValueDeltaSetTripleProducer(com.evolveum.midpoint.model.common.mapping.PrismValueDeltaSetTripleProducer) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 7 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment 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 8 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment 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 9 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment 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 10 with NameItemPathSegment

use of com.evolveum.midpoint.prism.path.NameItemPathSegment 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)

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