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