Search in sources :

Example 1 with InvokerStub

use of org.drools.mvel.asm.InvokerStub in project drools by kiegroup.

the class InvokerGeneratorTest method testGenerate.

@Test
public void testGenerate() {
    Map<String, Object> invokerContext = new HashMap<String, Object>();
    invokerContext.put("package", "pkg");
    invokerContext.put("invokerClassName", "TestInvoker");
    invokerContext.put("ruleClassName", "TestRule");
    invokerContext.put("methodName", "testMethod");
    invokerContext.put("consequenceName", "TestConsequence");
    invokerContext.put("hashCode", 111);
    invokerContext.put("declarations", new Declaration[0]);
    invokerContext.put("globals", new String[] { "globalList" });
    invokerContext.put("globalTypes", new String[] { "java/util/List" });
    Set<String> imports = new HashSet<String>();
    imports.add("p1");
    imports.add("p2");
    final ClassGenerator generator = InvokerGenerator.createStubGenerator(new InvokerContext(invokerContext), getClass().getClassLoader(), null, imports);
    generator.setInterfaces(InvokerStub.class);
    InvokerStub stub = generator.newInstance();
    assertEquals("pkg", stub.getPackageName());
    assertEquals("TestRule", stub.getRuleClassName());
    assertEquals("testMethod", stub.getMethodName());
    assertEquals("TestInvokerGenerated", stub.getGeneratedInvokerClassName());
    assertEquals(111, stub.hashCode());
    assertTrue(Arrays.equals(new String[] { "globalList" }, stub.getGlobals()));
    assertTrue(Arrays.equals(new String[] { "java/util/List" }, stub.getGlobalTypes()));
    List<String> importList = Arrays.asList(stub.getPackageImports());
    assertTrue(importList.contains("p1"));
    assertTrue(importList.contains("p2"));
}
Also used : ClassGenerator(org.drools.mvel.asm.ClassGenerator) HashMap(java.util.HashMap) InvokerContext(org.drools.mvel.asm.InvokerContext) InvokerStub(org.drools.mvel.asm.InvokerStub) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ClassGenerator (org.drools.mvel.asm.ClassGenerator)1 InvokerContext (org.drools.mvel.asm.InvokerContext)1 InvokerStub (org.drools.mvel.asm.InvokerStub)1 Test (org.junit.Test)1