use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testEnumeration.
@Test
public void testEnumeration() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "enumeration.drl");
assertEquals("simple_rule", rule.getName());
assertEquals(1, rule.getLhs().getDescrs().size());
final PatternDescr col = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Foo", col.getObjectType());
assertEquals(1, col.getConstraint().getDescrs().size());
final ExprConstraintDescr fld = (ExprConstraintDescr) col.getConstraint().getDescrs().get(0);
assertEquals("bar == Foo.BAR", fld.getExpression());
}
use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.
the class RuleParserTest method testEntryPoint.
@Test
public void testEntryPoint() throws Exception {
final String text = "rule X when StockTick( symbol==\"ACME\") from entry-point StreamA then end";
PackageDescr pkg = (PackageDescr) parse("compilationUnit", text);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
RuleDescr rule = pkg.getRules().get(0);
PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals(1, pattern.getDescrs().size());
ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("symbol==\"ACME\"", fcd.getExpression());
assertNotNull(pattern.getSource());
EntryPointDescr entry = (EntryPointDescr) pattern.getSource();
assertEquals("StreamA", entry.getEntryId());
}
use of org.drools.drl.ast.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.drl.ast.descr.ExprConstraintDescr 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.ExprConstraintDescr 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());
}
Aggregations