use of org.drools.drl.ast.descr.FromDescr in project drools by kiegroup.
the class XmlPackageReaderTest method testParseFrom.
@Test
public void testParseFrom() throws Exception {
final XmlPackageReader xmlPackageReader = getXmReader();
xmlPackageReader.read(new InputStreamReader(getClass().getResourceAsStream("test_ParseFrom.xml")));
final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
assertNotNull(packageDescr);
RuleDescr obj = (RuleDescr) packageDescr.getRules().get(0);
PatternDescr patterndescr = (PatternDescr) obj.getLhs().getDescrs().get(0);
FromDescr from = (FromDescr) patterndescr.getSource();
MVELExprDescr accessordescriptor = (MVELExprDescr) from.getDataSource();
assertEquals("cheesery.getCheeses(i+4)", accessordescriptor.getExpression());
assertEquals(patterndescr.getObjectType(), "Cheese");
assertEquals(patterndescr.getIdentifier(), "cheese");
}
use of org.drools.drl.ast.descr.FromDescr in project drools by kiegroup.
the class RuleParserTest method testSimpleMethodCallWithFrom.
@Test
public void testSimpleMethodCallWithFrom() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "test_SimpleMethodCallWithFrom.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
final FromDescr from = (FromDescr) pattern.getSource();
final MVELExprDescr method = (MVELExprDescr) from.getDataSource();
assertEquals("something.doIt( foo,bar,42,\"hello\",[ a : \"b\", \"something\" : 42, \"a\" : foo, x : [x:y]],\"end\", [a, \"b\", 42] )", method.getExpression());
}
use of org.drools.drl.ast.descr.FromDescr in project drools by kiegroup.
the class RuleParserTest method testFromWithInlineListIndex.
@Test
public void testFromWithInlineListIndex() throws Exception {
String source = "rule XYZ \n" + " when \n" + " o: Order( ) \n" + " Number( ) from [1, 2, 3][1] \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());
assertFalse(parser.hasErrors());
PatternDescr number = (PatternDescr) rule.getLhs().getDescrs().get(1);
assertEquals("[1, 2, 3][1]", ((FromDescr) number.getSource()).getDataSource().toString());
}
use of org.drools.drl.ast.descr.FromDescr in project drools by kiegroup.
the class RuleParserTest method testForallWithFrom.
@Test
public void testForallWithFrom() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "forallwithfrom.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final ForallDescr forall = (ForallDescr) rule.getLhs().getDescrs().get(0);
assertEquals(2, forall.getDescrs().size());
final PatternDescr pattern = forall.getBasePattern();
assertEquals("Person", pattern.getObjectType());
assertEquals("$village", ((FromDescr) pattern.getSource()).getDataSource().toString());
final List<BaseDescr> remaining = forall.getRemainingPatterns();
assertEquals(1, remaining.size());
final PatternDescr cheese = (PatternDescr) remaining.get(0);
assertEquals("Cheese", cheese.getObjectType());
assertEquals("$cheesery", ((FromDescr) cheese.getSource()).getDataSource().toString());
}
use of org.drools.drl.ast.descr.FromDescr 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());
}
Aggregations