use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testFromWithTernaryFollowedByQuery.
@Test
public void testFromWithTernaryFollowedByQuery() throws Exception {
// the 'from' expression requires a ";" to disambiguate the "?"
// prefix for queries from the ternary operator "? :"
final String text = "rule X when Cheese() from (isFull ? $cheesery : $market) ?person( \"Mark\", 42; ) then end";
RuleDescr rule = (RuleDescr) parse("rule", text);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Cheese", pattern.getObjectType());
assertEquals("from (isFull ? $cheesery : $market)", pattern.getSource().getText());
assertFalse(pattern.isQuery());
pattern = (PatternDescr) rule.getLhs().getDescrs().get(1);
assertEquals("person", pattern.getObjectType());
assertTrue(pattern.isQuery());
}
use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testOrCE.
@Test
public void testOrCE() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "or_ce.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(2, rule.getLhs().getDescrs().size());
final PatternDescr person = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Person", person.getObjectType());
assertEquals("$p", person.getIdentifier());
final OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(1);
assertEquals(2, or.getDescrs().size());
final PatternDescr cheese1 = (PatternDescr) or.getDescrs().get(0);
assertEquals("Cheese", cheese1.getObjectType());
assertEquals("$c", cheese1.getIdentifier());
final PatternDescr cheese2 = (PatternDescr) or.getDescrs().get(1);
assertEquals("Cheese", cheese2.getObjectType());
assertNull(cheese2.getIdentifier());
}
use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testRuleTwoLines.
@Test
public void testRuleTwoLines() throws Exception {
final String text = "rule \"another test\" salience 10 when eval( true ) then System.out.println(1);\n end";
RuleDescr rule = (RuleDescr) parse("rule", text);
assertEquals("another test", rule.getName());
assertEquals("System.out.println(1);\n ", rule.getConsequence());
}
use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testMultiValueAnnotationsBackwardCompatibility.
@Test
public void testMultiValueAnnotationsBackwardCompatibility() throws Exception {
// multiple values with no keys are parsed as a single value
final String text = "rule X @ann1( val1, val2 ) @ann2( \"val1\", \"val2\" ) when then end";
RuleDescr rule = (RuleDescr) parse("rule", text);
AnnotationDescr ann = rule.getAnnotation("ann1");
assertNotNull(ann);
assertEquals("val1, val2", ann.getValue());
ann = rule.getAnnotation("ann2");
assertNotNull(ann);
assertEquals("\"val1\", \"val2\"", ann.getValue());
}
use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testSlidingWindow.
@Test
public void testSlidingWindow() throws Exception {
final String text = "rule X when StockTick( symbol==\"ACME\") over window:length(10) 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());
List<BehaviorDescr> behaviors = pattern.getBehaviors();
assertNotNull(behaviors);
assertEquals(1, behaviors.size());
BehaviorDescr descr = behaviors.get(0);
assertEquals("window", descr.getType());
assertEquals("length", descr.getSubType());
assertEquals("10", descr.getParameters().get(0));
}
Aggregations