Search in sources :

Example 6 with ScriptExpression

use of com.evolveum.midpoint.model.common.expression.script.ScriptExpression in project midpoint by Evolveum.

the class TestModelExpressions method executeScriptExpressionString.

private String executeScriptExpressionString(final String TEST_NAME, ExpressionVariables variables) throws SchemaException, IOException, JAXBException, ExpressionEvaluationException, ObjectNotFoundException {
    // GIVEN
    OperationResult result = new OperationResult(TestModelExpressions.class.getName() + "." + TEST_NAME);
    ScriptExpressionEvaluatorType scriptType = parseScriptType("expression-" + TEST_NAME + ".xml");
    ItemDefinition outputDefinition = new PrismPropertyDefinitionImpl(PROPERTY_NAME, DOMUtil.XSD_STRING, PrismTestUtil.getPrismContext());
    ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptType, outputDefinition, TEST_NAME);
    if (variables == null) {
        variables = new ExpressionVariables();
    }
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    List<PrismPropertyValue<String>> scriptOutputs = evaluate(scriptExpression, variables, false, TEST_NAME, null, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    display("Script output", scriptOutputs);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    if (scriptOutputs.size() == 0) {
        return null;
    }
    assertEquals("Unexpected number of script outputs", 1, scriptOutputs.size());
    return scriptOutputs.get(0).getValue();
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ScriptExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType) ScriptExpression(com.evolveum.midpoint.model.common.expression.script.ScriptExpression) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

ScriptExpression (com.evolveum.midpoint.model.common.expression.script.ScriptExpression)6 ExpressionVariables (com.evolveum.midpoint.repo.common.expression.ExpressionVariables)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 ScriptExpressionEvaluatorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType)4 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)3 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)3 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 QName (javax.xml.namespace.QName)2 Test (org.testng.annotations.Test)2 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)1 ScriptExecutionException (com.evolveum.midpoint.model.api.ScriptExecutionException)1 ScriptExpressionEvaluationContext (com.evolveum.midpoint.model.common.expression.script.ScriptExpressionEvaluationContext)1 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)1 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 ExpressionSyntaxException (com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1