Search in sources :

Example 11 with ExpressionEvaluator

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")));
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 12 with ExpressionEvaluator

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")));
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 13 with ExpressionEvaluator

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);
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 14 with ExpressionEvaluator

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());
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 15 with ExpressionEvaluator

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);
}
Also used : CallContext(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext) Frame(com.walmartlabs.concord.svm.Frame) TaskCall(com.walmartlabs.concord.runtime.v2.model.TaskCall) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator) CallContext(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext) TaskException(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException) TaskCallOptions(com.walmartlabs.concord.runtime.v2.model.TaskCallOptions) TaskException(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException) TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) TaskCallInterceptor(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)

Aggregations

ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)16 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)16 Test (org.junit.jupiter.api.Test)15 Matchers.containsString (org.hamcrest.Matchers.containsString)14 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)13 EvalContext (com.walmartlabs.concord.runtime.v2.runner.el.EvalContext)5 ContextFactory (com.walmartlabs.concord.runtime.v2.runner.context.ContextFactory)4 EvalContextFactory (com.walmartlabs.concord.runtime.v2.runner.el.EvalContextFactory)4 ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)3 Serializable (java.io.Serializable)3 Map (java.util.Map)3 Step (com.walmartlabs.concord.runtime.v2.model.Step)2 Compiler (com.walmartlabs.concord.runtime.v2.sdk.Compiler)2 ProcessConfiguration (com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration)2 HashMap (java.util.HashMap)2 Form (com.walmartlabs.concord.forms.Form)1 FormService (com.walmartlabs.concord.runtime.common.FormService)1 Expression (com.walmartlabs.concord.runtime.v2.model.Expression)1 ExpressionOptions (com.walmartlabs.concord.runtime.v2.model.ExpressionOptions)1 FlowCall (com.walmartlabs.concord.runtime.v2.model.FlowCall)1