Search in sources :

Example 1 with PrismPropertyDefinitionImpl

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

the class TestDiffEquals method testDiffShadow.

@Test
public void testDiffShadow() throws Exception {
    System.out.println("\n\n===[ testDiffShadow ]===\n");
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    PrismObject<ShadowType> shadow1 = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class).instantiate();
    ShadowType shadow1Type = shadow1.asObjectable();
    shadow1Type.setName(new PolyStringType("Whatever"));
    shadow1Type.setFailedOperationType(FailedOperationTypeType.ADD);
    shadow1Type.getAuxiliaryObjectClass().add(new QName(NS_TEST_RI, "foo"));
    PrismContainer<Containerable> shadow1Attrs = shadow1.findOrCreateContainer(ShadowType.F_ATTRIBUTES);
    ShadowType shadow2Type = new ShadowType();
    PrismObject<ShadowType> shadow2 = shadow2Type.asPrismObject();
    prismContext.adopt(shadow2Type);
    shadow2Type.setName(new PolyStringType("Whatever"));
    shadow2Type.getAuxiliaryObjectClass().add(new QName(NS_TEST_RI, "foo"));
    shadow2Type.getAuxiliaryObjectClass().add(new QName(NS_TEST_RI, "bar"));
    PrismContainer<Containerable> shadow2Attrs = shadow2.findOrCreateContainer(ShadowType.F_ATTRIBUTES);
    PrismProperty<String> attrEntryUuid = new PrismProperty<>(new QName(NS_TEST_RI, "entryUuid"), prismContext);
    PrismPropertyDefinition<String> attrEntryUuidDef = new PrismPropertyDefinitionImpl<>(new QName(NS_TEST_RI, "entryUuid"), DOMUtil.XSD_STRING, prismContext);
    attrEntryUuid.setDefinition(attrEntryUuidDef);
    shadow2Attrs.add(attrEntryUuid);
    attrEntryUuid.addRealValue("1234-5678-8765-4321");
    PrismProperty<String> attrDn = new PrismProperty<>(new QName(NS_TEST_RI, "dn"), prismContext);
    PrismPropertyDefinition<String> attrDnDef = new PrismPropertyDefinitionImpl<>(new QName(NS_TEST_RI, "dn"), DOMUtil.XSD_STRING, prismContext);
    attrDn.setDefinition(attrDnDef);
    shadow2Attrs.add(attrDn);
    attrDn.addRealValue("uid=foo,o=bar");
    System.out.println("Shadow 1");
    System.out.println(shadow1.debugDump(1));
    System.out.println("Shadow 2");
    System.out.println(shadow2.debugDump(1));
    // WHEN
    ObjectDelta<ShadowType> delta = shadow1.diff(shadow2);
    // THEN
    assertNotNull("No delta", delta);
    System.out.println("Delta");
    System.out.println(delta.debugDump(1));
    PrismAsserts.assertIsModify(delta);
    PrismAsserts.assertPropertyDelete(delta, ShadowType.F_FAILED_OPERATION_TYPE, FailedOperationTypeType.ADD);
    PrismAsserts.assertPropertyAdd(delta, ShadowType.F_AUXILIARY_OBJECT_CLASS, new QName(NS_TEST_RI, "bar"));
    PrismAsserts.assertContainerAdd(delta, ShadowType.F_ATTRIBUTES, shadow2Attrs.getValue().clone());
    PrismAsserts.assertModifications(delta, 3);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) PrismContext(com.evolveum.midpoint.prism.PrismContext) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) Containerable(com.evolveum.midpoint.prism.Containerable) Test(org.testng.annotations.Test)

Example 2 with PrismPropertyDefinitionImpl

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

the class TestMappingTime method testNoReferenceTime.

@Test
public void testNoReferenceTime() throws Exception {
    final String TEST_NAME = "testNoReferenceTime";
    System.out.println("===[ " + TEST_NAME + "]===");
    // GIVEN
    PrismObject<UserType> userOld = evaluator.getUserOld();
    userOld.asObjectable().getActivation().setDisableTimestamp(null);
    Mapping.Builder<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> builder = evaluator.createMappingBuilder(MAPPING_TIME_ACTIVATION, TEST_NAME, "title", null, userOld);
    builder.setNow(TIME_PAST);
    PrismPropertyDefinition<Boolean> existenceDef = new PrismPropertyDefinitionImpl<>(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_BOOLEAN, evaluator.getPrismContext());
    builder.setDefaultTargetDefinition(existenceDef);
    Mapping<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> mapping = builder.build();
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN
    mapping.evaluate(null, opResult);
    // THEN
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = mapping.getOutputTriple();
    assertNullTriple(outputTriple);
    assertNextRecompute(mapping, null);
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Example 3 with PrismPropertyDefinitionImpl

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

the class TestMappingTime method testSetReferenceTimeBefore.

@Test
public void testSetReferenceTimeBefore() throws Exception {
    final String TEST_NAME = "testSetReferenceTimeBefore";
    System.out.println("===[ " + TEST_NAME + "]===");
    // GIVEN
    PrismObject<UserType> userOld = evaluator.getUserOld();
    XMLGregorianCalendar disableTimestamp = userOld.asObjectable().getActivation().getDisableTimestamp();
    userOld.asObjectable().getActivation().setDisableTimestamp(null);
    ObjectDelta<UserType> delta = ObjectDelta.createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, new ItemPath(UserType.F_ACTIVATION, ActivationType.F_DISABLE_TIMESTAMP), evaluator.getPrismContext(), disableTimestamp);
    Mapping.Builder<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> builder = evaluator.createMappingBuilder(MAPPING_TIME_ACTIVATION, TEST_NAME, "title", delta, userOld);
    builder.setNow(TIME_PAST);
    PrismPropertyDefinition<Boolean> existenceDef = new PrismPropertyDefinitionImpl<>(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_BOOLEAN, evaluator.getPrismContext());
    builder.setDefaultTargetDefinition(existenceDef);
    Mapping<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> mapping = builder.build();
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN
    mapping.evaluate(null, opResult);
    // THEN
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = mapping.getOutputTriple();
    assertNullTriple(outputTriple);
    assertNextRecompute(mapping, TIME_MAPPING_DISABLED_PLUS_1M);
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Example 4 with PrismPropertyDefinitionImpl

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

the class TestMappingTime method testExistenceBefore.

@Test
public void testExistenceBefore() throws Exception {
    final String TEST_NAME = "testExistenceBefore";
    System.out.println("===[ " + TEST_NAME + "]===");
    // GIVEN
    Mapping.Builder<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> builder = evaluator.createMappingBuilder(MAPPING_TIME_ACTIVATION, TEST_NAME, "title", null);
    builder.setNow(TIME_PAST);
    PrismPropertyDefinition<Boolean> existenceDef = new PrismPropertyDefinitionImpl<>(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_BOOLEAN, evaluator.getPrismContext());
    builder.setDefaultTargetDefinition(existenceDef);
    Mapping<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> mapping = builder.build();
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN
    mapping.evaluate(null, opResult);
    // THEN
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = mapping.getOutputTriple();
    assertNullTriple(outputTriple);
    assertNextRecompute(mapping, TIME_MAPPING_DISABLED_PLUS_1M);
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Example 5 with PrismPropertyDefinitionImpl

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

the class TestMappingTime method testExistenceAfter.

@Test
public void testExistenceAfter() throws Exception {
    final String TEST_NAME = "testExistenceAfter";
    System.out.println("===[ " + TEST_NAME + "]===");
    // GIVEN
    Mapping.Builder<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> builder = evaluator.createMappingBuilder(MAPPING_TIME_ACTIVATION, TEST_NAME, "title", null);
    builder.setNow(TIME_FUTURE);
    PrismPropertyDefinition<Boolean> existenceDef = new PrismPropertyDefinitionImpl<>(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_BOOLEAN, evaluator.getPrismContext());
    builder.setDefaultTargetDefinition(existenceDef);
    Mapping<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> mapping = builder.build();
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN
    mapping.evaluate(null, opResult);
    // THEN
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = mapping.getOutputTriple();
    PrismAsserts.assertTripleZero(outputTriple, false);
    PrismAsserts.assertTripleNoPlus(outputTriple);
    PrismAsserts.assertTripleNoMinus(outputTriple);
    assertNextRecompute(mapping, null);
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Aggregations

PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)26 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)19 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)18 QName (javax.xml.namespace.QName)16 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)11 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)10 Test (org.testng.annotations.Test)10 ExpressionVariables (com.evolveum.midpoint.repo.common.expression.ExpressionVariables)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 ScriptExpression (com.evolveum.midpoint.model.common.expression.script.ScriptExpression)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)3 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)3 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)2 Task (com.evolveum.midpoint.task.api.Task)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 ScriptExpressionEvaluatorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType)2