Skip to content

Commit

Permalink
[incubator-kie-issues-1131] v7 migration to code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhitocode committed Aug 21, 2024
1 parent f164c17 commit fdb4901
Showing 1 changed file with 20 additions and 50 deletions.
70 changes: 20 additions & 50 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FEELTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> params1 = new HashMap<String, Object>();
* 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<String, Object> params2 = new HashMap<String, Object>();
* 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<GatewayFEELModel> process = GatewayFEELProcess.newProcess(app);

GatewayFEELModel model = process.createModel();
model.setVA(Boolean.TRUE);
model.setVB(Boolean.FALSE);
ProcessInstance<GatewayFEELModel> 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<GatewayFEELModel> 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<GatewayFEELModel> 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<GatewayFEELModel> 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'");

}

}

0 comments on commit fdb4901

Please sign in to comment.