use of org.drools.drl.ast.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testAlmostEmptyRule.
@Test
public void testAlmostEmptyRule() throws Exception {
PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "almost_empty_rule.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertNotNull(pkg);
RuleDescr rule = pkg.getRules().get(0);
assertEquals("almost_empty", rule.getName());
assertNotNull(rule.getLhs());
assertEquals("", ((String) rule.getConsequence()).trim());
}
use of org.drools.drl.ast.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testEmptyPattern.
@Test
public void testEmptyPattern() throws Exception {
PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "test_EmptyPattern.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertEquals(1, pkg.getRules().size());
final RuleDescr ruleDescr = (RuleDescr) pkg.getRules().get(0);
assertEquals("simple rule", ruleDescr.getName());
assertNotNull(ruleDescr.getLhs());
assertEquals(1, ruleDescr.getLhs().getDescrs().size());
final PatternDescr patternDescr = (PatternDescr) ruleDescr.getLhs().getDescrs().get(0);
assertEquals(0, // this
patternDescr.getConstraint().getDescrs().size());
assertEquals("Cheese", patternDescr.getObjectType());
}
use of org.drools.drl.ast.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testSimpleConstraint.
@Test
public void testSimpleConstraint() throws Exception {
String source = "package com.sample rule test when Cheese( type == 'stilton', price > 10 ) then end";
PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
assertEquals("com.sample", pkg.getName());
RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals("test", rule.getName());
assertEquals(1, rule.getLhs().getDescrs().size());
PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
AndDescr constraint = (AndDescr) pattern.getConstraint();
assertEquals(2, constraint.getDescrs().size());
assertEquals("type == \"stilton\"", constraint.getDescrs().get(0).toString());
assertEquals("price > 10", constraint.getDescrs().get(1).toString());
}
use of org.drools.drl.ast.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testBracketsPrecedence.
/**
*/
@Test
public void testBracketsPrecedence() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "brackets_precedence.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
final AndDescr rootAnd = (AndDescr) rule.getLhs();
assertEquals(2, rootAnd.getDescrs().size());
final OrDescr leftOr = (OrDescr) rootAnd.getDescrs().get(0);
assertEquals(2, leftOr.getDescrs().size());
final NotDescr not = (NotDescr) leftOr.getDescrs().get(0);
final PatternDescr foo1 = (PatternDescr) not.getDescrs().get(0);
assertEquals("Foo", foo1.getObjectType());
final PatternDescr foo2 = (PatternDescr) leftOr.getDescrs().get(1);
assertEquals("Foo", foo2.getObjectType());
final OrDescr rightOr = (OrDescr) rootAnd.getDescrs().get(1);
assertEquals(2, rightOr.getDescrs().size());
final PatternDescr shoes = (PatternDescr) rightOr.getDescrs().get(0);
assertEquals("Shoes", shoes.getObjectType());
final PatternDescr butt = (PatternDescr) rightOr.getDescrs().get(1);
assertEquals("Butt", butt.getObjectType());
}
use of org.drools.drl.ast.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testNotMemberof.
@Test
public void testNotMemberof() throws Exception {
final String text = "rule X when Country( $cities : city )\nPerson( city not memberOf $cities ) then end\n";
AndDescr descrs = ((RuleDescr) parse("rule", text)).getLhs();
assertEquals(2, descrs.getDescrs().size());
PatternDescr pat = (PatternDescr) descrs.getDescrs().get(1);
ExprConstraintDescr fieldConstr = (ExprConstraintDescr) pat.getConstraint().getDescrs().get(0);
assertEquals("city not memberOf $cities", fieldConstr.getExpression());
}
Aggregations