use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class RuleParserTest method testQueryRuleMixed.
@Test
public void testQueryRuleMixed() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "query_and_rule.drl");
assertEquals(4, // as queries are rules
pkg.getRules().size());
RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals("bar", rule.getName());
QueryDescr query = (QueryDescr) pkg.getRules().get(1);
assertEquals("simple_query", query.getName());
rule = (RuleDescr) pkg.getRules().get(2);
assertEquals("bar2", rule.getName());
query = (QueryDescr) pkg.getRules().get(3);
assertEquals("simple_query2", query.getName());
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class RuleParserTest method testAccumulateMultipleFunctionsConstraint.
@Test
public void testAccumulateMultipleFunctionsConstraint() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "accumulateMultipleFunctionsConstraint.drl");
assertEquals(1, pkg.getRules().size());
RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Object", out.getObjectType());
assertEquals(2, out.getConstraint().getDescrs().size());
assertEquals("$a1 > 10 && $M1 <= 100", out.getConstraint().getDescrs().get(0).toString());
assertEquals("$m1 == 5", out.getConstraint().getDescrs().get(1).toString());
AccumulateDescr accum = (AccumulateDescr) out.getSource();
assertTrue(accum.isExternalFunction());
List<AccumulateFunctionCallDescr> functions = accum.getFunctions();
assertEquals(3, functions.size());
assertEquals("average", functions.get(0).getFunction());
assertEquals("$a1", functions.get(0).getBind());
assertEquals("$price", functions.get(0).getParams()[0]);
assertEquals("min", functions.get(1).getFunction());
assertEquals("$m1", functions.get(1).getBind());
assertEquals("$price", functions.get(1).getParams()[0]);
assertEquals("max", functions.get(2).getFunction());
assertEquals("$M1", functions.get(2).getBind());
assertEquals("$price", functions.get(2).getParams()[0]);
final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
assertEquals("Cheese", pattern.getObjectType());
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class RuleParserTest method testLineNumberIncludingCommentsInRHS.
@Test
public void testLineNumberIncludingCommentsInRHS() throws Exception {
PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "test_CommentLineNumbersInConsequence.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
final String rhs = (String) ((RuleDescr) pkg.getRules().get(0)).getConsequence();
String expected = "\\s*//woot$\\s*first$\\s*$\\s*//$\\s*$\\s*/\\* lala$\\s*$\\s*\\*/$\\s*second$\\s*";
assertTrue(Pattern.compile(expected, Pattern.DOTALL | Pattern.MULTILINE).matcher(rhs).matches());
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class RuleParserTest method testForall.
@Test
public void testForall() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "forall.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final ForallDescr forall = (ForallDescr) rule.getLhs().getDescrs().get(0);
assertEquals(2, forall.getDescrs().size());
final PatternDescr pattern = forall.getBasePattern();
assertEquals("Person", pattern.getObjectType());
final List<BaseDescr> remaining = forall.getRemainingPatterns();
assertEquals(1, remaining.size());
final PatternDescr cheese = (PatternDescr) remaining.get(0);
assertEquals("Cheese", cheese.getObjectType());
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class RuleParserTest method testAccumulateReverse.
@Test
public void testAccumulateReverse() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "accumulateReverse.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("int x = 0 ;", accum.getInitCode());
assertEqualsIgnoreWhitespace("x++;", accum.getActionCode());
assertEqualsIgnoreWhitespace("x--;", accum.getReverseCode());
assertEqualsIgnoreWhitespace("new Integer(x)", accum.getResultCode());
assertFalse(accum.isExternalFunction());
final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
assertEquals("Person", pattern.getObjectType());
}
Aggregations