use of org.drools.drl.ast.descr.RuleDescr 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.RuleDescr 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.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testGlobal.
@Test
public void testGlobal() throws Exception {
PackageDescr pack = (PackageDescr) parseResource("compilationUnit", "globals.drl");
assertEquals(1, pack.getRules().size());
final RuleDescr rule = (RuleDescr) pack.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
assertEquals(1, pack.getImports().size());
assertEquals(2, pack.getGlobals().size());
final GlobalDescr foo = (GlobalDescr) pack.getGlobals().get(0);
assertEquals("java.lang.String", foo.getType());
assertEquals("foo", foo.getIdentifier());
final GlobalDescr bar = (GlobalDescr) pack.getGlobals().get(1);
assertEquals("java.lang.Integer", bar.getType());
assertEquals("bar", bar.getIdentifier());
}
use of org.drools.drl.ast.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testEnabledExpression.
@Test
public void testEnabledExpression() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "rule_enabled_expression.drl");
assertEquals("simple_rule", rule.getName());
assertEqualsIgnoreWhitespace("bar();", (String) rule.getConsequence());
final Map<String, AttributeDescr> attrs = rule.getAttributes();
assertEquals(3, attrs.size());
AttributeDescr at = (AttributeDescr) attrs.get("enabled");
assertEquals("enabled", at.getName());
assertEquals("( 1 + 1 == 2 )", at.getValue());
at = (AttributeDescr) attrs.get("salience");
assertEquals("salience", at.getName());
assertEquals("( 1+2 )", at.getValue());
at = (AttributeDescr) attrs.get("lock-on-active");
assertEquals("lock-on-active", at.getName());
assertEquals("true", at.getValue());
}
use of org.drools.drl.ast.descr.RuleDescr 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());
}
Aggregations