Search in sources :

Example 1 with DefaultWorkItemManager

use of org.drools.core.process.instance.impl.DefaultWorkItemManager in project drools by kiegroup.

the class RegisterWorkItemHandlerTest method testRegisterWorkItemHandlerWithStatelessSession.

@Test
public void testRegisterWorkItemHandlerWithStatelessSession() {
    String str = "package org.kie.workitem.test \n" + "import " + DefaultWorkItemManager.class.getCanonicalName() + "\n" + "import " + WorkItem.class.getCanonicalName() + "\n" + "import " + WorkItemImpl.class.getCanonicalName() + "\n" + "rule r1 when \n" + "then \n" + "  WorkItem wi = new WorkItemImpl(); \n" + "  wi.setName( \"wihandler\" ); \n" + "  DefaultWorkItemManager wim = ( DefaultWorkItemManager ) kcontext.getKieRuntime().getWorkItemManager(); \n" + "  wim.internalExecuteWorkItem(wi); \n" + "end \n";
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
    if (kbuilder.hasErrors()) {
        fail(kbuilder.getErrors().toString());
    }
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    final boolean[] answer = new boolean[] { false };
    StatelessKieSession ks = kbase.newStatelessKieSession();
    ks.execute(CommandFactory.newRegisterWorkItemHandlerCommand(new WorkItemHandler() {

        public void executeWorkItem(org.kie.api.runtime.process.WorkItem workItem, WorkItemManager manager) {
            answer[0] = true;
        }

        public void abortWorkItem(org.kie.api.runtime.process.WorkItem workItem, WorkItemManager manager) {
        // TODO Auto-generated method stub
        }
    }, "wihandler"));
    assertTrue(answer[0]);
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) WorkItem(org.drools.core.process.instance.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Aggregations

InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 WorkItem (org.drools.core.process.instance.WorkItem)1 DefaultWorkItemManager (org.drools.core.process.instance.impl.DefaultWorkItemManager)1 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)1 Test (org.junit.Test)1 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)1 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)1 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)1 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)1