use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testNotWithConstraint.
@Test
public void testNotWithConstraint() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "not_with_constraint.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(2, rule.getLhs().getDescrs().size());
PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
final ExprConstraintDescr fieldBinding = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("$likes:like", fieldBinding.getExpression());
final NotDescr not = (NotDescr) rule.getLhs().getDescrs().get(1);
pattern = (PatternDescr) not.getDescrs().get(0);
final ExprConstraintDescr fld = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0);
assertEquals("type == $likes", fld.getExpression());
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testOrWithSpecialBind.
@Test
public void testOrWithSpecialBind() throws Exception {
String source = "rule \"A and (B or C or D)\" \n" + " when \n" + " pdo1 : ParametricDataObject( paramID == 101, stringValue == \"1000\" ) and \n" + " pdo2 :(ParametricDataObject( paramID == 101, stringValue == \"1001\" ) or \n" + " ParametricDataObject( paramID == 101, stringValue == \"1002\" ) or \n" + " ParametricDataObject( paramID == 101, stringValue == \"1003\" )) \n" + " then \n" + " System.out.println( \"Rule: A and (B or C or D) Fired. pdo1: \" + pdo1 + \" pdo2: \"+ pdo2); \n" + "end\n";
PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
RuleDescr rule = pkg.getRules().get(0);
AndDescr lhs = rule.getLhs();
assertEquals(2, lhs.getDescrs().size());
PatternDescr pdo1 = (PatternDescr) lhs.getDescrs().get(0);
assertEquals("pdo1", pdo1.getIdentifier());
OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(1);
assertEquals(3, or.getDescrs().size());
for (BaseDescr pdo2 : or.getDescrs()) {
assertEquals("pdo2", ((PatternDescr) pdo2).getIdentifier());
}
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testConstraintOrConnective.
@Test
public void testConstraintOrConnective() throws Exception {
final String text = "rule X when Person( age < 42 || location==\"atlanta\") then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals(1, pattern.getDescrs().size());
ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("age < 42 || location==\"atlanta\"", fcd.getExpression());
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testNestedCEs.
@Test
public void testNestedCEs() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "nested_conditional_elements.drl");
assertNotNull(rule);
final AndDescr root = rule.getLhs();
final NotDescr not1 = (NotDescr) root.getDescrs().get(0);
final AndDescr and1 = (AndDescr) not1.getDescrs().get(0);
final PatternDescr state = (PatternDescr) and1.getDescrs().get(0);
final NotDescr not2 = (NotDescr) and1.getDescrs().get(1);
final AndDescr and2 = (AndDescr) not2.getDescrs().get(0);
final PatternDescr person = (PatternDescr) and2.getDescrs().get(0);
final PatternDescr cheese = (PatternDescr) and2.getDescrs().get(1);
final PatternDescr person2 = (PatternDescr) root.getDescrs().get(1);
final OrDescr or = (OrDescr) root.getDescrs().get(2);
final PatternDescr cheese2 = (PatternDescr) or.getDescrs().get(0);
final PatternDescr cheese3 = (PatternDescr) or.getDescrs().get(1);
assertEquals(state.getObjectType(), "State");
assertEquals(person.getObjectType(), "Person");
assertEquals(cheese.getObjectType(), "Cheese");
assertEquals(person2.getObjectType(), "Person");
assertEquals(cheese2.getObjectType(), "Cheese");
assertEquals(cheese3.getObjectType(), "Cheese");
}
use of org.drools.compiler.lang.descr.PatternDescr 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());
}
Aggregations