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();
}
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);
}
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);
}
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);
}
Aggregations