use of org.apache.commons.jexl3.JexlBuilder in project jmeter by apache.
the class Jexl3Function method getJexlEngine.
/**
* Get JexlEngine from ThreadLocal
* @return JexlEngine
*/
private static JexlEngine getJexlEngine() {
JexlEngine engine = threadLocalJexl.get();
if (engine == null) {
engine = new JexlBuilder().cache(512).silent(true).strict(true).debug(false).create();
threadLocalJexl.set(engine);
}
return engine;
}
use of org.apache.commons.jexl3.JexlBuilder in project dbeaver by serge-rider.
the class DBVUtils method parseExpression.
public static JexlExpression parseExpression(String expression) {
Map<String, Object> nsList = getExpressionNamespaces();
JexlBuilder jexlBuilder = new JexlBuilder();
jexlBuilder.cache(100);
jexlBuilder.namespaces(nsList);
JexlEngine jexlEngine = jexlBuilder.create();
return jexlEngine.createExpression(expression);
}
use of org.apache.commons.jexl3.JexlBuilder in project waltz by khartec.
the class PredicateEvaluatorTest method evaluate.
@Test
public void evaluate() {
ImmutableAssessmentContextValue assessmentValue = ImmutableAssessmentContextValue.builder().ratingCode("A").ratingName("aRating").ratingExternalId("A_RATING").ratingComment("a rating description").build();
ImmutableSurveyQuestionResponseContextValue surveyValue = ImmutableSurveyQuestionResponseContextValue.builder().value("yes").comment("a survey comment").build();
ImmutableContextVariable<Object> assessmentVar = ImmutableContextVariable.builder().name("assessmentVar").value(assessmentValue).entityRef(EntityReference.mkRef(EntityKind.APPLICATION, 1L)).build();
ImmutableContextVariable<Object> surveyVar = ImmutableContextVariable.builder().name("surveyVar").value(surveyValue).entityRef(EntityReference.mkRef(EntityKind.APPLICATION, 1L)).build();
Set<ContextVariable<?>> contextVariables = asSet(assessmentVar, surveyVar);
JexlBuilder builder = new JexlBuilder();
JexlEngine jexl = builder.create();
JexlExpression pred1Expr = jexl.createExpression("assessmentVar.ratingCode == 'A'");
JexlExpression pred2Expr = jexl.createExpression("assessmentVar.ratingCode == 'C' || surveyVar.value == 'yes'");
JexlExpression pred3Expr = jexl.createExpression("assessmentVar.ratingCode == 'C'");
JexlExpression invalidExpr = jexl.createExpression("foo?.bar");
MapContext ctx = createContext(contextVariables);
assertTrue(evaluatePredicate(pred1Expr, ctx), "pred1Expr should evaluate true, rating equals A");
assertTrue(evaluatePredicate(pred2Expr, ctx), "pred2Expr should evaluate true, survey value equals 'yes");
assertFalse(evaluatePredicate(pred3Expr, ctx), "pred3Expr should evaluate false, rating equals A");
assertFalse(evaluatePredicate(invalidExpr, ctx), "Invalid expressions should return false");
Object evaluate = invalidExpr.evaluate(ctx);
System.out.println(evaluate);
}
use of org.apache.commons.jexl3.JexlBuilder in project waltz by khartec.
the class TransitionDefinitionCompiler method compile.
public static List<CompiledTransitionDefinition> compile(List<TransitionDefinition> defns) {
JexlBuilder builder = new JexlBuilder();
JexlEngine jexl = builder.create();
return map(defns, d -> d.compile(jexl));
}
use of org.apache.commons.jexl3.JexlBuilder in project waltz by khartec.
the class SideEffectTest method canMakeAssessmentRefs.
@Test
public void canMakeAssessmentRefs() {
JexlBuilder builder = new JexlBuilder();
TestSideEffectNamespace testNamespace = new TestSideEffectNamespace();
JexlEngine jexl = builder.namespaces(newHashMap("assessment", new AssessmentSideEffectNamespace(), "test", testNamespace)).create();
MapContext ctx = new MapContext();
String messageString = "I have updated something!";
ctx.set("message", messageString);
JexlExpression sideEffectExpression = jexl.createExpression("assessment:update('ARCH_REVIEW', 'YES')");
JexlExpression messageExpression = jexl.createExpression("test:sendMessage(message)");
messageExpression.evaluate(ctx);
assertEquals(messageString, testNamespace.lastMessage, "Should be able to use context as part of expression");
assertEquals(AssessmentSideEffectNamespace.update("ARCH_REVIEW", "YES"), sideEffectExpression.evaluate(ctx), "Should be able to parse survey templateExtId and ratingExtId from update()");
}
Aggregations