use of org.drools.compiler.lang.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());
}
use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testExpanderMultipleConstraintsFlush.
@Test
public void testExpanderMultipleConstraintsFlush() throws Exception {
final DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
// this is similar to the other test, but it requires a flush to add the
// constraints
final PackageDescr pkg = parser.parse(this.getReader("expander_multiple_constraints_flush.dslr"), this.getReader("multiple_constraints.dsl"));
assertFalse(parser.getErrors().toString(), parser.hasErrors());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Person", pattern.getObjectType());
assertEquals(2, pattern.getConstraint().getDescrs().size());
assertEquals("age < 42", ((ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0)).getExpression());
assertEquals("location==atlanta", ((ExprConstraintDescr) pattern.getConstraint().getDescrs().get(1)).getExpression());
assertNotNull((String) rule.getConsequence());
}
use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testRuleOldSyntax1.
@Test
public void testRuleOldSyntax1() throws Exception {
final String source = "rule \"Test\" when ( not $r :LiteralRestriction( operator == Operator.EQUAL ) ) then end";
PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals("Test", rule.getName());
assertEquals(1, rule.getLhs().getDescrs().size());
assertEquals(1, ((NotDescr) rule.getLhs().getDescrs().get(0)).getDescrs().size());
NotDescr notDescr = (NotDescr) rule.getLhs().getDescrs().get(0);
PatternDescr patternDescr = (PatternDescr) notDescr.getDescrs().get(0);
assertEquals("$r", patternDescr.getIdentifier());
assertEquals(1, patternDescr.getDescrs().size());
ExprConstraintDescr fieldConstraintDescr = (ExprConstraintDescr) patternDescr.getDescrs().get(0);
assertEquals("operator == Operator.EQUAL", fieldConstraintDescr.getExpression());
}
use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testRuleSingleLine.
@Test
public void testRuleSingleLine() throws Exception {
final String text = "rule \"another test\" salience 10 when eval( true ) then System.out.println(1); end";
RuleDescr rule = (RuleDescr) parse("rule", text);
assertEquals("another test", rule.getName());
assertEquals("System.out.println(1); ", rule.getConsequence());
}
use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class Misc2Test method testEvalConstraintWithMvelOperator.
@Test
public void testEvalConstraintWithMvelOperator() {
String drl = "rule \"yeah\" " + "\tdialect \"mvel\"\n when " + "Foo( eval( field soundslike \"water\" ) )" + " then " + "end";
DrlParser drlParser = new DrlParser();
PackageDescr packageDescr;
try {
packageDescr = drlParser.parse(true, drl);
} catch (DroolsParserException e) {
throw new RuntimeException(e);
}
RuleDescr r = packageDescr.getRules().get(0);
PatternDescr pd = (PatternDescr) r.getLhs().getDescrs().get(0);
assertEquals(1, pd.getConstraint().getDescrs().size());
}
Aggregations