use of org.drools.drl.ast.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());
}
use of org.drools.drl.ast.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.drl.ast.descr.AndDescr 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.AndDescr 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.AndDescr 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