use of com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator in project concord by walmartlabs.
the class ExpressionEvaluatorTest method testEval8.
@Test
public void testEval8() {
/*
* x:
* - ${y}
* y: "abc"
*/
Map<Object, Object> input = map("x", Collections.singletonList("${y}"), "y", "abc");
ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
Map<String, Object> vars = Collections.emptyMap();
// scope:
// ---
Map<Object, Object> output = ee.evalAsMap(scope(vars), input);
assertThat(output, is(map("x", Collections.singletonList("abc"), "y", "abc")));
}
use of com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator in project concord by walmartlabs.
the class ExpressionEvaluatorTest method testEval6.
@Test
public void testEval6() {
Map<Object, Object> input = map("x", Collections.singletonList("${y}"), "y", "abc");
ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
Map<String, Object> vars = Collections.emptyMap();
// scope:
// ---
Map<Object, Object> output = ee.evalAsMap(scope(vars), input);
assertThat(output, is(map("x", Collections.singletonList("abc"), "y", "abc")));
}
use of com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator in project concord by walmartlabs.
the class ExpressionEvaluatorTest method testEvalHasVariable.
@Test
public void testEvalHasVariable() {
String str = "${hasVariable('x')}";
ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
// ---
boolean result = ee.eval(global(Collections.emptyMap()), str, Boolean.class);
assertFalse(result);
// ---
Map<String, Object> vars = Collections.singletonMap("x", "x-value");
result = ee.eval(global(vars), str, Boolean.class);
assertTrue(result);
}
use of com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator in project concord by walmartlabs.
the class ExpressionEvaluatorTest method testEval4.
@Test
public void testEval4() {
/*
* configuration:
* arguments:
* x: ${y}
* z: ${y.y1}
* y:
* y1: ${task(y.y2)}
* y2: "asdasd"
* y3: ${z}
*/
Map<Object, Object> input = map("x", "${y}", "z", "${y.y1}", "y", map("y1", "${task.foo(y.y2)}", "y2", "abc", "y3", "${z}"));
TaskProviders providers = mock(TaskProviders.class);
TestTask2 task = spy(new TestTask2());
when(providers.createTask(any(), eq("task"))).thenReturn(task);
ExpressionEvaluator ee = new DefaultExpressionEvaluator(providers);
Map<String, Object> vars = Collections.emptyMap();
// scope:
// ---
Map<Object, Object> output = ee.evalAsMap(scope(vars), input);
Map<Object, Object> y = map("y1", "${abc}", "y2", "abc", "y3", "${abc}");
assertThat(output, is(map("x", y, "z", "${abc}", "y", y)));
verify(task, times(1)).foo(anyString());
}
use of com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator in project concord by walmartlabs.
the class TaskCallCommand method execute.
@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
Frame frame = state.peekFrame(threadId);
frame.pop();
Context ctx = runtime.getService(Context.class);
TaskProviders taskProviders = runtime.getService(TaskProviders.class);
ExpressionEvaluator expressionEvaluator = runtime.getService(ExpressionEvaluator.class);
TaskCall call = getStep();
String taskName = call.getName();
Task t = taskProviders.createTask(ctx, taskName);
if (t == null) {
throw new IllegalStateException("Task not found: '" + taskName + "'");
}
TaskCallInterceptor interceptor = runtime.getService(TaskCallInterceptor.class);
CallContext callContext = CallContext.builder().taskName(taskName).correlationId(ctx.execution().correlationId()).currentStep(getStep()).processDefinition(ctx.execution().processDefinition()).build();
TaskCallOptions opts = Objects.requireNonNull(call.getOptions());
Variables input = new MapBackedVariables(VMUtils.prepareInput(expressionEvaluator, ctx, opts.input(), opts.inputExpression()));
TaskResult result;
try {
result = interceptor.invoke(callContext, Method.of(t, "execute", Collections.singletonList(input)), () -> t.execute(input));
} catch (TaskException e) {
result = TaskResult.fail(e.getCause());
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
TaskCallUtils.processTaskResult(runtime, ctx, taskName, opts, result);
}
Aggregations