diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FEELTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FEELTest.java index e72b51a0229..3ac6abba783 100644 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FEELTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FEELTest.java @@ -25,88 +25,58 @@ import org.junit.jupiter.api.Test; import org.kie.kogito.Application; import org.kie.kogito.process.ProcessInstance; +import org.kie.kogito.process.ProcessInstanceExecutionException; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; public class FEELTest extends JbpmBpmn2TestCase { - - /* - * @Test - * public void testGatewayFEEL() throws Exception { - * kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/feel/BPMN2-GatewayFEEL.bpmn2"); - * - * Map params1 = new HashMap(); - * params1.put("VA", Boolean.TRUE); - * params1.put("VB", Boolean.FALSE); - * org.jbpm.workflow.instance.WorkflowProcessInstance procInstance1 = (org.jbpm.workflow.instance.WorkflowProcessInstance) kruntime.startProcess("GatewayFEEL", params1); - * assertThat(procInstance1.getVariable("Task1")).isEqualTo("ok"); - * assertThat(procInstance1.getVariable("Task2")).isEqualTo("ok"); - * assertThat(procInstance1.getVariable("Task3")).isNull(); - * assertNodeTriggered(procInstance1.getStringId(), "Task2", "VA and not(VB)"); - * - * Map params2 = new HashMap(); - * params2.put("VA", Boolean.FALSE); - * params2.put("VB", Boolean.TRUE); - * org.jbpm.workflow.instance.WorkflowProcessInstance procInstance2 = (org.jbpm.workflow.instance.WorkflowProcessInstance) kruntime.startProcess("GatewayFEEL", params2); - * assertThat(procInstance2.getVariable("Task1")).isEqualTo("ok"); - * assertThat(procInstance2.getVariable("Task2")).isNull(); - * assertThat(procInstance2.getVariable("Task3")).isEqualTo("ok"); - * assertNodeTriggered(procInstance2.getStringId(), "Task3", "VB or not(VA)"); - * } - */ @Test public void testGatewayFEEL() { Application app = ProcessTestHelper.newApplication(); EventTrackerProcessListener eventTrackerProcessListener = new EventTrackerProcessListener(); + ProcessTestHelper.registerProcessEventListener(app, eventTrackerProcessListener); org.kie.kogito.process.Process process = GatewayFEELProcess.newProcess(app); - GatewayFEELModel model = process.createModel(); model.setVA(Boolean.TRUE); model.setVB(Boolean.FALSE); ProcessInstance procInstance1 = process.createInstance(model); procInstance1.start(); - //The model does not have variables Task1, Task2, and Task3 - //So we are not able to assert the below assertions - - assertThat(procInstance1.variables().toMap().get("Task1")).isEqualTo("ok"); - assertThat(procInstance1.variables().toMap().get("Task2")).isEqualTo("ok") - assertThat(procInstance1.variables().toMap().get("Task3")).isNull(); + assertThat(procInstance1.variables().getTask1()).isEqualTo("ok"); + assertThat(procInstance1.variables().getTask2()).isEqualTo("ok"); + assertThat(procInstance1.variables().getTask3()).isNull(); assertThat(eventTrackerProcessListener.tracked()).anyMatch(ProcessTestHelper.triggered("Task2")) .anyMatch(ProcessTestHelper.triggered("VA and not(VB)")); - - model.setVA(Boolean.TRUE); - model.setVB(Boolean.FALSE); + + model.setVA(Boolean.FALSE); + model.setVB(Boolean.TRUE); ProcessInstance procInstance2 = process.createInstance(model); procInstance2.start(); - //The model does not have variables Task1, Task2, and Task3 - //So we are not able to assert the below assertions - - assertThat(procInstance2.variables().toMap().get("Task1")).isEqualTo("ok"); - assertThat(procInstance2.variables().toMap().get("Task2")).isNull(); - assertThat(procInstance2.variables().toMap().get("Task3")).isEqualTo("ok"); - - //Task3 is not triggered + assertThat(procInstance2.variables().getTask1()).isEqualTo("ok"); + assertThat(procInstance2.variables().getTask2()).isNull(); + assertThat(procInstance2.variables().getTask3()).isEqualTo("ok"); assertThat(eventTrackerProcessListener.tracked()).anyMatch(ProcessTestHelper.triggered("Task3")) .anyMatch(ProcessTestHelper.triggered("VB or not(VA)")); } - //Expected a Runtime assertion is thrown. But assertion fails as no exception is found @Test public void testGatewayFEELWrong() { Application app = ProcessTestHelper.newApplication(); org.kie.kogito.process.Process process = GatewayFEELProcess.newProcess(app); - assertThatExceptionOfType(RuntimeException.class) - .isThrownBy(() -> { - process.createInstance(process.createModel()).start(); - }) - .withMessageContaining("Invalid FEEL expression: 'VA and Not(VB)'") - .withMessageContaining("Invalid FEEL expression: 'VB or nOt(VA)'"); + ProcessInstance instance = process.createInstance(process.createModel()); + instance.start(); + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_ERROR); + assertThat(instance.error().isPresent()).isTrue(); + assertThatExceptionOfType(ProcessInstanceExecutionException.class) + .isThrownBy(instance::checkError).withMessageContaining("org.jbpm.process.instance.impl.FeelReturnValueEvaluatorException") + .withMessageContaining("ERROR Unknown variable 'VA'") + .withMessageContaining("ERROR Unknown variable name 'VB'"); + } }