use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testNotInOperator.
@Test
public void testNotInOperator() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "notin_operator_test.drl");
assertNotNull(rule);
assertEqualsIgnoreWhitespace("consequence();", (String) rule.getConsequence());
assertEquals("simple_rule", rule.getName());
assertEquals(2, rule.getLhs().getDescrs().size());
// The first pattern, with 2 restrictions on a single field (plus a
// connective)
PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Person", pattern.getObjectType());
assertEquals(1, pattern.getConstraint().getDescrs().size());
ExprConstraintDescr fld = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0);
assertEquals("age > 30 && < 40", fld.getExpression());
// the second col, with 2 fields, the first with 2 restrictions, the
// second field with one
pattern = (PatternDescr) rule.getLhs().getDescrs().get(1);
assertEquals("Vehicle", pattern.getObjectType());
assertEquals(2, pattern.getConstraint().getDescrs().size());
fld = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0);
assertEquals("type not in ( \"sedan\", \"wagon\" )", fld.getExpression());
// now the second field
fld = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(1);
assertEquals("age < 3", fld.getExpression());
}
use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testBoundVariables.
@Test
public void testBoundVariables() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "bindings.drl");
final RuleDescr ruleDescr = (RuleDescr) pkg.getRules().get(0);
final AndDescr lhs = ruleDescr.getLhs();
assertEquals(2, lhs.getDescrs().size());
final PatternDescr cheese = (PatternDescr) lhs.getDescrs().get(0);
assertEquals("Cheese", cheese.getObjectType());
assertEquals(1, cheese.getDescrs().size());
ExprConstraintDescr fieldBinding = (ExprConstraintDescr) cheese.getDescrs().get(0);
assertEquals("$type : type == \"stilton\"", fieldBinding.getExpression());
final PatternDescr person = (PatternDescr) lhs.getDescrs().get(1);
assertEquals(2, person.getDescrs().size());
fieldBinding = (ExprConstraintDescr) person.getDescrs().get(0);
assertEquals("$name : name == \"bob\"", fieldBinding.getExpression());
ExprConstraintDescr fld = (ExprConstraintDescr) person.getDescrs().get(1);
assertEquals("likes == $type", fld.getExpression());
}
use of org.drools.compiler.lang.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testCompatibleRestriction.
@Test
public void testCompatibleRestriction() throws Exception {
String source = "package com.sample rule test when Test( ( text == null || text2 matches \"\" ) ) then end";
PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
assertEquals("com.sample", pkg.getName());
RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals("test", rule.getName());
ExprConstraintDescr expr = (ExprConstraintDescr) ((PatternDescr) rule.getLhs().getDescrs().get(0)).getDescrs().get(0);
assertEquals("( text == null || text2 matches \"\" )", expr.getText());
}
use of org.drools.compiler.lang.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());
}
use of org.drools.compiler.lang.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());
}
Aggregations