Search in sources :

Example 6 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, IOException, JAXBException, ExpressionEvaluationException, ObjectNotFoundException {
    // GIVEN
    OperationResult result = new OperationResult(desc);
    ScriptExpressionEvaluatorType scriptType = parseScriptType(filname);
    ItemDefinition outputDefinition = new PrismPropertyDefinitionImpl(PROPERTY_NAME, DOMUtil.XSD_STRING, PrismTestUtil.getPrismContext());
    ScriptExpression scriptExpression = scriptExpressionfactory.createScriptExpression(scriptType, outputDefinition, desc);
    ExpressionVariables variables = ExpressionVariables.create(new QName(NS_WHATEVER, "foo"), "FOO", new QName(NS_WHATEVER, "bar"), "BAR");
    // WHEN
    long startTime = System.currentTimeMillis();
    List<PrismPropertyValue<String>> scripResults = scriptExpression.evaluate(variables, null, false, desc, null, result);
    long endTime = System.currentTimeMillis();
    // THEN
    System.out.println("Script results " + desc + ", etime: " + (endTime - startTime) + " ms");
    System.out.println(scripResults);
    String scriptResult = asScalarString(scripResults);
    assertEquals("Wrong script " + desc + " result", expectedResult, scriptResult);
    return (endTime - startTime);
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ScriptExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType)

Example 7 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 {
    final String TEST_NAME = "testIsUniquePropertyValue";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestModelExpressions.class.getName() + "." + TEST_NAME);
    PrismObject<UserType> chef = repositoryService.getObject(UserType.class, CHEF_OID, null, result);
    ScriptExpressionEvaluatorType scriptType = parseScriptType("expression-" + TEST_NAME + ".xml");
    PrismPropertyDefinition<Boolean> outputDefinition = new PrismPropertyDefinitionImpl<>(PROPERTY_NAME, DOMUtil.XSD_BOOLEAN, PrismTestUtil.getPrismContext());
    ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptType, outputDefinition, TEST_NAME);
    ExpressionVariables variables = new ExpressionVariables();
    variables.addVariableDefinition(new QName(SchemaConstants.NS_C, "user"), chef);
    variables.addVariableDefinition(new QName(SchemaConstants.NS_C, "value"), "Scumm Bar Chef");
    // WHEN
    List<PrismPropertyValue<Boolean>> scriptOutputs = evaluate(scriptExpression, variables, false, TEST_NAME, 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 : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) QName(javax.xml.namespace.QName) 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) 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) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 8 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)

Aggregations

ScriptExpressionEvaluatorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExpressionEvaluatorType)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 ScriptExpression (com.evolveum.midpoint.model.common.expression.script.ScriptExpression)4 ExpressionVariables (com.evolveum.midpoint.repo.common.expression.ExpressionVariables)4 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)3 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)3 QName (javax.xml.namespace.QName)3 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)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 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 ExpressionSyntaxException (com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 HashSet (java.util.HashSet)1