use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testPositionalsAndNamedConstraints.
@Test
public void testPositionalsAndNamedConstraints() throws Exception {
final String text = "rule X when Person( \"Mark\", 42; location == \"atlanta\" ) then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals(3, 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());
fcd = (ExprConstraintDescr) pattern.getDescrs().get(2);
assertEquals("location == \"atlanta\"", fcd.getExpression());
assertEquals(2, fcd.getPosition());
assertEquals(ExprConstraintDescr.Type.NAMED, fcd.getType());
}
use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testNotNode.
@Test
public void testNotNode() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "rule_not.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertNotNull(rule);
assertEquals("simple_rule", rule.getName());
final AndDescr lhs = rule.getLhs();
assertEquals(1, lhs.getDescrs().size());
final NotDescr not = (NotDescr) lhs.getDescrs().get(0);
assertEquals(1, not.getDescrs().size());
final PatternDescr pattern = (PatternDescr) not.getDescrs().get(0);
assertEquals("Cheese", pattern.getObjectType());
assertEquals(1, pattern.getConstraint().getDescrs().size());
final AndDescr and = (AndDescr) pattern.getConstraint();
final ExprConstraintDescr fld = (ExprConstraintDescr) and.getDescrs().get(0);
assertEquals("type == \"stilton\"", fld.getExpression());
}
use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testWithRetval.
@Test
public void testWithRetval() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "with_retval.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final PatternDescr col = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals(1, col.getConstraint().getDescrs().size());
assertEquals("Foo", col.getObjectType());
final ExprConstraintDescr fld = (ExprConstraintDescr) col.getConstraint().getDescrs().get(0);
assertEquals("name== (a + b)", fld.getExpression());
}
use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testRuleParseLhsWithStringQuotes2.
@Test
public void testRuleParseLhsWithStringQuotes2() throws Exception {
final String text = "rule X when Cheese( $x: type, type == \"s\\tti\\\"lto\\nn\" ) then end\n";
RuleDescr rule = (RuleDescr) parse("rule", text);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertNotNull(rule);
AndDescr lhs = rule.getLhs();
ExprConstraintDescr constr = (ExprConstraintDescr) ((PatternDescr) lhs.getDescrs().get(0)).getDescrs().get(1);
assertEquals("type == \"s\\tti\\\"lto\\nn\"", constr.getText());
}
use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testPredicate2.
@Test
public void testPredicate2() throws Exception {
// predicates are also prefixed by the eval keyword
final RuleDescr rule = (RuleDescr) parse("rule", "rule X when Foo(eval( $var.equals(\"xyz\") )) then end");
final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
final List<?> constraints = pattern.getConstraint().getDescrs();
assertEquals(1, constraints.size());
final ExprConstraintDescr predicate = (ExprConstraintDescr) constraints.get(0);
assertEquals("eval( $var.equals(\"xyz\") )", predicate.getExpression());
}
Aggregations