use of org.drools.drl.ast.descr.OrDescr in project drools by kiegroup.
the class RuleParserTest method testOrBindingWithBrackets.
@Test
public void testOrBindingWithBrackets() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "or_binding_with_brackets.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
assertEquals(1, rule.getLhs().getDescrs().size());
final OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(0);
assertEquals(2, or.getDescrs().size());
// first fact
final PatternDescr firstFact = (PatternDescr) or.getDescrs().get(0);
assertEquals("Person", firstFact.getObjectType());
assertEquals("foo", firstFact.getIdentifier());
// second "option"
final PatternDescr secondFact = (PatternDescr) or.getDescrs().get(0);
assertEquals("Person", secondFact.getObjectType());
assertEquals("foo", secondFact.getIdentifier());
assertEqualsIgnoreWhitespace("System.out.println( \"Mark and Michael\" + bar );", (String) rule.getConsequence());
}
use of org.drools.drl.ast.descr.OrDescr in project drools by kiegroup.
the class RuleParserTest method testOrWithSpecialBind.
@Test
public void testOrWithSpecialBind() throws Exception {
String source = "rule \"A and (B or C or D)\" \n" + " when \n" + " pdo1 : ParametricDataObject( paramID == 101, stringValue == \"1000\" ) and \n" + " pdo2 :(ParametricDataObject( paramID == 101, stringValue == \"1001\" ) or \n" + " ParametricDataObject( paramID == 101, stringValue == \"1002\" ) or \n" + " ParametricDataObject( paramID == 101, stringValue == \"1003\" )) \n" + " then \n" + " System.out.println( \"Rule: A and (B or C or D) Fired. pdo1: \" + pdo1 + \" pdo2: \"+ pdo2); \n" + "end\n";
PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
RuleDescr rule = pkg.getRules().get(0);
AndDescr lhs = rule.getLhs();
assertEquals(2, lhs.getDescrs().size());
PatternDescr pdo1 = (PatternDescr) lhs.getDescrs().get(0);
assertEquals("pdo1", pdo1.getIdentifier());
OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(1);
assertEquals(3, or.getDescrs().size());
for (BaseDescr pdo2 : or.getDescrs()) {
assertEquals("pdo2", ((PatternDescr) pdo2).getIdentifier());
}
}
use of org.drools.drl.ast.descr.OrDescr in project drools by kiegroup.
the class RuleParserTest method testOrBindingComplex.
/**
* test basic foo : Fact() || Fact() stuff binding to an "or"
*/
@Test
public void testOrBindingComplex() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "or_binding_complex.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
assertEquals(1, rule.getLhs().getDescrs().size());
final OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(0);
assertEquals(2, or.getDescrs().size());
// first fact
final PatternDescr firstFact = (PatternDescr) or.getDescrs().get(0);
assertEquals("Person", firstFact.getObjectType());
assertEquals("foo", firstFact.getIdentifier());
// second "option"
final PatternDescr secondFact = (PatternDescr) or.getDescrs().get(1);
assertEquals("Person", secondFact.getObjectType());
assertEquals(1, secondFact.getConstraint().getDescrs().size());
assertEquals("foo", secondFact.getIdentifier());
assertEqualsIgnoreWhitespace("System.out.println( \"Mark and Michael\" + bar );", (String) rule.getConsequence());
}
use of org.drools.drl.ast.descr.OrDescr in project drools by kiegroup.
the class RuleParserTest method testOrNesting.
@Test
public void testOrNesting() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "or_nesting.drl");
assertNotNull(pkg);
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals("simple_rule", rule.getName());
assertEquals(1, rule.getLhs().getDescrs().size());
final OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(0);
assertEquals(2, or.getDescrs().size());
final PatternDescr first = (PatternDescr) or.getDescrs().get(0);
assertEquals("Person", first.getObjectType());
final AndDescr and = (AndDescr) or.getDescrs().get(1);
assertEquals(2, and.getDescrs().size());
final PatternDescr left = (PatternDescr) and.getDescrs().get(0);
assertEquals("Person", left.getObjectType());
final PatternDescr right = (PatternDescr) and.getDescrs().get(1);
assertEquals("Cheese", right.getObjectType());
}
use of org.drools.drl.ast.descr.OrDescr in project drools by kiegroup.
the class RuleParserTest method testRuleParseLhs.
@Test
public void testRuleParseLhs() throws Exception {
final String text = "rule X when Person(age < 42, location==\"atlanta\") \nor\nPerson(name==\"bob\") then end";
RuleDescr rule = (RuleDescr) parse("rule", text);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertNotNull(rule);
AndDescr lhs = rule.getLhs();
assertEquals(1, lhs.getDescrs().size());
assertEquals(2, ((OrDescr) lhs.getDescrs().get(0)).getDescrs().size());
}
Aggregations