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