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 d67d8f7 commit b5e3cc3
Showing 1 changed file with 93 additions and 78 deletions.
171 changes: 93 additions & 78 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -34,6 +35,8 @@
import org.jbpm.bpmn2.activity.ScriptTaskProcess;
import org.jbpm.bpmn2.activity.ScriptTaskWithIOModel;
import org.jbpm.bpmn2.activity.ScriptTaskWithIOProcess;
import org.jbpm.bpmn2.activity.UserTaskWithParametrizedInputModel;
import org.jbpm.bpmn2.activity.UserTaskWithParametrizedInputProcess;
import org.jbpm.bpmn2.activity.UserTaskWithSimulationMetaDataModel;
import org.jbpm.bpmn2.activity.UserTaskWithSimulationMetaDataProcess;
import org.jbpm.bpmn2.flow.CompositeWithDIGraphicalModel;
Expand All @@ -58,8 +61,13 @@
import org.jbpm.bpmn2.objects.HelloService;
import org.jbpm.bpmn2.objects.Person;
import org.jbpm.bpmn2.objects.TestWorkItemHandler;
import org.jbpm.bpmn2.subprocess.CallActivity2Model;
import org.jbpm.bpmn2.subprocess.CallActivity2Process;
import org.jbpm.bpmn2.subprocess.CallActivityMIModel;
import org.jbpm.bpmn2.subprocess.CallActivityMIProcess;
import org.jbpm.bpmn2.subprocess.CallActivityModel;
import org.jbpm.bpmn2.subprocess.CallActivityProcess;
import org.jbpm.bpmn2.subprocess.CallActivitySubProcessModel;
import org.jbpm.bpmn2.subprocess.CallActivitySubProcessProcess;
import org.jbpm.bpmn2.subprocess.InputMappingUsingValueModel;
import org.jbpm.bpmn2.subprocess.InputMappingUsingValueProcess;
Expand All @@ -71,6 +79,8 @@
import org.jbpm.bpmn2.subprocess.SubProcessWithTerminateEndEventProcess;
import org.jbpm.bpmn2.subprocess.SubProcessWithTerminateEndEventProcessScopeModel;
import org.jbpm.bpmn2.subprocess.SubProcessWithTerminateEndEventProcessScopeProcess;
import org.jbpm.bpmn2.subprocess.SubProcessWithTypeVariableModel;
import org.jbpm.bpmn2.subprocess.SubProcessWithTypeVariableProcess;
import org.jbpm.bpmn2.task.ReceiveTaskModel;
import org.jbpm.bpmn2.task.ReceiveTaskProcess;
import org.jbpm.bpmn2.task.SendTaskModel;
Expand Down Expand Up @@ -103,10 +113,10 @@
import org.jbpm.workflow.instance.node.EndNodeInstance;
import org.jbpm.workflow.instance.node.StartNodeInstance;
import org.jbpm.workflow.instance.node.WorkItemNodeInstance;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.kie.api.command.ExecutableCommand;
import org.kie.api.definition.process.Node;
import org.kie.api.definition.process.NodeContainer;
import org.kie.api.definition.process.Process;
Expand All @@ -126,7 +136,7 @@
import org.kie.kogito.auth.SecurityPolicy;
import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener;
import org.kie.kogito.internal.process.runtime.KogitoNode;
import org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer;
import org.kie.kogito.internal.process.runtime.KogitoNodeInstance;
import org.kie.kogito.internal.process.runtime.KogitoProcessInstance;
import org.kie.kogito.internal.process.runtime.KogitoProcessRuntime;
import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
Expand Down Expand Up @@ -434,40 +444,38 @@ public void testUserTask() {
}

@Test
public void testUserTaskVerifyParameters() throws Exception {
kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/activity/BPMN2-UserTask.bpmn2");

kruntime.getKieSession().getEnvironment().set("deploymentId", "test-deployment-id");
public void testUserTaskVerifyParameters() {
Application app = ProcessTestHelper.newApplication();
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
KogitoProcessInstance processInstance = kruntime.startProcess("UserTask");
assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE);
ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler);
org.kie.kogito.process.Process<UserTaskModel> process = UserTaskProcess.newProcess(app);
UserTaskModel model = process.createModel();
ProcessInstance<UserTaskModel> processInstance = process.createInstance(model);
processInstance.start();

assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
org.kie.kogito.internal.process.runtime.KogitoWorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
final String pId = processInstance.getStringId();

kruntime.getKieSession().execute((ExecutableCommand<Void>) context -> {

KogitoProcessInstance processInstance1 = kruntime.getProcessInstance(pId);
assertThat(processInstance1).isNotNull();
NodeInstance nodeInstance = ((KogitoNodeInstanceContainer) processInstance1)
.getNodeInstance(((InternalKogitoWorkItem) workItem).getNodeInstanceStringId());

assertThat(nodeInstance).isNotNull().isInstanceOf(WorkItemNodeInstance.class);
String deploymentId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getDeploymentId();
String nodeInstanceId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getNodeInstanceStringId();
WorkflowElementIdentifier nodeId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getNodeId();

assertThat(deploymentId).isEqualTo(((InternalKogitoWorkItem) workItem).getDeploymentId());
assertThat(nodeId).isEqualTo(((InternalKogitoWorkItem) workItem).getNodeId());
assertThat(nodeInstanceId).isEqualTo(((InternalKogitoWorkItem) workItem).getNodeInstanceStringId());

return null;
});

kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
assertProcessInstanceFinished(processInstance, kruntime);
final String pId = processInstance.id();
Optional<ProcessInstance<UserTaskModel>> processInstance1 = process.instances().stream()
.filter(instance -> instance.id().equals(pId)).findFirst();
assertThat(processInstance1).isNotNull();
Assertions.assertTrue(processInstance1.isPresent());
Optional<KogitoNodeInstance> nodeInstance = processInstance1.get().findNodes(node -> node.getStringId().equals(workItem.getNodeInstance().getStringId()))
.stream().findFirst();
assertThat(nodeInstance).isNotNull();
Assertions.assertTrue(nodeInstance.isPresent());
assertThat(nodeInstance.get()).isInstanceOf(WorkItemNodeInstance.class);
String deploymentId = ((InternalKogitoWorkItem) workItem).getDeploymentId();
String nodeInstanceId = ((InternalKogitoWorkItem) workItem).getNodeInstanceStringId();
WorkflowElementIdentifier nodeId = ((InternalKogitoWorkItem) workItem).getNodeId();

assertThat(deploymentId).isEqualTo(((InternalKogitoWorkItem) workItem).getDeploymentId());
assertThat(nodeId).isEqualTo(((InternalKogitoWorkItem) workItem).getNodeId());
assertThat(nodeInstanceId).isEqualTo(((InternalKogitoWorkItem) workItem).getNodeInstanceStringId());
processInstance.completeWorkItem(workItem.getStringId(), null);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}

@Test
Expand Down Expand Up @@ -533,13 +541,13 @@ public void testCallActivity() {
}

@Test
public void testCallActivityMI() throws Exception {
kruntime = createKogitoProcessRuntime(
"org/jbpm/bpmn2/subprocess/BPMN2-CallActivityMI.bpmn2",
"org/jbpm/bpmn2/subprocess/BPMN2-CallActivitySubProcess.bpmn2");

public void testCallActivityMI() {
Application app = ProcessTestHelper.newApplication();
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ProcessTestHelper.registerHandler(app, "Human Task",
workItemHandler);
final List<String> subprocessStarted = new ArrayList<>();
kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() {
DefaultKogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
Expand All @@ -548,47 +556,47 @@ public void beforeProcessStarted(ProcessStartedEvent event) {
}
}

});

};
ProcessTestHelper.registerProcessEventListener(app, listener);
CallActivitySubProcessProcess.newProcess(app);
org.kie.kogito.process.Process<CallActivityMIModel> process = CallActivityMIProcess.newProcess(app);
CallActivityMIModel model = process.createModel();
List<String> list = new ArrayList<>();
list.add("first");
list.add("second");
List<String> listOut = new ArrayList<>();
model.setX("oldValue");
model.setList(list);
model.setListOut(listOut);
ProcessInstance<CallActivityMIModel> processInstance = process.createInstance(model);
processInstance.start();

Map<String, Object> params = new HashMap<>();
params.put("x", "oldValue");
params.put("list", list);
params.put("listOut", listOut);

KogitoProcessInstance processInstance = kruntime.startProcess("CallActivityMI", params);
assertProcessInstanceCompleted(processInstance);
assertThat(processInstance.status()).isEqualTo(org.jbpm.process.instance.ProcessInstance.STATE_COMPLETED);
assertThat(subprocessStarted).hasSize(2);

listOut = (List) ((KogitoWorkflowProcessInstance) processInstance).getVariable("listOut");
listOut = processInstance.variables().getListOut();
assertThat(listOut).isNotNull().hasSize(2).containsExactly("new value", "new value");
}

@Test
public void testCallActivity2() throws Exception {
kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/subprocess/BPMN2-CallActivity2.bpmn2",
"org/jbpm/bpmn2/subprocess/BPMN2-CallActivitySubProcess.bpmn2");
public void testCallActivity2() {
Application app = ProcessTestHelper.newApplication();
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();

kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task",
ProcessTestHelper.registerHandler(app, "Human Task",
workItemHandler);
Map<String, Object> params = new HashMap<>();
params.put("x", "oldValue");
KogitoProcessInstance processInstance = kruntime.startProcess(
"CallActivity2", params);
assertProcessInstanceActive(processInstance);
assertThat(((KogitoWorkflowProcessInstance) processInstance).getVariable("y")).isEqualTo("new value");
org.kie.kogito.process.Process<CallActivitySubProcessModel> callActivitySubProcess = CallActivitySubProcessProcess.newProcess(app);
org.kie.kogito.process.Process<CallActivity2Model> process = CallActivity2Process.newProcess(app);
CallActivity2Model model = process.createModel();
model.setX("oldValue");
ProcessInstance<CallActivity2Model> processInstance = process.createInstance(model);
processInstance.start();

assertThat(processInstance.status()).isEqualTo(org.jbpm.process.instance.ProcessInstance.STATE_ACTIVE);
assertThat(processInstance.variables().getY()).isEqualTo("new value");
org.kie.kogito.internal.process.runtime.KogitoWorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
assertThat(workItem.getParameter("ActorId")).isEqualTo("krisv");
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);

assertProcessInstanceFinished(processInstance, kruntime);
processInstance.completeWorkItem(workItem.getStringId(), null);
assertThat(processInstance.status()).isEqualTo(org.jbpm.process.instance.ProcessInstance.STATE_COMPLETED);
}

@Test
Expand Down Expand Up @@ -1329,36 +1337,43 @@ public void testAdHocSubProcessEmptyCompleteExpression() throws Exception {
}

@Test
public void testSubProcessWithTypeVariable() throws Exception {
kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/subprocess/BPMN2-SubProcessWithTypeVariable.bpmn2");

public void testSubProcessWithTypeVariable() {
Application app = ProcessTestHelper.newApplication();
final List<String> list = new ArrayList<>();
kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() {
DefaultKogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
if (event.getNodeInstance().getNodeName().equals("Read Map")) {
list.add(event.getNodeInstance().getNodeName());
}
}
});
KogitoProcessInstance processInstance = kruntime.startProcess("SubProcessWithTypeVariable");
assertProcessInstanceCompleted(processInstance);
};
ProcessTestHelper.registerProcessEventListener(app, listener);
org.kie.kogito.process.Process<SubProcessWithTypeVariableModel> process = SubProcessWithTypeVariableProcess.newProcess(app);
SubProcessWithTypeVariableModel model = process.createModel();
ProcessInstance<SubProcessWithTypeVariableModel> processInstance = process.createInstance(model);
processInstance.start();

assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(list).hasSize(2);
}

@Test
public void testUserTaskParametrizedInput() throws Exception {
kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/activity/BPMN2-UserTaskWithParametrizedInput.bpmn2");
public void testUserTaskParametrizedInput() {
Application app = ProcessTestHelper.newApplication();
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler);
org.kie.kogito.process.Process<UserTaskWithParametrizedInputModel> process = UserTaskWithParametrizedInputProcess.newProcess(app);
UserTaskWithParametrizedInputModel model = process.createModel();
ProcessInstance<UserTaskWithParametrizedInputModel> processInstance = process.createInstance(model);
processInstance.start();

kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
KogitoProcessInstance processInstance = kruntime.startProcess("UserTaskWithParametrizedInput");
assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
org.kie.kogito.internal.process.runtime.KogitoWorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
assertThat(workItem.getParameter("Description").toString().trim()).isEqualTo("Executing task of process instance " + processInstance.getStringId() + " as work item with Hello");
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
assertProcessInstanceFinished(processInstance, kruntime);
assertThat(workItem.getParameter("Description").toString().trim()).isEqualTo("Executing task of process instance " + processInstance.id() + " as work item with Hello");
processInstance.completeWorkItem(workItem.getStringId(), null);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}

@Test
Expand Down

0 comments on commit b5e3cc3

Please sign in to comment.