use of org.drools.compiler.lang.descr.AndDescr 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());
}
use of org.drools.compiler.lang.descr.AndDescr 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());
}
use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testMemberof.
@Test
public void testMemberof() throws Exception {
final String text = "rule X when Country( $cities : city )\nPerson( city memberOf $cities )\n then end";
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 memberOf $cities", fieldConstr.getExpression());
}
use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testAccumulateMultiPattern.
@Test
public void testAccumulateMultiPattern() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "accumulate_multi_pattern.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final PatternDescr outPattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
final AccumulateDescr accum = (AccumulateDescr) outPattern.getSource();
assertEqualsIgnoreWhitespace("$counter", outPattern.getIdentifier());
assertEqualsIgnoreWhitespace("int x = 0 ;", accum.getInitCode());
assertEqualsIgnoreWhitespace("x++;", accum.getActionCode());
assertEqualsIgnoreWhitespace("new Integer(x)", accum.getResultCode());
final AndDescr and = (AndDescr) accum.getInput();
assertEquals(2, and.getDescrs().size());
final PatternDescr person = (PatternDescr) and.getDescrs().get(0);
final PatternDescr cheese = (PatternDescr) and.getDescrs().get(1);
assertEquals("Person", person.getObjectType());
assertEquals("Cheese", cheese.getObjectType());
}
use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testRestrictions.
@Test
public void testRestrictions() throws Exception {
final String text = "rule X when Foo( bar > 1 || == 1 ) then end\n";
AndDescr descrs = (AndDescr) ((RuleDescr) parse("rule", text)).getLhs();
assertEquals(1, descrs.getDescrs().size());
PatternDescr pat = (PatternDescr) descrs.getDescrs().get(0);
ExprConstraintDescr fieldConstr = (ExprConstraintDescr) pat.getConstraint().getDescrs().get(0);
assertEquals("bar > 1 || == 1", fieldConstr.getExpression());
}
Aggregations