use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testBigLiterals.
@Test
public void testBigLiterals() throws Exception {
final String text = "rule X when Primitives( bigInteger == (10I), " + " bigDecimal == (10B), " + " bigInteger < 50I, " + " bigDecimal < 50B ) then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals(4, pattern.getDescrs().size());
ExprConstraintDescr ecd = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("bigInteger == (10I)", ecd.getExpression());
ecd = (ExprConstraintDescr) pattern.getDescrs().get(1);
assertEquals("bigDecimal == (10B)", ecd.getExpression());
ecd = (ExprConstraintDescr) pattern.getDescrs().get(2);
assertEquals("bigInteger < 50I", ecd.getExpression());
ecd = (ExprConstraintDescr) pattern.getDescrs().get(3);
assertEquals("bigDecimal < 50B", ecd.getExpression());
}
use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testInlineEval.
@Test
public void testInlineEval() throws Exception {
final String text = "rule \"inline eval\"\n" + "when\n" + " Person( eval( name.startsWith(\"b\") && name.finishesWith(\"b\")) )\n" + "then\n" + "end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals("Person", pattern.getObjectType());
ExprConstraintDescr constr = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0);
assertEquals("eval( name.startsWith(\"b\") && name.finishesWith(\"b\"))", constr.getText());
}
use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testNotInOperator.
@Test
public void testNotInOperator() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "notin_operator_test.drl");
assertNotNull(rule);
assertEqualsIgnoreWhitespace("consequence();", (String) rule.getConsequence());
assertEquals("simple_rule", rule.getName());
assertEquals(2, rule.getLhs().getDescrs().size());
// The first pattern, with 2 restrictions on a single field (plus a
// connective)
PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Person", pattern.getObjectType());
assertEquals(1, pattern.getConstraint().getDescrs().size());
ExprConstraintDescr fld = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0);
assertEquals("age > 30 && < 40", fld.getExpression());
// the second col, with 2 fields, the first with 2 restrictions, the
// second field with one
pattern = (PatternDescr) rule.getLhs().getDescrs().get(1);
assertEquals("Vehicle", pattern.getObjectType());
assertEquals(2, pattern.getConstraint().getDescrs().size());
fld = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0);
assertEquals("type not in ( \"sedan\", \"wagon\" )", fld.getExpression());
// now the second field
fld = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(1);
assertEquals("age < 3", fld.getExpression());
}
use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testSlidingWindow.
@Test
public void testSlidingWindow() throws Exception {
final String text = "rule X when StockTick( symbol==\"ACME\") over window:length(10) then end";
PackageDescr pkg = (PackageDescr) parse("compilationUnit", text);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
RuleDescr rule = pkg.getRules().get(0);
PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals(1, pattern.getDescrs().size());
ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("symbol==\"ACME\"", fcd.getExpression());
List<BehaviorDescr> behaviors = pattern.getBehaviors();
assertNotNull(behaviors);
assertEquals(1, behaviors.size());
BehaviorDescr descr = behaviors.get(0);
assertEquals("window", descr.getType());
assertEquals("length", descr.getSubType());
assertEquals("10", descr.getParameters().get(0));
}
use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testIsQuery.
@Test
public void testIsQuery() throws Exception {
final String text = "rule X when ?person( \"Mark\", 42; ) then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertTrue(pattern.isQuery());
assertEquals(2, pattern.getDescrs().size());
ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("\"Mark\"", fcd.getExpression());
assertEquals(0, fcd.getPosition());
assertEquals(ExprConstraintDescr.Type.POSITIONAL, fcd.getType());
fcd = (ExprConstraintDescr) pattern.getDescrs().get(1);
assertEquals("42", fcd.getExpression());
assertEquals(1, fcd.getPosition());
assertEquals(ExprConstraintDescr.Type.POSITIONAL, fcd.getType());
}
Aggregations