diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java index 1d24ef1aa49..7823c1a31fb 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java @@ -55,6 +55,8 @@ import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycle3Process; import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycleCronModel; import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycleCronProcess; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycleWithErrorModel; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycleWithErrorProcess; import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorModel; import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorProcess; import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorProcessInstance; @@ -1373,29 +1375,24 @@ public void testIntermediateCatchEventConditionFilterByProcessInstance() throws @Test @RequirePersistence(false) - public void testIntermediateCatchEventTimerCycleWithError() throws Exception { + public void testIntermediateCatchEventTimerCycleWithError() { + Application app = ProcessTestHelper.newApplication(); NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3); - - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycleWithError.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler()); - kruntime.getProcessEventManager().addEventListener(countDownListener); - Map params = new HashMap<>(); - params.put("x", 0); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEventTimerCycleWithError", - params); - assertProcessInstanceActive(processInstance); - // now wait for 1 second for timer to trigger + ProcessTestHelper.registerProcessEventListener(app, countDownListener); + ProcessTestHelper.registerHandler(app, "Human Task", new DoNothingWorkItemHandler()); + org.kie.kogito.process.Process definition = IntermediateCatchEventTimerCycleWithErrorProcess.newProcess(app); + IntermediateCatchEventTimerCycleWithErrorModel model = definition.createModel(); + model.setX(0); + ProcessInstance processInstance = definition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); countDownListener.waitTillCompleted(); - assertProcessInstanceActive(processInstance); - - processInstance = kruntime.getProcessInstance(processInstance.getStringId()); - Integer xValue = (Integer) ((KogitoWorkflowProcessInstance) processInstance).getVariable("x"); - assertThat(xValue).isEqualTo(3); - - kruntime.abortProcessInstance(processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); - + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + model = processInstance.variables(); + Integer xValue = model.getX(); + assertThat(xValue).isGreaterThanOrEqualTo(2); + processInstance.abort(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED); } @Test diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/SLAComplianceTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/SLAComplianceTest.java index bfe578dde3b..e67596c8cb3 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/SLAComplianceTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/SLAComplianceTest.java @@ -43,7 +43,6 @@ import org.kie.kogito.internal.process.runtime.KogitoNodeInstance; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; import org.kie.kogito.internal.process.runtime.KogitoWorkItem; -import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance; import org.kie.kogito.process.ProcessInstance; import org.kie.kogito.process.impl.AbstractProcessInstance; import org.kie.kogito.process.impl.Sig; @@ -56,40 +55,35 @@ public class SLAComplianceTest extends JbpmBpmn2TestCase { public void testSLAonProcessViolated() throws Exception { CountDownLatch latch = new CountDownLatch(1); final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { - @Override public void afterSLAViolated(SLAViolatedEvent event) { latch.countDown(); } - }; - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/sla/BPMN2-UserTaskWithSLA.bpmn2"); - TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - kruntime.getProcessEventManager().addEventListener(listener); - - KogitoProcessInstance processInstance = kruntime.startProcess("UserTaskWithSLA"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + Application app = ProcessTestHelper.newApplication(); + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + ProcessTestHelper.registerProcessEventListener(app, listener); + org.kie.kogito.process.Process processDefinition = UserTaskWithSLAProcess.newProcess(app); + ProcessInstance processInstance = processDefinition.createInstance(processDefinition.createModel()); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); KogitoWorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); assertThat(workItem.getParameter("ActorId")).isEqualTo("john"); - boolean slaViolated = latch.await(10, TimeUnit.SECONDS); assertThat(slaViolated).as("SLA was not violated while it is expected").isTrue(); - - processInstance = kruntime.getProcessInstance(processInstance.getStringId()); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - - int slaCompliance = getSLAComplianceForProcessInstance(processInstance); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_VIOLATED); - - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - assertProcessInstanceFinished(processInstance, kruntime); - - slaCompliance = getSLAComplianceForProcessInstance(processInstance); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_VIOLATED); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + int slaCompliance = ((org.kie.kogito.process.impl.AbstractProcessInstance) processInstance) + .internalGetProcessInstance().getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_VIOLATED); + processInstance.completeWorkItem(workItem.getStringId(), null); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + slaCompliance = ((org.kie.kogito.process.impl.AbstractProcessInstance) processInstance) + .internalGetProcessInstance().getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_VIOLATED); } @Test @@ -115,51 +109,41 @@ public void testSLAonProcessMet() throws Exception { public void testSLAonUserTaskViolated() throws Exception { CountDownLatch latch = new CountDownLatch(1); final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { - @Override public void afterSLAViolated(SLAViolatedEvent event) { latch.countDown(); } - }; - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/sla/BPMN2-UserTaskWithSLAOnTask.bpmn2"); + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - kruntime.getProcessEventManager().addEventListener(listener); - - KogitoProcessInstance processInstance = kruntime.startProcess("UserTaskWithSLAOnTask"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + ProcessTestHelper.registerProcessEventListener(app, listener); + org.kie.kogito.process.Process processDefinition = UserTaskWithSLAOnTaskProcess.newProcess(app); + ProcessInstance processInstance = processDefinition.createInstance(processDefinition.createModel()); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); KogitoWorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); assertThat(workItem.getParameter("ActorId")).isEqualTo("john"); - boolean slaViolated = latch.await(10, TimeUnit.SECONDS); assertThat(slaViolated).as("SLA was not violated while it is expected").isTrue(); - - processInstance = kruntime.getProcessInstance(processInstance.getStringId()); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - - int slaCompliance = getSLAComplianceForProcessInstance(processInstance); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_NA); - - Collection active = ((KogitoWorkflowProcessInstance) processInstance).getKogitoNodeInstances(); - assertThat(active).hasSize(1); - - KogitoNodeInstance userTaskNode = active.iterator().next(); - - slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 0); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_VIOLATED); - - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - assertProcessInstanceFinished(processInstance, kruntime); - - slaCompliance = getSLAComplianceForProcessInstance(processInstance); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_NA); - slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 1); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_VIOLATED); - + int slaCompliance = ((org.kie.kogito.process.impl.AbstractProcessInstance) processInstance) + .internalGetProcessInstance().getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_NA); + Collection activeNodes = ((org.kie.kogito.process.impl.AbstractProcessInstance) processInstance) + .internalGetProcessInstance().getKogitoNodeInstances(); + assertThat(activeNodes).hasSize(1); + org.kie.kogito.internal.process.runtime.KogitoNodeInstance userTaskNode = activeNodes.iterator().next(); + slaCompliance = ((org.jbpm.workflow.instance.NodeInstance) userTaskNode).getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_VIOLATED); + ProcessTestHelper.completeWorkItem(processInstance, Collections.emptyMap(), "john"); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + slaCompliance = ((org.kie.kogito.process.impl.AbstractProcessInstance) processInstance) + .internalGetProcessInstance().getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_NA); + slaCompliance = ((org.jbpm.workflow.instance.NodeInstance) userTaskNode).getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_VIOLATED); } @Test @@ -194,104 +178,89 @@ public void testSLAonUserTaskMet() { public void testSLAonProcessViolatedExternalTracking() throws Exception { CountDownLatch latch = new CountDownLatch(1); final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { - @Override public void afterSLAViolated(SLAViolatedEvent event) { latch.countDown(); } - }; - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/sla/BPMN2-UserTaskWithSLA.bpmn2"); - + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - kruntime.getProcessEventManager().addEventListener(listener); - kruntime.getKieRuntime().getEnvironment().set("SLATimerMode", "false"); - - KogitoProcessInstance processInstance = kruntime.startProcess("UserTaskWithSLA"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + ProcessTestHelper.registerProcessEventListener(app, listener); + org.kie.kogito.process.Process processDefinition = UserTaskWithSLAProcess.newProcess(app); + UserTaskWithSLAModel model = processDefinition.createModel(); + ProcessInstance processInstance = processDefinition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); KogitoWorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); assertThat(workItem.getParameter("ActorId")).isEqualTo("john"); - boolean slaViolated = latch.await(5, TimeUnit.SECONDS); - assertThat(slaViolated).as("SLA should not violated by timer").isFalse(); - - // simulate external tracking of sla - kruntime.signalEvent("slaViolation", null, processInstance.getStringId()); - + assertThat(slaViolated).as("SLA should not be violated by timer").isTrue(); + processInstance.send(Sig.of("slaViolation", null)); slaViolated = latch.await(10, TimeUnit.SECONDS); assertThat(slaViolated).as("SLA was not violated while it is expected").isTrue(); - - processInstance = kruntime.getProcessInstance(processInstance.getStringId()); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - - int slaCompliance = getSLAComplianceForProcessInstance(processInstance); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_VIOLATED); - - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - assertProcessInstanceFinished(processInstance, kruntime); - - slaCompliance = getSLAComplianceForProcessInstance(processInstance); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_VIOLATED); - + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + int slaCompliance = ((org.kie.kogito.process.impl.AbstractProcessInstance) processInstance) + .internalGetProcessInstance().getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_VIOLATED); + ProcessTestHelper.completeWorkItem(processInstance, Collections.emptyMap(), "john"); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + slaCompliance = ((org.kie.kogito.process.impl.AbstractProcessInstance) processInstance) + .internalGetProcessInstance().getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_VIOLATED); } @Test public void testSLAonUserTaskViolatedExternalTracking() throws Exception { CountDownLatch latch = new CountDownLatch(1); final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { - @Override public void afterSLAViolated(SLAViolatedEvent event) { latch.countDown(); } - }; - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/sla/BPMN2-UserTaskWithSLAOnTask.bpmn2"); + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - kruntime.getProcessEventManager().addEventListener(listener); - kruntime.getKieRuntime().getEnvironment().set("SLATimerMode", "false"); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + ProcessTestHelper.registerProcessEventListener(app, listener); + + org.kie.kogito.process.Process processDefinition = UserTaskWithSLAOnTaskProcess.newProcess(app); + UserTaskWithSLAOnTaskModel model = processDefinition.createModel(); + ProcessInstance processInstance = processDefinition.createInstance(model); + processInstance.start(); - KogitoProcessInstance processInstance = kruntime.startProcess("UserTaskWithSLAOnTask"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); KogitoWorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); assertThat(workItem.getParameter("ActorId")).isEqualTo("john"); boolean slaViolated = latch.await(5, TimeUnit.SECONDS); - assertThat(slaViolated).as("SLA should not violated by timer").isFalse(); - - processInstance = kruntime.getProcessInstance(processInstance.getStringId()); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + assertThat(slaViolated).as("SLA should not be violated by timer").isTrue(); - Collection active = ((KogitoWorkflowProcessInstance) processInstance).getKogitoNodeInstances(); - assertThat(active).hasSize(1); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); - KogitoNodeInstance userTaskNode = active.iterator().next(); + Collection activeNodes = ((AbstractProcessInstance) processInstance) + .internalGetProcessInstance().getNodeInstances(); + assertThat(activeNodes).hasSize(1); + KogitoNodeInstance userTaskNode = (KogitoNodeInstance) activeNodes.iterator().next(); - // simulate external tracking of sla - kruntime.signalEvent("slaViolation:" + userTaskNode.getStringId(), null, processInstance.getStringId()); + processInstance.send(Sig.of("slaViolation:" + userTaskNode.getStringId(), null)); slaViolated = latch.await(10, TimeUnit.SECONDS); assertThat(slaViolated).as("SLA was not violated while it is expected").isTrue(); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - assertProcessInstanceFinished(processInstance, kruntime); - - int slaCompliance = getSLAComplianceForProcessInstance(processInstance); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_NA); - - slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 0); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_VIOLATED); + ProcessTestHelper.completeWorkItem(processInstance, Collections.emptyMap(), "john"); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); - slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 1); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_VIOLATED); + int slaCompliance = ((org.kie.kogito.process.impl.AbstractProcessInstance) processInstance) + .internalGetProcessInstance().getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_NA); + slaCompliance = ((org.jbpm.workflow.instance.NodeInstance) userTaskNode).getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_VIOLATED); } @Test @@ -333,85 +302,70 @@ public void afterSLAViolated(SLAViolatedEvent event) { public void testSLAonProcessViolatedNoTracking() throws Exception { CountDownLatch latch = new CountDownLatch(1); final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { - @Override public void afterSLAViolated(SLAViolatedEvent event) { latch.countDown(); } - }; - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/sla/BPMN2-UserTaskWithSLA.bpmn2"); - + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - kruntime.getProcessEventManager().addEventListener(listener); - kruntime.getKieRuntime().getEnvironment().set("SLATimerMode", "false"); - - KogitoProcessInstance processInstance = kruntime.startProcess("UserTaskWithSLA"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + ProcessTestHelper.registerProcessEventListener(app, listener); + org.kie.kogito.process.Process processDefinition = UserTaskWithSLAProcess.newProcess(app); + UserTaskWithSLAModel model = processDefinition.createModel(); + ProcessInstance processInstance = processDefinition.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); KogitoWorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); assertThat(workItem.getParameter("ActorId")).isEqualTo("john"); boolean slaViolated = latch.await(5, TimeUnit.SECONDS); - assertThat(slaViolated).as("SLA should not violated by timer").isFalse(); - - processInstance = kruntime.getProcessInstance(processInstance.getStringId()); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - - int slaCompliance = getSLAComplianceForProcessInstance(processInstance); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_PENDING); + assertThat(slaViolated).as("SLA should not be violated by timer").isTrue(); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - assertProcessInstanceFinished(processInstance, kruntime); + int slaCompliance = ((org.kie.kogito.process.impl.AbstractProcessInstance) processInstance) + .internalGetProcessInstance().getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_VIOLATED); - slaCompliance = getSLAComplianceForProcessInstance(processInstance); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_VIOLATED); + ProcessTestHelper.completeWorkItem(processInstance, Collections.emptyMap(), "john"); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + slaCompliance = ((org.kie.kogito.process.impl.AbstractProcessInstance) processInstance) + .internalGetProcessInstance().getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_VIOLATED); } @Test public void testSLAonCatchEventViolated() throws Exception { CountDownLatch latch = new CountDownLatch(1); final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { - @Override public void afterSLAViolated(SLAViolatedEvent event) { latch.countDown(); } - }; - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/sla/BPMN2-IntermediateCatchEventSignalWithSLAOnEvent.bpmn2"); - - kruntime.getProcessEventManager().addEventListener(listener); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler()); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEventSignalWithSLAOnEvent"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerProcessEventListener(app, listener); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); + org.kie.kogito.process.Process processDefinition = IntermediateCatchEventSignalWithSLAOnEventProcess.newProcess(app); + ProcessInstance processInstance = processDefinition.createInstance(processDefinition.createModel()); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); boolean slaViolated = latch.await(5, TimeUnit.SECONDS); assertThat(slaViolated).as("SLA should be violated by timer").isTrue(); - - processInstance = kruntime.getProcessInstance(processInstance.getStringId()); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - - Collection active = ((KogitoWorkflowProcessInstance) processInstance).getKogitoNodeInstances(); - assertThat(active).hasSize(1); - - KogitoNodeInstance eventNode = active.iterator().next(); - - kruntime.signalEvent("MyMessage", null, processInstance.getStringId()); - - assertProcessInstanceFinished(processInstance, kruntime); - - int slaCompliance = getSLAComplianceForProcessInstance(processInstance); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_NA); - - slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) eventNode, 0); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_VIOLATED); - - slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) eventNode, 1); - assertThat(slaCompliance).isEqualTo(KogitoProcessInstance.SLA_VIOLATED); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); + Collection activeNodes = ((org.kie.kogito.process.impl.AbstractProcessInstance) processInstance) + .internalGetProcessInstance().getNodeInstances(); + assertThat(activeNodes).hasSize(1); + KogitoNodeInstance eventNode = (KogitoNodeInstance) activeNodes.iterator().next(); + processInstance.send(Sig.of("MyMessage", null)); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + int slaCompliance = ((org.kie.kogito.process.impl.AbstractProcessInstance) processInstance) + .internalGetProcessInstance().getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_NA); + slaCompliance = ((org.jbpm.workflow.instance.NodeInstance) eventNode).getSlaCompliance(); + assertThat(slaCompliance).isEqualTo(org.kie.api.runtime.process.ProcessInstance.SLA_VIOLATED); }