Search in sources :

Example 51 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class TestMappingDynamicSimple method testScriptTransformMultiAddDelete.

@Test
public void testScriptTransformMultiAddDelete() throws Exception {
    final String TEST_NAME = "testScriptTransformMultiAddDelete";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    ObjectDelta<UserType> delta = ObjectDelta.createEmptyModifyDelta(UserType.class, evaluator.USER_OLD_OID, evaluator.getPrismContext());
    PropertyDelta<String> propDelta = delta.createPropertyModification(evaluator.toPath("employeeType"));
    propDelta.addValueToAdd(new PrismPropertyValue<String>("CAPTAIN"));
    propDelta.addValueToDelete(new PrismPropertyValue<String>("LANDLUBER"));
    delta.addModification(propDelta);
    Mapping<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> mapping = evaluator.createMapping("mapping-script-transform.xml", TEST_NAME, "organizationalUnit", delta);
    PrismObject<UserType> user = (PrismObject<UserType>) mapping.getSourceContext().getOldObject();
    user.asObjectable().getEmployeeType().add("LANDLUBER");
    mapping.getSourceContext().recompute();
    display("user before", user);
    display("delta", delta);
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    mapping.evaluate(null, opResult);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple();
    outputTriple.checkConsistence();
    PrismAsserts.assertTripleZero(outputTriple, PrismTestUtil.createPolyString("The pirate deck"));
    PrismAsserts.assertTriplePlus(outputTriple, PrismTestUtil.createPolyString("The captain deck"));
    PrismAsserts.assertTripleMinus(outputTriple, PrismTestUtil.createPolyString("The landluber deck"));
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Example 52 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class TestMappingDynamicSimple method testScriptVariablesPolyStringXPath.

@Test
public void testScriptVariablesPolyStringXPath() throws Exception {
    // WHEN
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = evaluator.evaluateMappingDynamicAdd("mapping-script-system-variables-polystring-xpath.xml", "testScriptVariablesPolyStringXPath", // target
    "fullName", // changed property
    "employeeType", "CAPTAIN", // changed values
    "SWASHBUCKLER");
    // THEN
    outputTriple.checkConsistence();
    PrismAsserts.assertTripleZero(outputTriple, new PolyString("Captain Jack Sparrow", "captain jack sparrow"));
    PrismAsserts.assertTripleNoPlus(outputTriple);
    PrismAsserts.assertTripleNoMinus(outputTriple);
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Example 53 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class TestMappingDynamicSimple method generatePolicy.

private void generatePolicy(final String TEST_NAME, String mappingFileName, String policyFileName, String pattern, boolean ignoreMax) throws Exception {
    TestUtil.displayTestTile(TEST_NAME);
    // This is just for validation. The expression has to resolve reference of its own
    PrismObject<ValuePolicyType> valuePolicy = PrismTestUtil.parseObject(new File(MidPointTestConstants.OBJECTS_DIR, policyFileName));
    final StringPolicyType stringPolicy = valuePolicy.asObjectable().getStringPolicy();
    // GIVEN
    Mapping<PrismPropertyValue<String>, PrismPropertyDefinition<String>> mapping = evaluator.createMapping(mappingFileName, TEST_NAME, stringPolicy, "employeeNumber", null);
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN (1)
    mapping.evaluate(null, opResult);
    // THEN (1)
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = mapping.getOutputTriple();
    outputTriple.checkConsistence();
    String value1 = MappingTestEvaluator.getSingleValue("plus set", outputTriple.getZeroSet());
    PrismAsserts.assertTripleNoPlus(outputTriple);
    PrismAsserts.assertTripleNoMinus(outputTriple);
    System.out.println("Generated value (1): " + value1);
    assertNotNull("Generated null value", value1);
    assertGeneratedValue(value1, stringPolicy, pattern, false, ignoreMax);
    // GIVEN (2)
    mapping = evaluator.createMapping(mappingFileName, TEST_NAME, stringPolicy, "employeeNumber", null);
    // WHEN (2)
    mapping.evaluate(null, opResult);
    // THEN (2)
    outputTriple = mapping.getOutputTriple();
    outputTriple.checkConsistence();
    String value2 = MappingTestEvaluator.getSingleValue("plus set", outputTriple.getZeroSet());
    System.out.println("Generated value (2): " + value2);
    assertNotNull("Generated null value", value2);
    assertGeneratedValue(value2, stringPolicy, pattern, false, ignoreMax);
    PrismAsserts.assertTripleNoPlus(outputTriple);
    PrismAsserts.assertTripleNoMinus(outputTriple);
    assertFalse("Generated the same value", value1.equals(value2));
}
Also used : StringPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) File(java.io.File) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 54 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class TestExpressionUtil method testResolvePathPolyStringOdo.

@Test
public void testResolvePathPolyStringOdo() throws Exception {
    final String TEST_NAME = "testResolvePathPolyStringOdo";
    System.out.println("\n===[ " + TEST_NAME + " ]===\n");
    // GIVEN
    // WHEN
    ItemDeltaItem<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> idi = resolvePathOdo("$user/fullName", TEST_NAME);
    // THEN
    assertEquals("Wrong resolved idi old value", PrismTestUtil.createPolyString("Jack Sparrow"), ((PrismProperty<PolyString>) idi.getItemOld()).getRealValue());
    assertEquals("Wrong resolved idi new value", PrismTestUtil.createPolyString("Captain Jack Sparrow"), ((PrismProperty<PolyString>) idi.getItemNew()).getRealValue());
    assertTrue("Wrong residual path: " + idi.getResidualPath(), idi.getResidualPath() == null || idi.getResidualPath().isEmpty());
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Example 55 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class TestExpressionUtil method testResolvePathPolyStringOdoOrig.

@Test
public void testResolvePathPolyStringOdoOrig() throws Exception {
    final String TEST_NAME = "testResolvePathPolyStringOdoOrig";
    System.out.println("\n===[ " + TEST_NAME + " ]===\n");
    // GIVEN
    // WHEN
    ItemDeltaItem<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> idi = resolvePathOdo("$user/fullName/t:orig", TEST_NAME);
    // THEN
    assertEquals("Wrong resolved idi old value", PrismTestUtil.createPolyString("Jack Sparrow"), ((PrismProperty<PolyString>) idi.getItemOld()).getRealValue());
    assertEquals("Wrong resolved idi new value", PrismTestUtil.createPolyString("Captain Jack Sparrow"), ((PrismProperty<PolyString>) idi.getItemNew()).getRealValue());
    PrismAsserts.assertPathEquivalent("Wrong residual path", new ItemPath(PolyString.F_ORIG), idi.getResidualPath());
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)176 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)93 Test (org.testng.annotations.Test)83 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)81 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)81 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)60 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)43 QName (javax.xml.namespace.QName)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)29 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ArrayList (java.util.ArrayList)16 Task (com.evolveum.midpoint.task.api.Task)12 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)11 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)10 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)9 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)8 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)8 File (java.io.File)8