use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testFromWithInlineList.
@Test
public void testFromWithInlineList() throws Exception {
String source = "rule XYZ \n" + " when \n" + " o: Order( ) \n" + " not( Number( ) from [1, 2, 3] ) \n" + " then \n" + " System.err.println(\"Invalid customer id found!\"); \n" + " o.addError(\"Invalid customer id\"); \n" + "end \n";
PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals("XYZ", rule.getName());
PatternDescr number = (PatternDescr) ((NotDescr) rule.getLhs().getDescrs().get(1)).getDescrs().get(0);
assertEquals("[1, 2, 3]", ((FromDescr) number.getSource()).getDataSource().toString());
}
use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testSimpleFunctionCallWithFrom.
@Test
public void testSimpleFunctionCallWithFrom() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "test_SimpleFunctionCallWithFrom.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
final FromDescr from = (FromDescr) pattern.getSource();
final MVELExprDescr func = (MVELExprDescr) from.getDataSource();
assertEquals("doIt( foo,bar,42,\"hello\",[ a : \"b\", \"something\" : 42, \"a\" : foo, x : [x:y]],\"end\", [a, \"b\", 42] )", func.getExpression());
}
use of org.drools.drl.ast.descr.PatternDescr 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.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testSimpleAccessorAndArgWithFrom.
@Test
public void testSimpleAccessorAndArgWithFrom() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "test_SimpleAccessorArgWithFrom.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
final FromDescr from = (FromDescr) pattern.getSource();
final MVELExprDescr accessor = (MVELExprDescr) from.getDataSource();
assertEquals("something.doIt[\"key\"]", accessor.getExpression());
}
use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testEmptyPattern.
@Test
public void testEmptyPattern() throws Exception {
PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "test_EmptyPattern.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertEquals(1, pkg.getRules().size());
final RuleDescr ruleDescr = (RuleDescr) pkg.getRules().get(0);
assertEquals("simple rule", ruleDescr.getName());
assertNotNull(ruleDescr.getLhs());
assertEquals(1, ruleDescr.getLhs().getDescrs().size());
final PatternDescr patternDescr = (PatternDescr) ruleDescr.getLhs().getDescrs().get(0);
assertEquals(0, // this
patternDescr.getConstraint().getDescrs().size());
assertEquals("Cheese", patternDescr.getObjectType());
}
Aggregations