|
18 | 18 | */
|
19 | 19 | package org.jbpm.bpmn2;
|
20 | 20 |
|
21 |
| -import java.util.HashMap; |
22 |
| -import java.util.Map; |
23 |
| - |
| 21 | +import org.jbpm.bpmn2.feel.GatewayFEELModel; |
| 22 | +import org.jbpm.bpmn2.feel.GatewayFEELProcess; |
| 23 | +import org.jbpm.test.utils.EventTrackerProcessListener; |
| 24 | +import org.jbpm.test.utils.ProcessTestHelper; |
24 | 25 | import org.junit.jupiter.api.Test;
|
| 26 | +import org.kie.kogito.Application; |
| 27 | +import org.kie.kogito.process.ProcessInstance; |
| 28 | +import org.kie.kogito.process.ProcessInstanceExecutionException; |
25 | 29 |
|
26 | 30 | import static org.assertj.core.api.Assertions.assertThat;
|
27 | 31 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
28 | 32 |
|
29 | 33 | public class FEELTest extends JbpmBpmn2TestCase {
|
30 |
| - |
31 | 34 | @Test
|
32 |
| - public void testGatewayFEEL() throws Exception { |
33 |
| - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/feel/BPMN2-GatewayFEEL.bpmn2"); |
34 |
| - |
35 |
| - Map<String, Object> params1 = new HashMap<String, Object>(); |
36 |
| - params1.put("VA", Boolean.TRUE); |
37 |
| - params1.put("VB", Boolean.FALSE); |
38 |
| - org.jbpm.workflow.instance.WorkflowProcessInstance procInstance1 = (org.jbpm.workflow.instance.WorkflowProcessInstance) kruntime.startProcess("GatewayFEEL", params1); |
39 |
| - assertThat(procInstance1.getVariable("Task1")).isEqualTo("ok"); |
40 |
| - assertThat(procInstance1.getVariable("Task2")).isEqualTo("ok"); |
41 |
| - assertThat(procInstance1.getVariable("Task3")).isNull(); |
42 |
| - assertNodeTriggered(procInstance1.getStringId(), "Task2", "VA and not(VB)"); |
43 |
| - |
44 |
| - Map<String, Object> params2 = new HashMap<String, Object>(); |
45 |
| - params2.put("VA", Boolean.FALSE); |
46 |
| - params2.put("VB", Boolean.TRUE); |
47 |
| - org.jbpm.workflow.instance.WorkflowProcessInstance procInstance2 = (org.jbpm.workflow.instance.WorkflowProcessInstance) kruntime.startProcess("GatewayFEEL", params2); |
48 |
| - assertThat(procInstance2.getVariable("Task1")).isEqualTo("ok"); |
49 |
| - assertThat(procInstance2.getVariable("Task2")).isNull(); |
50 |
| - assertThat(procInstance2.getVariable("Task3")).isEqualTo("ok"); |
51 |
| - assertNodeTriggered(procInstance2.getStringId(), "Task3", "VB or not(VA)"); |
| 35 | + public void testGatewayFEEL() { |
| 36 | + Application app = ProcessTestHelper.newApplication(); |
| 37 | + EventTrackerProcessListener eventTrackerProcessListener = new EventTrackerProcessListener(); |
| 38 | + |
| 39 | + ProcessTestHelper.registerProcessEventListener(app, eventTrackerProcessListener); |
| 40 | + org.kie.kogito.process.Process<GatewayFEELModel> process = GatewayFEELProcess.newProcess(app); |
| 41 | + GatewayFEELModel model = process.createModel(); |
| 42 | + model.setVA(Boolean.TRUE); |
| 43 | + model.setVB(Boolean.FALSE); |
| 44 | + ProcessInstance<GatewayFEELModel> procInstance1 = process.createInstance(model); |
| 45 | + procInstance1.start(); |
| 46 | + |
| 47 | + assertThat(procInstance1.variables().getTask1()).isEqualTo("ok"); |
| 48 | + assertThat(procInstance1.variables().getTask2()).isEqualTo("ok"); |
| 49 | + assertThat(procInstance1.variables().getTask3()).isNull(); |
| 50 | + |
| 51 | + assertThat(eventTrackerProcessListener.tracked()).anyMatch(ProcessTestHelper.triggered("Task2")) |
| 52 | + .anyMatch(ProcessTestHelper.triggered("VA and not(VB)")); |
| 53 | + |
| 54 | + model.setVA(Boolean.FALSE); |
| 55 | + model.setVB(Boolean.TRUE); |
| 56 | + |
| 57 | + ProcessInstance<GatewayFEELModel> procInstance2 = process.createInstance(model); |
| 58 | + procInstance2.start(); |
| 59 | + |
| 60 | + assertThat(procInstance2.variables().getTask1()).isEqualTo("ok"); |
| 61 | + assertThat(procInstance2.variables().getTask2()).isNull(); |
| 62 | + assertThat(procInstance2.variables().getTask3()).isEqualTo("ok"); |
| 63 | + assertThat(eventTrackerProcessListener.tracked()).anyMatch(ProcessTestHelper.triggered("Task3")) |
| 64 | + .anyMatch(ProcessTestHelper.triggered("VB or not(VA)")); |
52 | 65 | }
|
53 | 66 |
|
54 | 67 | @Test
|
55 | 68 | public void testGatewayFEELWrong() {
|
56 |
| - assertThatExceptionOfType(RuntimeException.class) |
57 |
| - .isThrownBy(() -> createKogitoProcessRuntime("BPMN2-GatewayFEEL-wrong.bpmn2")) |
58 |
| - .withMessageContaining("Invalid FEEL expression: 'VA and Not(VB)'") |
59 |
| - .withMessageContaining("Invalid FEEL expression: 'VB or nOt(VA)'"); |
| 69 | + Application app = ProcessTestHelper.newApplication(); |
| 70 | + org.kie.kogito.process.Process<GatewayFEELModel> process = GatewayFEELProcess.newProcess(app); |
| 71 | + ProcessInstance<GatewayFEELModel> instance = process.createInstance(process.createModel()); |
| 72 | + instance.start(); |
| 73 | + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_ERROR); |
| 74 | + assertThat(instance.error().isPresent()).isTrue(); |
| 75 | + assertThatExceptionOfType(ProcessInstanceExecutionException.class) |
| 76 | + .isThrownBy(instance::checkError).withMessageContaining("org.jbpm.process.instance.impl.FeelReturnValueEvaluatorException") |
| 77 | + .withMessageContaining("ERROR Unknown variable 'VA'") |
| 78 | + .withMessageContaining("ERROR Unknown variable name 'VB'"); |
| 79 | + |
60 | 80 | }
|
61 | 81 |
|
62 | 82 | }
|
0 commit comments