use of org.drools.drl.ast.descr.OrDescr in project drools by kiegroup.
the class RuleParserTest method testNestedCEs.
@Test
public void testNestedCEs() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "nested_conditional_elements.drl");
assertNotNull(rule);
final AndDescr root = rule.getLhs();
final NotDescr not1 = (NotDescr) root.getDescrs().get(0);
final AndDescr and1 = (AndDescr) not1.getDescrs().get(0);
final PatternDescr state = (PatternDescr) and1.getDescrs().get(0);
final NotDescr not2 = (NotDescr) and1.getDescrs().get(1);
final AndDescr and2 = (AndDescr) not2.getDescrs().get(0);
final PatternDescr person = (PatternDescr) and2.getDescrs().get(0);
final PatternDescr cheese = (PatternDescr) and2.getDescrs().get(1);
final PatternDescr person2 = (PatternDescr) root.getDescrs().get(1);
final OrDescr or = (OrDescr) root.getDescrs().get(2);
final PatternDescr cheese2 = (PatternDescr) or.getDescrs().get(0);
final PatternDescr cheese3 = (PatternDescr) or.getDescrs().get(1);
assertEquals(state.getObjectType(), "State");
assertEquals(person.getObjectType(), "Person");
assertEquals(cheese.getObjectType(), "Cheese");
assertEquals(person2.getObjectType(), "Person");
assertEquals(cheese2.getObjectType(), "Cheese");
assertEquals(cheese3.getObjectType(), "Cheese");
}
use of org.drools.drl.ast.descr.OrDescr in project drools by kiegroup.
the class RuleParserTest method testExpanderLineSpread.
@Test
public void testExpanderLineSpread() throws Exception {
final DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
final PackageDescr pkg = parser.parse(this.getReader("expander_spread_lines.dslr"), this.getReader("complex.dsl"));
assertFalse(parser.getErrors().toString(), parser.hasErrors());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(0);
assertEquals(2, or.getDescrs().size());
assertNotNull((String) rule.getConsequence());
}
use of org.drools.drl.ast.descr.OrDescr in project drools by kiegroup.
the class RuleParserTest method testRuleWithLHSNesting.
@Test
public void testRuleWithLHSNesting() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "Rule_with_nested_LHS.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
RuleDescr rule = pkg.getRules().get(0);
assertEquals("test", rule.getName());
AndDescr lhs = rule.getLhs();
assertNotNull(lhs);
assertEquals(2, lhs.getDescrs().size());
PatternDescr a = (PatternDescr) lhs.getDescrs().get(0);
assertEquals("A", a.getObjectType());
OrDescr or = (OrDescr) lhs.getDescrs().get(1);
assertEquals(3, or.getDescrs().size());
AndDescr and1 = (AndDescr) or.getDescrs().get(0);
assertEquals(2, and1.getDescrs().size());
PatternDescr b = (PatternDescr) and1.getDescrs().get(0);
PatternDescr c = (PatternDescr) and1.getDescrs().get(1);
assertEquals("B", b.getObjectType());
assertEquals("C", c.getObjectType());
AndDescr and2 = (AndDescr) or.getDescrs().get(1);
assertEquals(2, and2.getDescrs().size());
PatternDescr d = (PatternDescr) and2.getDescrs().get(0);
PatternDescr e = (PatternDescr) and2.getDescrs().get(1);
assertEquals("D", d.getObjectType());
assertEquals("E", e.getObjectType());
AndDescr and3 = (AndDescr) or.getDescrs().get(2);
assertEquals(2, and3.getDescrs().size());
PatternDescr f = (PatternDescr) and3.getDescrs().get(0);
PatternDescr g = (PatternDescr) and3.getDescrs().get(1);
assertEquals("F", f.getObjectType());
assertEquals("G", g.getObjectType());
}
use of org.drools.drl.ast.descr.OrDescr 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.OrDescr in project drools by kiegroup.
the class CEDescrBuilderImpl method or.
/**
* {@inheritDoc}
*/
public CEDescrBuilder<CEDescrBuilder<P, T>, OrDescr> or() {
OrDescr orDescr = new OrDescr();
((ConditionalElementDescr) descr).addDescr(orDescr);
return new CEDescrBuilderImpl<CEDescrBuilder<P, T>, OrDescr>(this, orDescr);
}
Aggregations