use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testPluggableOperators2.
@Test
public void testPluggableOperators2() throws Exception {
final String text = "rule \"tt\"\n" + " dialect \"mvel\"\n" + "when\n" + " exists (TelephoneCall( this finishes [1m] \"25-May-2011\" ))\n" + "then\n" + "end";
PatternDescr pattern = (PatternDescr) ((ExistsDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0)).getDescrs().get(0);
assertEquals("TelephoneCall", pattern.getObjectType());
ExprConstraintDescr constr = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0);
assertEquals("this finishes [1m] \"25-May-2011\"", constr.getText());
}
use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testWithRetval.
@Test
public void testWithRetval() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "with_retval.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final PatternDescr col = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals(1, col.getConstraint().getDescrs().size());
assertEquals("Foo", col.getObjectType());
final ExprConstraintDescr fld = (ExprConstraintDescr) col.getConstraint().getDescrs().get(0);
assertEquals("name== (a + b)", fld.getExpression());
}
use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testUnificationBinding.
@Test
public void testUnificationBinding() throws Exception {
final String text = "rule X when $p := Person( $name := name, $loc : location ) then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals("$p", pattern.getIdentifier());
assertTrue(pattern.isUnification());
assertEquals(2, pattern.getDescrs().size());
ExprConstraintDescr bindingDescr = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("$name := name", bindingDescr.getExpression());
bindingDescr = (ExprConstraintDescr) pattern.getDescrs().get(1);
assertEquals("$loc : location", bindingDescr.getExpression());
}
use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testNullConstraints.
@Test
public void testNullConstraints() throws Exception {
final String text = "rule X when Person( name == null ) 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("name == null", fcd.getExpression());
assertEquals(0, fcd.getPosition());
assertEquals(ExprConstraintDescr.Type.NAMED, fcd.getType());
}
use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testRuleOldSyntax2.
@Test
public void testRuleOldSyntax2() throws Exception {
final String source = "rule \"Test\" when ( $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());
PatternDescr patternDescr = (PatternDescr) rule.getLhs().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());
}
Aggregations