Process Nodes Not Executing in JUnit Test
tujasiri Mar 12, 2015 12:01 PMGreetings,
In Eclipse, I have a simple Business Process Model, consisting of two Service Task nodes, that looks like this:
The ProcessTest Class code looks like this:
public class ProcessTest extends JbpmJUnitBaseTestCase {
@Test
public void testProcess() {
KieHelper kieHelper = new KieHelper();
KieBase kbase = kieHelper.addResource(ResourceFactory
.newClassPathResource("briefverify_mod.bpmn2"))
.build();
KieSession ksession = kbase.newKieSession();
KieRuntimeLogger logger = KieServices.Factory.get().getLoggers()
.newThreadedFileLogger(ksession, "src/main/resources/mylogfile", 1000);
try{
ksession.getWorkItemManager().registerWorkItemHandler("Service Task", new MyWorkItemHandler());
}
catch (Exception ex){
System.err.println("WorkitemHandler==>"+ex.toString());
}
System.out.println("before process instance start");
System.out.println("Session ID ==>"+ksession.getId());
ProcessInstance processInstance = ksession.startProcess("ServiceProcess");
System.out.println("process instance started");
assertProcessInstanceCompleted(processInstance.getId(), ksession);
//assertNodeTriggered(processInstance.getId(),"StartProcess");
ksession.dispose();
logger.close();
System.out.println("reached the end...");
}
}
That gets the first node executed. How do I get subsequent nodes to execute?
Here's the MyWorkItemHandler.java code:
public class MyWorkItemHandler implements WorkItemHandler{
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
String service = (String) workItem.getParameter("Interface");
String operation = (String) workItem.getParameter("Operation");
String parameterType = (String) workItem.getParameter("ParameterType");
Object parameter = workItem.getParameter("Parameter");
try {
Class<?> c = Class.forName(service);
Object instance = c.newInstance();
Class<?>[] classes = null;
Object[] params = null;
if (parameterType != null) {
classes = new Class<?>[] {
Class.forName(parameterType)
};
params = new Object[] {
parameter
};
}
Method method = c.getMethod(operation, classes);
Object result = method.invoke(instance, params);
Map<String, Object> results = new HashMap<String, Object>();
results.put("Result", result);
manager.completeWorkItem(workItem.getId(), results);
} catch (ClassNotFoundException cnfe) {
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
manager.completeWorkItem(workItem.getId(), null);
}
public void abortWorkItem (WorkItem workItem, WorkItemManager manager) {
// Nothing
System.out.println("Hell0 there...Aborting...");
}
}
Message was edited by: Tajiri Ujasiri