Search in sources :

Example 11 with FunctionDescr

use of org.drools.compiler.lang.descr.FunctionDescr in project drools by kiegroup.

the class RuleParserTest method testFunctions.

@Test
public void testFunctions() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "functions.drl");
    assertEquals(2, pkg.getRules().size());
    final List<FunctionDescr> functions = pkg.getFunctions();
    assertEquals(2, functions.size());
    FunctionDescr func = functions.get(0);
    assertEquals("functionA", func.getName());
    assertEquals("String", func.getReturnType());
    assertEquals(2, func.getParameterNames().size());
    assertEquals(2, func.getParameterTypes().size());
    assertEquals(19, func.getLine());
    assertEquals(0, func.getColumn());
    assertEquals("String", func.getParameterTypes().get(0));
    assertEquals("s", func.getParameterNames().get(0));
    assertEquals("Integer", func.getParameterTypes().get(1));
    assertEquals("i", func.getParameterNames().get(1));
    assertEqualsIgnoreWhitespace("foo();", func.getBody());
    func = functions.get(1);
    assertEquals("functionB", func.getName());
    assertEqualsIgnoreWhitespace("bar();", func.getText());
}
Also used : PackageDescr(org.drools.compiler.lang.descr.PackageDescr) FunctionDescr(org.drools.compiler.lang.descr.FunctionDescr) Test(org.junit.Test)

Aggregations

FunctionDescr (org.drools.compiler.lang.descr.FunctionDescr)11 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)8 Test (org.junit.Test)5 List (java.util.List)4 GlobalDescr (org.drools.compiler.lang.descr.GlobalDescr)4 InputStreamReader (java.io.InputStreamReader)3 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)3 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)3 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)1 DrlParser (org.drools.compiler.compiler.DrlParser)1 DuplicateFunction (org.drools.compiler.compiler.DuplicateFunction)1 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)1 AndDescr (org.drools.compiler.lang.descr.AndDescr)1