use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testRuleWithLHSNesting.
@Test
public void testRuleWithLHSNesting() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "Rule_with_nested_LHS.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
RuleDescr rule = pkg.getRules().get(0);
assertEquals("test", rule.getName());
AndDescr lhs = rule.getLhs();
assertNotNull(lhs);
assertEquals(2, lhs.getDescrs().size());
PatternDescr a = (PatternDescr) lhs.getDescrs().get(0);
assertEquals("A", a.getObjectType());
OrDescr or = (OrDescr) lhs.getDescrs().get(1);
assertEquals(3, or.getDescrs().size());
AndDescr and1 = (AndDescr) or.getDescrs().get(0);
assertEquals(2, and1.getDescrs().size());
PatternDescr b = (PatternDescr) and1.getDescrs().get(0);
PatternDescr c = (PatternDescr) and1.getDescrs().get(1);
assertEquals("B", b.getObjectType());
assertEquals("C", c.getObjectType());
AndDescr and2 = (AndDescr) or.getDescrs().get(1);
assertEquals(2, and2.getDescrs().size());
PatternDescr d = (PatternDescr) and2.getDescrs().get(0);
PatternDescr e = (PatternDescr) and2.getDescrs().get(1);
assertEquals("D", d.getObjectType());
assertEquals("E", e.getObjectType());
AndDescr and3 = (AndDescr) or.getDescrs().get(2);
assertEquals(2, and3.getDescrs().size());
PatternDescr f = (PatternDescr) and3.getDescrs().get(0);
PatternDescr g = (PatternDescr) and3.getDescrs().get(1);
assertEquals("F", f.getObjectType());
assertEquals("G", g.getObjectType());
}
use of org.drools.compiler.lang.descr.RuleDescr 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.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testRuleExtends.
@Test
public void testRuleExtends() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "Rule_with_Extends.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
RuleDescr rule = pkg.getRules().get(0);
assertTrue(rule.getParentName() != null);
assertEquals("rule1", rule.getParentName());
AndDescr lhs = rule.getLhs();
assertNotNull(lhs);
assertEquals(1, lhs.getDescrs().size());
PatternDescr pattern = (PatternDescr) lhs.getDescrs().get(0);
assertEquals("foo", pattern.getObjectType());
assertEquals("$foo", pattern.getIdentifier());
}
use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testCalendars2.
@Test
public void testCalendars2() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "rule_calendars_attribute2.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertEquals("simple_rule", rule.getName());
assertEqualsIgnoreWhitespace("bar();", (String) rule.getConsequence());
final Map<String, AttributeDescr> attrs = rule.getAttributes();
assertEquals(2, attrs.size());
AttributeDescr at = (AttributeDescr) attrs.get("calendars");
assertEquals("calendars", at.getName());
assertEquals("[ \"cal 1\", \"cal 2\", \"cal 3\" ]", at.getValue());
at = (AttributeDescr) attrs.get("lock-on-active");
assertEquals("lock-on-active", at.getName());
assertEquals("true", at.getValue());
}
use of org.drools.compiler.lang.descr.RuleDescr in project drools by kiegroup.
the class RuleParserTest method testFunctionWithArrays.
// public void FIXME_testLatinChars() throws Exception {
// final DrlParser parser = new DrlParser();
// final Reader drl = new InputStreamReader( this.getClass().getResourceAsStream( "latin-sample.dslr" ) );
// final Reader dsl = new InputStreamReader( this.getClass().getResourceAsStream( "latin.dsl" ) );
//
// final PackageDescr pkg = parser.parse( drl,
// dsl );
//
// // MN: will get some errors due to the char encoding on my FC5 install
// // others who use the right encoding may not see this, feel free to
// // uncomment
// // the following assertion.
// assertFalse( parser.hasErrors() );
//
// assertEquals( "br.com.auster.drools.sample",
// pkg.getName() );
// assertEquals( 1,
// pkg.getRules().size() );
//
// }
//
@Test
public void testFunctionWithArrays() throws Exception {
PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "function_arrays.drl");
assertEquals("foo", pkg.getName());
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEqualsIgnoreWhitespace("yourFunction(new String[3] {\"a\",\"b\",\"c\"});", (String) rule.getConsequence());
final FunctionDescr func = (FunctionDescr) pkg.getFunctions().get(0);
assertEquals("String[]", func.getReturnType());
assertEquals("args[]", func.getParameterNames().get(0));
assertEquals("String", func.getParameterTypes().get(0));
}
Aggregations