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