use of org.jbpm.process.instance.LightProcessRuntimeServiceProvider in project kogito-runtimes by kiegroup.
the class ProcessFactoryTest method testBoundaryErrorEvent.
@Test
public void testBoundaryErrorEvent() throws Exception {
final String boundaryErrorEvent = "BoundaryErrorEvent";
final String errorCode = "java.lang.RuntimeException";
final String processId = "myProcess";
final RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess(processId);
final String startNode = "Start";
final String task = "Task";
final String endOnError = "EndOnError";
factory.name("My process").packageName("org.kie.kogito").startNode(1).name(startNode).metaData(UNIQUE_ID, startNode).done().workItemNode(2).name(task).workName(task).done().endNode(3).name("EndOnSuccess").done().boundaryEventNode(4).name(boundaryErrorEvent).attachedTo(2).metaData(ERROR_EVENT, errorCode).metaData(HAS_ERROR_EVENT, true).metaData(ERROR_STRUCTURE_REF, null).metaData("EventTpe", "error").metaData(UNIQUE_ID, boundaryErrorEvent).eventType("Error", errorCode).done().endNode(5).name(endOnError).metaData(UNIQUE_ID, endOnError).terminate(true).done().connection(1, 2).connection(2, 3).connection(4, 5);
final RuleFlowProcess process = factory.validate().getProcess();
Application application = mock(Application.class);
when(application.get(Processes.class)).thenReturn(new BpmnProcesses().addProcess(new BpmnProcess(process)));
final LightProcessRuntime processRuntime = LightProcessRuntime.of(application, Collections.singletonList(process), new LightProcessRuntimeServiceProvider());
processRuntime.getKogitoWorkItemManager().registerWorkItemHandler(task, new ExceptionOnPurposeHandler());
final List<String> completedNodes = new ArrayList<>();
final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
completedNodes.add(event.getNodeInstance().getNodeName());
super.afterNodeLeft(event);
}
};
processRuntime.addEventListener(listener);
ProcessInstance processInstance = processRuntime.startProcess(processId);
assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED);
assertThat(completedNodes).contains(startNode, task, boundaryErrorEvent, endOnError);
}
Aggregations