use of org.drools.compiler.lang.descr.PackageDescr 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));
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class RuleParserTest method testAccumulateWithNestedFrom.
@Test
public void testAccumulateWithNestedFrom() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "accumulate_with_nested_from.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get(0);
final AccumulateDescr accumulate = (AccumulateDescr) out.getSource();
PatternDescr person = (PatternDescr) accumulate.getInputPattern();
assertEquals("Person", person.getObjectType());
final CollectDescr collect2 = (CollectDescr) person.getSource();
final PatternDescr people = collect2.getInputPattern();
assertEquals("People", people.getObjectType());
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class RuleParserTest method testAccumulateMnemonic.
@Test
public void testAccumulateMnemonic() throws Exception {
String drl = "package org.drools.compiler\n" + "rule \"Accumulate 1\"\n" + "when\n" + " acc( Cheese( $price : price ),\n" + " $a1 : average( $price ) )\n" + "then\n" + "end\n";
final PackageDescr pkg = (PackageDescr) parse("compilationUnit", drl);
assertEquals(1, pkg.getRules().size());
RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Object", out.getObjectType());
AccumulateDescr accum = (AccumulateDescr) out.getSource();
assertTrue(accum.isExternalFunction());
List<AccumulateFunctionCallDescr> functions = accum.getFunctions();
assertEquals(1, functions.size());
assertEquals("average", functions.get(0).getFunction());
assertEquals("$a1", functions.get(0).getBind());
assertEquals("$price", functions.get(0).getParams()[0]);
final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
assertEquals("Cheese", pattern.getObjectType());
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class RuleParserTest method testWithPredicate.
@Test
public void testWithPredicate() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "with_predicate.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final PatternDescr col = (PatternDescr) rule.getLhs().getDescrs().get(0);
AndDescr and = (AndDescr) col.getConstraint();
assertEquals(2, and.getDescrs().size());
final ExprConstraintDescr field = (ExprConstraintDescr) col.getDescrs().get(0);
final ExprConstraintDescr pred = (ExprConstraintDescr) and.getDescrs().get(1);
assertEquals("$age2:age", field.getExpression());
assertEqualsIgnoreWhitespace("$age2 == $age1+2", pred.getExpression());
}
use of org.drools.compiler.lang.descr.PackageDescr in project drools by kiegroup.
the class RuleParserTest method testAccumulateExternalFunction.
@Test
public void testAccumulateExternalFunction() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "accumulateExternalFunction.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get(0);
final AccumulateDescr accum = (AccumulateDescr) out.getSource();
assertEqualsIgnoreWhitespace("$age", accum.getFunctions().get(0).getParams()[0]);
assertEqualsIgnoreWhitespace("average", accum.getFunctions().get(0).getFunction());
assertTrue(accum.isExternalFunction());
final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
assertEquals("Person", pattern.getObjectType());
}
Aggregations