use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project drools by kiegroup.
the class ExpressionEvaluatorFactoryTest method isAnMVELExpression.
@Test
public void isAnMVELExpression() {
ExpressionEvaluatorFactory ruleEvaluatorFactory = ExpressionEvaluatorFactory.create(classLoader, ScenarioSimulationModel.Type.RULE);
assertFalse(ruleEvaluatorFactory.isAnMVELExpression("10"));
assertTrue(ruleEvaluatorFactory.isAnMVELExpression(MVEL_ESCAPE_SYMBOL + "10"));
assertTrue(ruleEvaluatorFactory.isAnMVELExpression(" " + MVEL_ESCAPE_SYMBOL + " 10"));
assertTrue(ruleEvaluatorFactory.isAnMVELExpression(new TextNode(MVEL_ESCAPE_SYMBOL + " 10").textValue()));
assertTrue(ruleEvaluatorFactory.isAnMVELExpression(new TextNode(" " + MVEL_ESCAPE_SYMBOL + " 10").textValue()));
assertFalse(ruleEvaluatorFactory.isAnMVELExpression(new TextNode("10").textValue()));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project drools by kiegroup.
the class DMNFeelExpressionEvaluatorTest method expressionListTest_Wrong.
@Test(expected = IllegalArgumentException.class)
public void expressionListTest_Wrong() {
String expressionCollectionJsonString = new TextNode("[ 1 : 234").toString();
expressionEvaluator.convertResult(expressionCollectionJsonString, List.class.getCanonicalName(), Collections.EMPTY_LIST);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project drools by kiegroup.
the class DMNFeelExpressionEvaluatorTest method evaluateLiteralExpression.
@Test
@SuppressWarnings("unchecked")
public void evaluateLiteralExpression() {
assertEquals(BigDecimal.valueOf(5), expressionEvaluator.evaluateLiteralExpression("2 + 3", BigDecimal.class.getCanonicalName(), null));
Map<String, Object> parsedValue = (Map<String, Object>) expressionEvaluator.evaluateLiteralExpression("{key_a : 1}", Map.class.getCanonicalName(), Collections.emptyList());
assertTrue(parsedValue.containsKey("key_a"));
assertEquals(parsedValue.get("key_a"), BigDecimal.valueOf(1));
List<BigDecimal> parsedValueListExpression = (List<BigDecimal>) expressionEvaluator.evaluateLiteralExpression(new TextNode("[10, 12]").toString(), List.class.getCanonicalName(), Collections.emptyList());
assertEquals(2, parsedValueListExpression.size());
assertEquals(BigDecimal.valueOf(10), parsedValueListExpression.get(0));
assertEquals(BigDecimal.valueOf(12), parsedValueListExpression.get(1));
assertThatThrownBy(() -> expressionEvaluator.evaluateLiteralExpression("SPEED", String.class.getCanonicalName(), null)).isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith("Error during evaluation:");
assertThatThrownBy(() -> expressionEvaluator.evaluateLiteralExpression("\"SPEED", String.class.getCanonicalName(), null)).isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith("Syntax error:");
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project drools by kiegroup.
the class DMNFeelExpressionEvaluatorTest method evaluateUnaryExpression.
@Test
public void evaluateUnaryExpression() {
assertTrue(expressionEvaluator.evaluateUnaryExpression("not( true )", false, boolean.class).isSuccessful());
assertTrue(expressionEvaluator.evaluateUnaryExpression(">2, >5", BigDecimal.valueOf(6), BigDecimal.class).isSuccessful());
assertTrue(expressionEvaluator.evaluateUnaryExpression("abs(-1)", BigDecimal.valueOf(1), BigDecimal.class).isSuccessful());
assertFalse(expressionEvaluator.evaluateUnaryExpression("abs(-1)", BigDecimal.valueOf(-1), BigDecimal.class).isSuccessful());
assertTrue(expressionEvaluator.evaluateUnaryExpression("max(1, ?) > 1", BigDecimal.valueOf(2), BigDecimal.class).isSuccessful());
assertFalse(expressionEvaluator.evaluateUnaryExpression("max(1, ?) < 1", BigDecimal.valueOf(2), BigDecimal.class).isSuccessful());
assertTrue(expressionEvaluator.evaluateUnaryExpression("? = 2", BigDecimal.valueOf(2), BigDecimal.class).isSuccessful());
assertFalse(expressionEvaluator.evaluateUnaryExpression("? > 2", BigDecimal.valueOf(2), BigDecimal.class).isSuccessful());
assertTrue(expressionEvaluator.evaluateUnaryExpression("? + 1 > ?", BigDecimal.valueOf(2), BigDecimal.class).isSuccessful());
Map<String, BigDecimal> contextValue = Collections.singletonMap("key_a", BigDecimal.valueOf(1));
assertTrue(expressionEvaluator.evaluateUnaryExpression("{key_a : 1}", contextValue, Map.class).isSuccessful());
assertFalse(expressionEvaluator.evaluateUnaryExpression("{key_a : 2}", contextValue, Map.class).isSuccessful());
List<BigDecimal> contextListValue = Collections.singletonList(BigDecimal.valueOf(23));
assertTrue(expressionEvaluator.evaluateUnaryExpression(new TextNode("23").toString(), contextListValue, List.class).isSuccessful());
assertFalse(expressionEvaluator.evaluateUnaryExpression(new TextNode("2").toString(), contextListValue, List.class).isSuccessful());
assertTrue(expressionEvaluator.evaluateUnaryExpression(new TextNode("? = [23]").toString(), contextListValue, List.class).isSuccessful());
assertFalse(expressionEvaluator.evaluateUnaryExpression(new TextNode("? = [2]").toString(), contextListValue, List.class).isSuccessful());
List<BigDecimal> contextListValue2 = Arrays.asList(BigDecimal.valueOf(23), BigDecimal.valueOf(32));
assertTrue(expressionEvaluator.evaluateUnaryExpression(new TextNode(" ? = [23, 32]").toString(), contextListValue2, List.class).isSuccessful());
assertFalse("Collection unary expression needs to start with ?", expressionEvaluator.evaluateUnaryExpression(new TextNode("[23, 32]").toString(), contextListValue2, List.class).isSuccessful());
assertFalse(expressionEvaluator.evaluateUnaryExpression(new TextNode(" ? = [23, 32, 123]").toString(), contextListValue2, List.class).isSuccessful());
assertTrue(expressionEvaluator.evaluateUnaryExpression(new TextNode(" ?[1] = 23").toString(), contextListValue2, List.class).isSuccessful());
assertFalse(expressionEvaluator.evaluateUnaryExpression(new TextNode(" ?[1] = 32").toString(), contextListValue2, List.class).isSuccessful());
Map<String, Object> firstMap = new HashMap<>();
firstMap.put("Price", new BigDecimal(2000));
firstMap.put("Name", "PC");
Map<String, Object> secondMap = new HashMap<>();
secondMap.put("Price", new BigDecimal(3300));
secondMap.put("Name", "CAR");
String firstParameter = "{Price: 2000,Name:\"PC\"}";
String secondParameter = "{Price:3300, Name:\"CAR\"}";
List<Map<String, Object>> context = Arrays.asList(firstMap, secondMap);
assertTrue(expressionEvaluator.evaluateUnaryExpression(new TextNode("?=[" + firstParameter + ", " + secondParameter + "]").toString(), context, List.class).isSuccessful());
assertFalse(expressionEvaluator.evaluateUnaryExpression(new TextNode("?=[{Price: 2001,Name:\"PC\"}, {Price:3301,Name:\"CAR\"}]").toString(), context, List.class).isSuccessful());
assertFalse(expressionEvaluator.evaluateUnaryExpression(new TextNode("?=[{Price: 2000, Name:\"PCA\"}, {Price:3300,Name:\"CARE\"}]").toString(), context, List.class).isSuccessful());
assertFalse(expressionEvaluator.evaluateUnaryExpression(new TextNode("?=[{Pric: 2000, Name:\"PC\"}, {Price:3300,Names:\"CARE\"}]").toString(), context, List.class).isSuccessful());
/* Different order: Failure */
assertFalse(expressionEvaluator.evaluateUnaryExpression(new TextNode("?=[" + secondParameter + ", " + firstParameter + "]").toString(), context, List.class).isSuccessful());
/* IN operator */
assertTrue(expressionEvaluator.evaluateUnaryExpression(new TextNode(firstParameter + " in ?").toString(), context, List.class).isSuccessful());
assertTrue(expressionEvaluator.evaluateUnaryExpression(new TextNode(secondParameter + " in ?").toString(), context, List.class).isSuccessful());
assertFalse(expressionEvaluator.evaluateUnaryExpression(new TextNode("{Price: 2001,Name:\"PC\"} in ?").toString(), context, List.class).isSuccessful());
assertFalse(expressionEvaluator.evaluateUnaryExpression(new TextNode("{Price: 3300,Name:\"CARE\"} in ?").toString(), context, List.class).isSuccessful());
assertTrue(expressionEvaluator.evaluateUnaryExpression(new TextNode("(" + firstParameter + " in ?) and (" + secondParameter + " in ?)").toString(), context, List.class).isSuccessful());
assertTrue(expressionEvaluator.evaluateUnaryExpression(new TextNode("(" + secondParameter + " in ?) and (" + firstParameter + " in ?)").toString(), context, List.class).isSuccessful());
assertThatThrownBy(() -> expressionEvaluator.evaluateUnaryExpression("variable", null, null)).isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith("Error during evaluation:");
assertThatThrownBy(() -> expressionEvaluator.evaluateUnaryExpression("! true", null, null)).isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith("Syntax error:");
assertThatThrownBy(() -> expressionEvaluator.evaluateUnaryExpression("? > 2", null, BigDecimal.class)).isInstanceOf(IllegalArgumentException.class);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project drools by kiegroup.
the class DMNFeelExpressionEvaluatorTest method expressionListTest.
@Test
public void expressionListTest() {
String expressionCollectionJsonString = new TextNode("[ 1, 10 ]").toString();
List<BigDecimal> result = (List<BigDecimal>) expressionEvaluator.convertResult(expressionCollectionJsonString, List.class.getCanonicalName(), Collections.EMPTY_LIST);
assertEquals(2, result.size());
assertEquals(BigDecimal.ONE, result.get(0));
assertEquals(BigDecimal.TEN, result.get(1));
}
Aggregations