Search in sources :

Example 1 with MyError

use of org.jbpm.bpmn2.objects.MyError in project jbpm by kiegroup.

the class ErrorEventTest method testCatchErrorBoundaryEventOnTask.

@Test
public void testCatchErrorBoundaryEventOnTask() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ErrorBoundaryEventOnTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            if (workItem.getParameter("ActorId").equals("mary")) {
                throw new MyError();
            }
        }

        @Override
        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
            manager.abortWorkItem(workItem.getId());
        }
    });
    ProcessInstance processInstance = ksession.startProcess("BPMN2-ErrorBoundaryEventOnTask");
    assertProcessInstanceActive(processInstance);
    assertNodeTriggered(processInstance.getId(), "start", "split", "User Task", "User task error attached", "Script Task", "error1", "error2");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) MyError(org.jbpm.bpmn2.objects.MyError) KieBase(org.kie.api.KieBase) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 2 with MyError

use of org.jbpm.bpmn2.objects.MyError in project jbpm by kiegroup.

the class ErrorEventTest method testEventSubprocessErrorThrowOnTask.

@Test
public void testEventSubprocessErrorThrowOnTask() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessError.bpmn2");
    final List<Long> executednodes = new ArrayList<Long>();
    ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
                executednodes.add(event.getNodeInstance().getId());
            }
        }
    };
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(listener);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            throw new MyError();
        }

        @Override
        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
            manager.abortWorkItem(workItem.getId());
        }
    });
    ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessError");
    assertProcessInstanceFinished(processInstance, ksession);
    assertProcessInstanceAborted(processInstance);
    assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
    assertEquals(1, executednodes.size());
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) MyError(org.jbpm.bpmn2.objects.MyError) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ArrayList(java.util.ArrayList) WorkItem(org.kie.api.runtime.process.WorkItem) KieBase(org.kie.api.KieBase) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Aggregations

MyError (org.jbpm.bpmn2.objects.MyError)2 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)2 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)2 Test (org.junit.Test)2 KieBase (org.kie.api.KieBase)2 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 WorkItem (org.kie.api.runtime.process.WorkItem)2 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)2 ArrayList (java.util.ArrayList)1 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)1 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)1 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)1