use of org.drools.drl.ast.descr.AndDescr 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.drl.ast.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testNotNode.
@Test
public void testNotNode() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "rule_not.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertNotNull(rule);
assertEquals("simple_rule", rule.getName());
final AndDescr lhs = rule.getLhs();
assertEquals(1, lhs.getDescrs().size());
final NotDescr not = (NotDescr) lhs.getDescrs().get(0);
assertEquals(1, not.getDescrs().size());
final PatternDescr pattern = (PatternDescr) not.getDescrs().get(0);
assertEquals("Cheese", pattern.getObjectType());
assertEquals(1, pattern.getConstraint().getDescrs().size());
final AndDescr and = (AndDescr) pattern.getConstraint();
final ExprConstraintDescr fld = (ExprConstraintDescr) and.getDescrs().get(0);
assertEquals("type == \"stilton\"", fld.getExpression());
}
use of org.drools.drl.ast.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testRuleParseLhsWithStringQuotes.
@Test
public void testRuleParseLhsWithStringQuotes() throws Exception {
final String text = "rule X when Person( location==\"atlanta\\\"\") then end\n";
RuleDescr rule = (RuleDescr) parse("rule", text);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertNotNull(rule);
AndDescr lhs = rule.getLhs();
ExprConstraintDescr constr = (ExprConstraintDescr) ((PatternDescr) lhs.getDescrs().get(0)).getDescrs().get(0);
assertEquals("location==\"atlanta\\\"\"", constr.getText());
}
use of org.drools.drl.ast.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testStringEscapes.
@Test
public void testStringEscapes() throws Exception {
String source = "package com.sample rule test when Cheese( type 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());
assertEquals(1, rule.getLhs().getDescrs().size());
PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
AndDescr constraint = (AndDescr) pattern.getConstraint();
assertEquals(1, constraint.getDescrs().size());
assertEquals("type matches \"\\..*\\\\.\"", constraint.getDescrs().get(0).toString());
}
use of org.drools.drl.ast.descr.AndDescr in project drools by kiegroup.
the class RuleParserTest method testRuleParseLhs.
@Test
public void testRuleParseLhs() throws Exception {
final String text = "rule X when Person(age < 42, location==\"atlanta\") \nor\nPerson(name==\"bob\") then end";
RuleDescr rule = (RuleDescr) parse("rule", text);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertNotNull(rule);
AndDescr lhs = rule.getLhs();
assertEquals(1, lhs.getDescrs().size());
assertEquals(2, ((OrDescr) lhs.getDescrs().get(0)).getDescrs().size());
}
Aggregations