Search in sources :

Example 11 with ScriptExpressionEvaluatorType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType 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)

Example 12 with ScriptExpressionEvaluatorType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType in project midpoint by Evolveum.

the class AbstractScriptTest method evaluateBooleanExpression.

private List<PrismPropertyValue<Boolean>> evaluateBooleanExpression(String fileName, String testName, VariablesMap variables) throws ObjectNotFoundException, CommunicationException, SecurityViolationException, SchemaException, IOException, ExpressionEvaluationException, ConfigurationException {
    ScriptExpressionEvaluatorType scriptType = parseScriptType(fileName);
    OperationResult opResult = createOperationResult();
    return evaluateExpression(scriptType, DOMUtil.XSD_BOOLEAN, true, variables, testName, opResult);
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ScriptExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType)

Example 13 with ScriptExpressionEvaluatorType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType in project midpoint by Evolveum.

the class TestScriptCaching method executeScript.

private long executeScript(String filname, String expectedResult, String desc) throws SchemaException, SecurityViolationException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, IOException {
    // GIVEN
    OperationResult result = createOperationResult(desc);
    ScriptExpressionEvaluatorType scriptType = parseScriptType(filname);
    ItemDefinition outputDefinition = getPrismContext().definitionFactory().createPropertyDefinition(PROPERTY_NAME, DOMUtil.XSD_STRING);
    ScriptExpression scriptExpression = createScriptExpression(scriptType, outputDefinition);
    VariablesMap variables = VariablesMap.create(getPrismContext(), "foo", "FOO", PrimitiveType.STRING, "bar", "BAR", PrimitiveType.STRING);
    // WHEN
    long startTime = System.currentTimeMillis();
    ScriptExpressionEvaluationContext context = new ScriptExpressionEvaluationContext();
    context.setVariables(variables);
    context.setEvaluateNew(false);
    context.setScriptExpression(scriptExpression);
    context.setContextDescription(desc);
    context.setResult(result);
    List<PrismPropertyValue<String>> scripResults = scriptExpression.evaluate(context);
    long endTime = System.currentTimeMillis();
    // THEN
    displayValue("Script results " + desc + ", etime: " + (endTime - startTime) + " ms", scripResults);
    String scriptResult = asScalarString(scripResults);
    assertEquals("Wrong script " + desc + " result", expectedResult, scriptResult);
    return (endTime - startTime);
}
Also used : ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) 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) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 14 with ScriptExpressionEvaluatorType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType in project midpoint by Evolveum.

the class TestModelExpressions method testIsUniquePropertyValue.

/**
 * MID-2887
 */
@Test
public void testIsUniquePropertyValue() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    String testName = getTestNameShort();
    PrismObject<UserType> chef = repositoryService.getObject(UserType.class, CHEF_OID, null, result);
    ScriptExpressionEvaluatorType scriptType = parseScriptType("expression-" + testName + ".xml");
    PrismPropertyDefinition<Boolean> outputDefinition = getPrismContext().definitionFactory().createPropertyDefinition(PROPERTY_NAME, DOMUtil.XSD_BOOLEAN);
    ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptType, outputDefinition, MiscSchemaUtil.getExpressionProfile(), expressionFactory, testName, result);
    VariablesMap variables = createVariables(ExpressionConstants.VAR_USER, chef, chef.getDefinition(), ExpressionConstants.VAR_VALUE, "Scumm Bar Chef", String.class);
    // WHEN
    List<PrismPropertyValue<Boolean>> scriptOutputs = evaluate(scriptExpression, variables, false, testName, null, result);
    // THEN
    display("Script output", scriptOutputs);
    assertEquals("Unexpected number of script outputs", 1, scriptOutputs.size());
    Boolean scriptOutput = scriptOutputs.get(0).getValue();
    assertEquals("Unexpected script output", Boolean.TRUE, scriptOutput);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) 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) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Aggregations

ScriptExpressionEvaluatorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType)14 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)10 ScriptExpression (com.evolveum.midpoint.model.common.expression.script.ScriptExpression)6 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)4 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)2 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)2 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)2 ExpressionSyntaxException (com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException)2 Task (com.evolveum.midpoint.task.api.Task)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 Test (org.testng.annotations.Test)2 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)1 ScriptExecutionException (com.evolveum.midpoint.model.api.ScriptExecutionException)1 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)1 ExpressionWrapper (com.evolveum.midpoint.prism.ExpressionWrapper)1 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)1 ExpressionVariables (com.evolveum.midpoint.repo.common.expression.ExpressionVariables)1 ExpressionProfile (com.evolveum.midpoint.schema.expression.ExpressionProfile)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)1