use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testAccumulateExternalFunction.
@Test
public void testAccumulateExternalFunction() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "accumulateExternalFunction.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get(0);
final AccumulateDescr accum = (AccumulateDescr) out.getSource();
assertEqualsIgnoreWhitespace("$age", accum.getFunctions().get(0).getParams()[0]);
assertEqualsIgnoreWhitespace("average", accum.getFunctions().get(0).getFunction());
assertTrue(accum.isExternalFunction());
final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
assertEquals("Person", pattern.getObjectType());
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testEvalMultiple.
@Test
public void testEvalMultiple() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "eval_multiple.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(4, rule.getLhs().getDescrs().size());
final EvalDescr eval = (EvalDescr) rule.getLhs().getDescrs().get(0);
assertEqualsIgnoreWhitespace("abc(\"foo\") + 5", (String) eval.getContent());
final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(1);
assertEquals("Foo", pattern.getObjectType());
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testUnificationBinding.
@Test
public void testUnificationBinding() throws Exception {
final String text = "rule X when $p := Person( $name := name, $loc : location ) then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals("$p", pattern.getIdentifier());
assertTrue(pattern.isUnification());
assertEquals(2, pattern.getDescrs().size());
ExprConstraintDescr bindingDescr = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("$name := name", bindingDescr.getExpression());
bindingDescr = (ExprConstraintDescr) pattern.getDescrs().get(1);
assertEquals("$loc : location", bindingDescr.getExpression());
}
use of org.drools.compiler.lang.descr.PatternDescr 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.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testLineNumberInAST.
@Test
public void testLineNumberInAST() throws Exception {
// also see testSimpleExpander to see how this works with an expander
// (should be the same).
final RuleDescr rule = (RuleDescr) parseResource("rule", "simple_rule.drl");
assertNotNull(rule);
assertEquals("simple_rule", rule.getName());
assertEquals(22, rule.getConsequenceLine());
assertEquals(2, rule.getConsequencePattern());
final AndDescr lhs = rule.getLhs();
assertNotNull(lhs);
assertEquals(3, lhs.getDescrs().size());
// Check first pattern
final PatternDescr first = (PatternDescr) lhs.getDescrs().get(0);
assertEquals("foo3", first.getIdentifier());
assertEquals("Bar", first.getObjectType());
assertEquals(1, first.getConstraint().getDescrs().size());
// Check second pattern
final PatternDescr second = (PatternDescr) lhs.getDescrs().get(1);
assertEquals("foo4", second.getIdentifier());
assertEquals("Bar", second.getObjectType());
final PatternDescr third = (PatternDescr) lhs.getDescrs().get(2);
assertEquals("Baz", third.getObjectType());
assertEquals(19, first.getLine());
assertEquals(20, second.getLine());
assertEquals(21, third.getLine());
}
Aggregations