Skip to content

Commit

Permalink
[incubator-kie-issues-1131] test migration from V7 to code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhitocode committed Jun 7, 2024
1 parent 218e3dd commit ec5afd7
Showing 1 changed file with 90 additions and 70 deletions.
160 changes: 90 additions & 70 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import org.drools.compiler.rule.builder.PackageBuildContext;
import org.jbpm.bpmn2.flow.ProcessCustomDescriptionMetaDataModel;
import org.jbpm.bpmn2.flow.ProcessCustomDescriptionMetaDataProcess;
import org.jbpm.bpmn2.flow.ProcessVariableCustomDescriptionMetaDataModel;
import org.jbpm.bpmn2.flow.ProcessVariableCustomDescriptionMetaDataProcess;
import org.jbpm.bpmn2.handler.ReceiveTaskHandler;
import org.jbpm.bpmn2.handler.SendTaskHandler;
import org.jbpm.bpmn2.handler.ServiceTaskHandler;
Expand All @@ -34,6 +41,14 @@
import org.jbpm.bpmn2.objects.HelloService;
import org.jbpm.bpmn2.objects.Person;
import org.jbpm.bpmn2.objects.TestWorkItemHandler;
import org.jbpm.bpmn2.subprocess.CallActivityProcessBoundaryErrorModel;
import org.jbpm.bpmn2.subprocess.CallActivityProcessBoundaryErrorProcess;
import org.jbpm.bpmn2.subprocess.CallActivitySubProcessBoundaryErrorModel;
import org.jbpm.bpmn2.subprocess.CallActivitySubProcessBoundaryErrorProcess;
import org.jbpm.bpmn2.subprocess.CallActivitySubProcessWithBoundaryEventModel;
import org.jbpm.bpmn2.subprocess.CallActivitySubProcessWithBoundaryEventProcess;
import org.jbpm.bpmn2.subprocess.CallActivityWithBoundaryEventModel;
import org.jbpm.bpmn2.subprocess.CallActivityWithBoundaryEventProcess;
import org.jbpm.bpmn2.subprocess.SubProcessWithEntryExitScriptsModel;
import org.jbpm.bpmn2.subprocess.SubProcessWithEntryExitScriptsProcess;
import org.jbpm.bpmn2.test.RequirePersistence;
Expand Down Expand Up @@ -948,31 +963,26 @@ public void testScriptTaskWithVariableByName() throws Exception {
}

@Test
public void testCallActivityWithBoundaryEvent() throws Exception {
ProcessCompletedCountDownProcessEventListener countDownListener = new ProcessCompletedCountDownProcessEventListener();
kruntime = createKogitoProcessRuntime(
"org/jbpm/bpmn2/subprocess/BPMN2-CallActivityWithBoundaryEvent.bpmn2",
"org/jbpm/bpmn2/subprocess/BPMN2-CallActivitySubProcessWithBoundaryEvent.bpmn2");
kruntime.getProcessEventManager().addEventListener(countDownListener);

public void testCallActivityWithBoundaryEvent() {
Application app = ProcessTestHelper.newApplication();
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task",
workItemHandler);
Map<String, Object> params = new HashMap<>();
params.put("x", "oldValue");
KogitoProcessInstance processInstance = kruntime.startProcess("CallActivityWithBoundaryEvent", params);

countDownListener.waitTillCompleted();

assertProcessInstanceFinished(processInstance, kruntime);
// assertEquals("new timer value",
// ((WorkflowProcessInstance) processInstance).getVariable("y"));
// first check the parent process executed nodes
assertNodeTriggered(processInstance.getStringId(), "StartProcess",
"CallActivity", "Boundary event", "Script Task", "end");
// then check child process executed nodes - is there better way to get child process id than simply increment?
assertNodeTriggered(processInstance.getStringId() + 1, "StartProcess2",
"User Task");
ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler);
ProcessCompletedCountDownProcessEventListener listener = new ProcessCompletedCountDownProcessEventListener();
ProcessTestHelper.registerProcessEventListener(app, listener);
org.kie.kogito.process.Process<CallActivitySubProcessWithBoundaryEventModel> callActivitySubProcessWithBoundaryEventProcess = CallActivitySubProcessWithBoundaryEventProcess.newProcess(app);
org.kie.kogito.process.Process<CallActivityWithBoundaryEventModel> process = CallActivityWithBoundaryEventProcess.newProcess(app);
CallActivityWithBoundaryEventModel model = process.createModel();
model.setX("oldValue");
ProcessInstance<CallActivityWithBoundaryEventModel> processInstance = process.createInstance(model);
processInstance.start();
listener.waitTillCompleted();
assertThat(processInstance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED);
Collection<String> processNodes = process.findNodes(Objects::nonNull).stream().map(Node::getName).collect(Collectors.toSet());
Collection<String> subProcessNodes = callActivitySubProcessWithBoundaryEventProcess.findNodes(Objects::nonNull).stream().map(Node::getName).collect(Collectors.toSet());
assertThat(processNodes.containsAll(List.of("StartProcess",
"CallActivity", "Boundary event", "Script Task", "end"))).isTrue();
assertThat(subProcessNodes.containsAll(List.of("StartProcess2",
"User Task"))).isTrue();
}

@Test
Expand Down Expand Up @@ -1037,45 +1047,56 @@ public void testUserTaskWithSimData() throws Exception {
}

@Test
public void testCallActivityWithBoundaryErrorEvent() throws Exception {
kruntime = createKogitoProcessRuntime(
"org/jbpm/bpmn2/subprocess/BPMN2-CallActivityProcessBoundaryError.bpmn2",
"org/jbpm/bpmn2/subprocess/BPMN2-CallActivitySubProcessBoundaryError.bpmn2");

kruntime.getKogitoWorkItemManager().registerWorkItemHandler("task1",
new SystemOutWorkItemHandler());
KogitoProcessInstance processInstance = kruntime.startProcess("CallActivityProcessBoundaryError");
public void testCallActivityWithBoundaryErrorEvent() {
Application app = ProcessTestHelper.newApplication();
SystemOutWorkItemHandler workItemHandler = new SystemOutWorkItemHandler();
ProcessTestHelper.registerHandler(app, "task1", workItemHandler);
ProcessCompletedCountDownProcessEventListener listener = new ProcessCompletedCountDownProcessEventListener();
ProcessTestHelper.registerProcessEventListener(app, listener);
org.kie.kogito.process.Process<CallActivitySubProcessBoundaryErrorModel> callActivitySubProcessBoundaryErrorProcess = CallActivitySubProcessBoundaryErrorProcess.newProcess(app);
org.kie.kogito.process.Process<CallActivityProcessBoundaryErrorModel> process = CallActivityProcessBoundaryErrorProcess.newProcess(app);
CallActivityProcessBoundaryErrorModel model = process.createModel();
ProcessInstance<CallActivityProcessBoundaryErrorModel> processInstance = process.createInstance(model);
processInstance.start();
assertThat(processInstance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED);

assertProcessInstanceFinished(processInstance, kruntime);
assertNodeTriggered(processInstance.getStringId(), "StartProcess",
"Call Activity 1", "Boundary event", "Task Parent", "End2");
// then check child process executed nodes - is there better way to get child process id than simply increment?
assertNodeTriggered(processInstance.getStringId() + 1, "StartProcess", "Task 1", "End");
Collection<String> processNodes = process.findNodes(Objects::nonNull).stream().map(Node::getName).collect(Collectors.toSet());
Collection<String> subProcessNodes = callActivitySubProcessBoundaryErrorProcess.findNodes(Objects::nonNull).stream()
.map(Node::getName).collect(Collectors.toSet());
assertThat(processNodes.containsAll(List.of("StartProcess",
"Call Activity 1", "Boundary event", "Task Parent", "End2"))).isTrue();
assertThat(subProcessNodes.containsAll(List.of("StartProcess", "Task 1", "End"))).isTrue();
}

@Test
public void testCallActivityWithBoundaryErrorEventWithWaitState() throws Exception {
kruntime = createKogitoProcessRuntime(
"org/jbpm/bpmn2/subprocess/BPMN2-CallActivityProcessBoundaryError.bpmn2",
"org/jbpm/bpmn2/subprocess/BPMN2-CallActivitySubProcessBoundaryError.bpmn2");

public void testCallActivityWithBoundaryErrorEventWithWaitState() {
Application app = ProcessTestHelper.newApplication();
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("task1", workItemHandler);
KogitoProcessInstance processInstance = kruntime.startProcess("CallActivityProcessBoundaryError");
ProcessTestHelper.registerHandler(app, "task1", workItemHandler);

org.kie.kogito.process.Process<CallActivitySubProcessBoundaryErrorModel> callActivitySubProcessBoundaryErrorProcess = CallActivitySubProcessBoundaryErrorProcess.newProcess(app);
ProcessInstance<CallActivitySubProcessBoundaryErrorModel> subProcessInstance = callActivitySubProcessBoundaryErrorProcess
.createInstance(callActivitySubProcessBoundaryErrorProcess.createModel());
org.kie.kogito.process.Process<CallActivityProcessBoundaryErrorModel> process = CallActivityProcessBoundaryErrorProcess.newProcess(app);
CallActivityProcessBoundaryErrorModel model = process.createModel();
ProcessInstance<CallActivityProcessBoundaryErrorModel> processInstance = process.createInstance(model);
processInstance.start();

org.kie.kogito.internal.process.runtime.KogitoWorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);

subProcessInstance.completeWorkItem(workItem.getStringId(), Collections.emptyMap());

workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);

assertProcessInstanceFinished(processInstance, kruntime);
assertNodeTriggered(processInstance.getStringId(), "StartProcess",
"Call Activity 1", "Boundary event", "Task Parent", "End2");
// then check child process executed nodes - is there better way to get child process id than simply increment?
assertNodeTriggered(processInstance.getStringId() + 1, "StartProcess", "Task 1", "End");
processInstance.completeWorkItem(workItem.getStringId(), Collections.emptyMap());
assertThat(processInstance).extracting(ProcessInstance::status).isEqualTo(ProcessInstance.STATE_COMPLETED);
Collection<String> processNodes = process.findNodes(Objects::nonNull).stream().map(Node::getName).collect(Collectors.toSet());
Collection<String> subProcessNodes = callActivitySubProcessBoundaryErrorProcess.findNodes(Objects::nonNull).stream()
.map(Node::getName).collect(Collectors.toSet());
assertThat(processNodes.containsAll(List.of("StartProcess",
"Call Activity 1", "Boundary event", "Task Parent", "End2"))).isTrue();
assertThat(subProcessNodes.containsAll(List.of("StartProcess", "Task 1", "End"))).isTrue();
}

@Test
Expand Down Expand Up @@ -1206,28 +1227,27 @@ public void testErrorBetweenProcessesProcess() throws Exception {
}

@Test
public void testProcessCustomDescriptionMetaData() throws Exception {
kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/flow/BPMN2-ProcessCustomDescriptionMetaData.bpmn2");

Map<String, Object> params = new HashMap<>();

KogitoProcessInstance processInstance = kruntime.startProcess("ProcessCustomDescriptionMetaData", params);
assertProcessInstanceCompleted(processInstance);

String description = processInstance.getDescription();
public void testProcessCustomDescriptionMetaData() {
Application app = ProcessTestHelper.newApplication();
org.kie.kogito.process.Process<ProcessCustomDescriptionMetaDataModel> process = ProcessCustomDescriptionMetaDataProcess.newProcess(app);
ProcessCustomDescriptionMetaDataModel model = process.createModel();
ProcessInstance<ProcessCustomDescriptionMetaDataModel> processInstance = process.createInstance(model);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
String description = processInstance.description();
assertThat(description).isNotNull().isEqualTo("my process with description");
}

@Test
public void testProcessVariableCustomDescriptionMetaData() throws Exception {
kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/flow/BPMN2-ProcessVariableCustomDescriptionMetaData.bpmn2");

Map<String, Object> params = new HashMap<>();
params.put("x", "variable name for process");
KogitoProcessInstance processInstance = kruntime.startProcess("ProcessVariableCustomDescriptionMetaData", params);
assertProcessInstanceCompleted(processInstance);

String description = processInstance.getDescription();
public void testProcessVariableCustomDescriptionMetaData() {
Application app = ProcessTestHelper.newApplication();
org.kie.kogito.process.Process<ProcessVariableCustomDescriptionMetaDataModel> process = ProcessVariableCustomDescriptionMetaDataProcess.newProcess(app);
ProcessVariableCustomDescriptionMetaDataModel model = process.createModel();
model.setX("variable name for process");
ProcessInstance<ProcessVariableCustomDescriptionMetaDataModel> processInstance = process.createInstance(model);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
String description = processInstance.description();
assertThat(description).isNotNull().isEqualTo("variable name for process");
}

Expand Down

0 comments on commit ec5afd7

Please sign in to comment.