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]);
}
Aggregations