use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testPositionalConstraintsOnly.
@Test
public void testPositionalConstraintsOnly() throws Exception {
final String text = "rule X when Person( \"Mark\", 42; ) then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals(2, pattern.getDescrs().size());
ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("\"Mark\"", fcd.getExpression());
assertEquals(0, fcd.getPosition());
assertEquals(ExprConstraintDescr.Type.POSITIONAL, fcd.getType());
fcd = (ExprConstraintDescr) pattern.getDescrs().get(1);
assertEquals("42", fcd.getExpression());
assertEquals(1, fcd.getPosition());
assertEquals(ExprConstraintDescr.Type.POSITIONAL, fcd.getType());
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testAccumulateMultiPattern.
@Test
public void testAccumulateMultiPattern() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "accumulate_multi_pattern.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("$counter", outPattern.getIdentifier());
assertEqualsIgnoreWhitespace("int x = 0 ;", accum.getInitCode());
assertEqualsIgnoreWhitespace("x++;", accum.getActionCode());
assertEqualsIgnoreWhitespace("new Integer(x)", accum.getResultCode());
final AndDescr and = (AndDescr) accum.getInput();
assertEquals(2, and.getDescrs().size());
final PatternDescr person = (PatternDescr) and.getDescrs().get(0);
final PatternDescr cheese = (PatternDescr) and.getDescrs().get(1);
assertEquals("Person", person.getObjectType());
assertEquals("Cheese", cheese.getObjectType());
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testCollect.
@Test
public void testCollect() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "collect.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 CollectDescr collect = (CollectDescr) outPattern.getSource();
final PatternDescr pattern = (PatternDescr) collect.getInputPattern();
assertEquals("Person", pattern.getObjectType());
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testRestrictions.
@Test
public void testRestrictions() throws Exception {
final String text = "rule X when Foo( bar > 1 || == 1 ) then end\n";
AndDescr descrs = (AndDescr) ((RuleDescr) parse("rule", text)).getLhs();
assertEquals(1, descrs.getDescrs().size());
PatternDescr pat = (PatternDescr) descrs.getDescrs().get(0);
ExprConstraintDescr fieldConstr = (ExprConstraintDescr) pat.getConstraint().getDescrs().get(0);
assertEquals("bar > 1 || == 1", fieldConstr.getExpression());
}
use of org.drools.compiler.lang.descr.PatternDescr in project drools by kiegroup.
the class RuleParserTest method testBigLiterals.
@Test
public void testBigLiterals() throws Exception {
final String text = "rule X when Primitives( bigInteger == (10I), " + " bigDecimal == (10B), " + " bigInteger < 50I, " + " bigDecimal < 50B ) then end";
PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
assertEquals(4, pattern.getDescrs().size());
ExprConstraintDescr ecd = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("bigInteger == (10I)", ecd.getExpression());
ecd = (ExprConstraintDescr) pattern.getDescrs().get(1);
assertEquals("bigDecimal == (10B)", ecd.getExpression());
ecd = (ExprConstraintDescr) pattern.getDescrs().get(2);
assertEquals("bigInteger < 50I", ecd.getExpression());
ecd = (ExprConstraintDescr) pattern.getDescrs().get(3);
assertEquals("bigDecimal < 50B", ecd.getExpression());
}
Aggregations