Search in sources :

Example 41 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class TestModelExpressions method testGetLinkedShadowKindIntentFullname.

@Test
public void testGetLinkedShadowKindIntentFullname() throws Exception {
    rememberCounter(InternalCounters.SHADOW_FETCH_OPERATION_COUNT);
    PrismObject<UserType> user = getUser(USER_GUYBRUSH_OID);
    VariablesMap variables = createVariables(ExpressionConstants.VAR_USER, user, user.getDefinition());
    assertExecuteScriptExpressionString(variables, ACCOUNT_GUYBRUSH_DUMMY_FULLNAME);
    assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 1);
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 42 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class TestModelExpressions method testGetManagersOids.

@Test
public void testGetManagersOids() throws Exception {
    // GIVEN
    OperationResult result = createOperationResult();
    String shortTestName = getTestNameShort();
    PrismObject<UserType> chef = repositoryService.getObject(UserType.class, CHEF_OID, null, result);
    ScriptExpressionEvaluatorType scriptType = parseScriptType("expression-" + shortTestName + ".xml");
    PrismPropertyDefinition<String> outputDefinition = getPrismContext().definitionFactory().createPropertyDefinition(PROPERTY_NAME, DOMUtil.XSD_STRING);
    ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptType, outputDefinition, MiscSchemaUtil.getExpressionProfile(), expressionFactory, shortTestName, result);
    VariablesMap variables = createVariables(ExpressionConstants.VAR_USER, chef, chef.getDefinition());
    // WHEN
    List<PrismPropertyValue<String>> scriptOutputs = evaluate(scriptExpression, variables, false, shortTestName, null, result);
    // THEN
    display("Script output", scriptOutputs);
    assertEquals("Unexpected number of script outputs", 3, scriptOutputs.size());
    Set<String> oids = new HashSet<>();
    oids.add(scriptOutputs.get(0).getValue());
    oids.add(scriptOutputs.get(1).getValue());
    oids.add(scriptOutputs.get(2).getValue());
    Set<String> expectedOids = new HashSet<>(Arrays.asList(CHEESE_OID, CHEESE_JR_OID, LECHUCK_OID));
    assertEquals("Unexpected script output", expectedOids, oids);
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ScriptExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType) ScriptExpression(com.evolveum.midpoint.model.common.expression.script.ScriptExpression) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 43 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class TestModelExpressions method testGetLinkedShadowNameRepo.

@Test
public void testGetLinkedShadowNameRepo() throws Exception {
    rememberCounter(InternalCounters.SHADOW_FETCH_OPERATION_COUNT);
    PrismObject<UserType> user = getUser(USER_GUYBRUSH_OID);
    VariablesMap variables = createVariables(ExpressionConstants.VAR_USER, user, user.getDefinition());
    assertExecuteScriptExpressionString(variables, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
    assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 44 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class TestModelExpressions method testGetLinkedShadowName.

@Test
public void testGetLinkedShadowName() throws Exception {
    rememberCounter(InternalCounters.SHADOW_FETCH_OPERATION_COUNT);
    PrismObject<UserType> user = getUser(USER_GUYBRUSH_OID);
    VariablesMap variables = createVariables(ExpressionConstants.VAR_USER, user, user.getDefinition());
    assertExecuteScriptExpressionString(variables, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
    assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 1);
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 45 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class TestModelExpressions method executeScriptExpressionString.

private String executeScriptExpressionString(VariablesMap variables) throws SecurityViolationException, ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, IOException {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    String shortTestName = getTestNameShort();
    ScriptExpressionEvaluatorType scriptType = parseScriptType("expression-" + shortTestName + ".xml");
    ItemDefinition<?> outputDefinition = getPrismContext().definitionFactory().createPropertyDefinition(PROPERTY_NAME, DOMUtil.XSD_STRING);
    ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptType, outputDefinition, MiscSchemaUtil.getExpressionProfile(), expressionFactory, shortTestName, result);
    if (variables == null) {
        variables = new VariablesMap();
    }
    // WHEN
    when();
    List<PrismPropertyValue<String>> scriptOutputs = evaluate(scriptExpression, variables, false, shortTestName, null, result);
    // THEN
    then();
    display("Script output", scriptOutputs);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    if (scriptOutputs.size() == 0) {
        return null;
    }
    assertEquals("Unexpected number of script outputs", 1, scriptOutputs.size());
    PrismPropertyValue<String> scriptOutput = scriptOutputs.get(0);
    if (scriptOutput == null) {
        return null;
    }
    return scriptOutput.getValue();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) ScriptExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType) ScriptExpression(com.evolveum.midpoint.model.common.expression.script.ScriptExpression)

Aggregations

VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)166 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)48 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)30 Test (org.testng.annotations.Test)28 Task (com.evolveum.midpoint.task.api.Task)23 NotNull (org.jetbrains.annotations.NotNull)23 QName (javax.xml.namespace.QName)15 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)12 Source (com.evolveum.midpoint.repo.common.expression.Source)12 AbstractModelCommonTest (com.evolveum.midpoint.model.common.AbstractModelCommonTest)11 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)11 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)10 Trace (com.evolveum.midpoint.util.logging.Trace)10 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)10 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)9 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)9 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)9 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)8 ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)8 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)7