Search in sources :

Example 16 with ExpressionEvaluator

use of com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator in project concord by walmartlabs.

the class ImmutablesTest method test.

@Test
public void test() throws Exception {
    TestBean testBean = ImmutableTestBean.builder().foo("foo").build();
    ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
    Map<String, Object> vars = Collections.singletonMap("testBean", testBean);
    // ---
    String str = ee.eval(EvalContextFactory.global(new SingleFrameContext(vars)), "Hello ${testBean.foo}", String.class);
    assertEquals("Hello foo", str);
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Test(org.junit.jupiter.api.Test)

Example 17 with ExpressionEvaluator

use of com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator in project concord by walmartlabs.

the class DefaultContextFactory method create.

@Override
public Context create(Runtime runtime, State state, ThreadId currentThreadId, Step currentStep, UUID correlationId) {
    ProcessDefinition pd = runtime.getService(ProcessDefinition.class);
    Compiler compiler = runtime.getService(Compiler.class);
    ExpressionEvaluator ee = runtime.getService(ExpressionEvaluator.class);
    return new ContextImpl(compiler, ee, currentThreadId, runtime, state, pd, currentStep, correlationId, workingDirectory.getValue(), processInstanceId.getValue(), fileService, dockerService, secretService, lockService, apiConfiguration, processConfiguration);
}
Also used : Compiler(com.walmartlabs.concord.runtime.v2.sdk.Compiler) ProcessDefinition(com.walmartlabs.concord.runtime.v2.model.ProcessDefinition) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)

Example 18 with ExpressionEvaluator

use of com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator in project concord by walmartlabs.

the class ExpressionEvaluatorTest method testEval1.

@Test
public void testEval1() {
    /*
         * configuration:
         *   arguments:
         *     x: ${y}
         *     z: ${y.y1}
         *     y:
         *     	y1: ${task(..)}
         *     	y2: "asdasd"
         *     	y3: ${z}
         */
    Map<Object, Object> input = map("x", "${y}", "z", "${y.y1}", "y", map("y1", "${in}", "y2", "abc", "y3", "${z}"));
    ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
    Map<String, Object> vars = Collections.singletonMap("in", "task");
    // scope -> ok
    // ---
    Map<Object, Object> output = ee.evalAsMap(scope(vars), input);
    Map<Object, Object> y = map("y1", "task", "y2", "abc", "y3", "task");
    assertThat(output, is(map("x", y, "z", "task", "y", y)));
    // ---
    try {
        ee.evalAsMap(global(vars), input);
        fail("exception expected");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), containsString("variable in '${y}'"));
    }
    // undef -> x = null, z = null, y ...y3 = null
    // ---
    output = ee.evalAsMap(undefAsNull(global(vars)), input);
    y.put("y3", null);
    assertThat(output, is(map("x", null, "z", null, "y", y)));
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 19 with ExpressionEvaluator

use of com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator in project concord by walmartlabs.

the class ExpressionEvaluatorTest method testEval2.

@Test
public void testEval2() {
    Map<Object, Object> input = map("x", "${y}", "y", "${x}");
    ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
    Map<String, Object> vars = Collections.emptyMap();
    // ---
    try {
        ee.evalAsMap(global(vars), input);
        fail("exception expected");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), containsString("variable in '${y}'"));
    }
    // ---
    try {
        ee.evalAsMap(scope(vars), input);
        fail("exception expected");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), containsString("Key 'x' already in evaluation"));
    }
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 20 with ExpressionEvaluator

use of com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator in project concord by walmartlabs.

the class ExpressionEvaluatorTest method testEvaGlobal.

@Test
public void testEvaGlobal() {
    ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
    Map<String, Object> vars = Collections.singletonMap("name", "${Concord}");
    // ---
    String str = ee.eval(global(vars), "Hello ${name}", String.class);
    assertEquals("Hello ${Concord}", str);
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

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