use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testInfinityLiteral.
@Test
public void testInfinityLiteral() throws Exception {
final String text = "rule \"infinity\"\n" + "when\n" + " StockTick( this after[-*,*] $another )\n" + "then\n" + "end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals("StockTick", pattern.getObjectType());
ExprConstraintDescr constr = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0);
assertEquals("this after[-*,*] $another", constr.getText());
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testMemberof.
@Test
public void testMemberof() throws Exception {
final String text = "rule X when Country( $cities : city )\nPerson( city memberOf $cities )\n then end";
AndDescr descrs = ((RuleDescr) parse("rule", text)).getLhs();
assertEquals(2, descrs.getDescrs().size());
PatternDescr pat = (PatternDescr) descrs.getDescrs().get(1);
ExprConstraintDescr fieldConstr = (ExprConstraintDescr) pat.getConstraint().getDescrs().get(0);
assertEquals("city memberOf $cities", fieldConstr.getExpression());
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testAccumulate.
@Test
public void testAccumulate() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "accumulate.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final PatternDescr outPattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
final AccumulateDescr accum = (AccumulateDescr) outPattern.getSource();
assertEqualsIgnoreWhitespace("int x = 0 ;", accum.getInitCode());
assertEqualsIgnoreWhitespace("x++;", accum.getActionCode());
assertNull(accum.getReverseCode());
assertEqualsIgnoreWhitespace("new Integer(x)", accum.getResultCode());
assertFalse(accum.isExternalFunction());
final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
assertEquals("Person", pattern.getObjectType());
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testOrWithBinding.
/**
* test basic foo : Fact() || Fact() stuff
*/
@Test
public void testOrWithBinding() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "or_binding.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(2, rule.getLhs().getDescrs().size());
final OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(0);
assertEquals(2, or.getDescrs().size());
final PatternDescr leftPattern = (PatternDescr) or.getDescrs().get(0);
assertEquals("Person", leftPattern.getObjectType());
assertEquals("foo", leftPattern.getIdentifier());
final PatternDescr rightPattern = (PatternDescr) or.getDescrs().get(1);
assertEquals("Person", rightPattern.getObjectType());
assertEquals("foo", rightPattern.getIdentifier());
final PatternDescr cheeseDescr = (PatternDescr) rule.getLhs().getDescrs().get(1);
assertEquals("Cheese", cheeseDescr.getObjectType());
assertEquals(null, cheeseDescr.getIdentifier());
assertEqualsIgnoreWhitespace("System.out.println( \"Mark and Michael\" + bar );", (String) rule.getConsequence());
}
use of org.drools.compiler.lang.descr.PatternDescr 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());
}
Aggregations