use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testConstraintAndConnective.
@Test
public void testConstraintAndConnective() throws Exception {
final String text = "rule X when Person( age < 42 && location==\"atlanta\") then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals(1, pattern.getDescrs().size());
ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("age < 42 && location==\"atlanta\"", fcd.getExpression());
}
use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testPositionalConstraintsOnly.
@Test
public void testPositionalConstraintsOnly() throws Exception {
final String text = "rule X when Person( \"Mark\", 42; ) then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
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());
}
use of org.drools.drl.ast.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.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testConstraintOrConnective.
@Test
public void testConstraintOrConnective() throws Exception {
final String text = "rule X when Person( age < 42 || location==\"atlanta\") then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals(1, pattern.getDescrs().size());
ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("age < 42 || location==\"atlanta\"", fcd.getExpression());
}
use of org.drools.drl.ast.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