Search in sources :

Example 16 with TaskProviders

use of com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders in project concord by walmartlabs.

the class ExpressionEvaluatorTest method testEvalScope.

@Test
public void testEvalScope() {
    ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
    Map<String, Object> vars = Collections.singletonMap("name", "${Concord}");
    Map<String, Object> input = new LinkedHashMap<>();
    input.put("msg", "Hello, ${name}");
    input.put("text", "${msg}");
    Map<String, Object> expected = new LinkedHashMap<>();
    expected.put("msg", "Hello, ${Concord}");
    expected.put("text", "Hello, ${Concord}");
    Map<String, Object> output = ee.evalAsMap(scope(vars), input);
    assertThat(output, is(expected));
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 17 with TaskProviders

use of com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders in project concord by walmartlabs.

the class ExpressionEvaluatorTest method testEval3.

@Test
public void testEval3() {
    /*
         * 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);
    TestTask task = spy(new TestTask());
    when(providers.createTask(any(), eq("task"))).thenReturn(task);
    ExpressionEvaluator ee = new DefaultExpressionEvaluator(providers);
    Map<String, Object> vars = Collections.emptyMap();
    // ---
    try {
        ee.evalAsMap(global(vars), input);
        fail("exception expected");
    } catch (Exception e) {
        assertThat(e.getMessage(), containsString("variable in '${y}'"));
    }
    verify(task, times(0)).foo(anyString());
    // scope:
    // ---
    Map<Object, Object> output = ee.evalAsMap(scope(vars), input);
    Map<Object, Object> y = map("y1", "from-task: abc", "y2", "abc", "y3", "from-task: abc");
    assertThat(output, is(map("x", y, "z", "from-task: 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 18 with TaskProviders

use of com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders in project concord by walmartlabs.

the class ExpressionEvaluatorTest method testStrictUndef.

@Test
public void testStrictUndef() {
    ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
    Map<String, Object> vars = Collections.singletonMap("name", "Concord");
    Map<String, Object> strict = Collections.emptyMap();
    EvalContext ctx = EvalContextFactory.strict(new SingleFrameContext(vars), strict);
    // ---
    try {
        ee.eval(ctx, "Hello ${name}", String.class);
        fail("exception expected");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), containsString("variable in 'Hello ${name}'"));
    }
    // undef as null
    // ---
    String str = ee.eval(undefAsNull(ctx), "Hello ${name}", String.class);
    assertNull(str);
}
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 TaskProviders

use of com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders in project concord by walmartlabs.

the class ExpressionEvaluatorTest method testEval5.

@Test
public void testEval5() {
    Map<Object, Object> input = map("y", map("y1", "y1-value", "y2", "${y1}"));
    ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
    Map<String, Object> vars = Collections.emptyMap();
    try {
        ee.evalAsMap(scope(vars), input);
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), containsString("Can't find the specified variable in '${y1}'"));
    }
}
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 TaskProviders

use of com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders in project concord by walmartlabs.

the class ExpressionEvaluatorTest method testEvalListGlobal.

@Test
public void testEvalListGlobal() {
    ExpressionEvaluator ee = new DefaultExpressionEvaluator(new TaskProviders());
    Map<String, Object> vars = Collections.singletonMap("name", "${Concord}");
    List<String> input = new ArrayList<>();
    input.add("Hello, ${name}");
    List<String> expected = new ArrayList<>();
    expected.add("Hello, ${Concord}");
    List<String> output = ee.evalAsList(global(vars), input);
    assertThat(output, is(expected));
}
Also used : TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Aggregations

TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)18 Test (org.junit.jupiter.api.Test)15 Matchers.containsString (org.hamcrest.Matchers.containsString)14 TaskCallInterceptor (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)2 TaskException (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException)2 Frame (com.walmartlabs.concord.svm.Frame)2 AbstractModule (com.google.inject.AbstractModule)1 Multibinder (com.google.inject.multibindings.Multibinder)1 FormService (com.walmartlabs.concord.runtime.common.FormService)1 TaskCall (com.walmartlabs.concord.runtime.v2.model.TaskCall)1 TaskCallOptions (com.walmartlabs.concord.runtime.v2.model.TaskCallOptions)1 DefaultCheckpointService (com.walmartlabs.concord.runtime.v2.runner.checkpoints.DefaultCheckpointService)1 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)1 BeanELResolver (com.walmartlabs.concord.runtime.v2.runner.el.resolvers.BeanELResolver)1 BaseRunnerModule (com.walmartlabs.concord.runtime.v2.runner.guice.BaseRunnerModule)1 LogContext (com.walmartlabs.concord.runtime.v2.runner.logging.LogContext)1 CallContext (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext)1 TaskCallListener (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallListener)1 TaskCallPolicyChecker (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallPolicyChecker)1 TaskResultListener (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskResultListener)1