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 6, 2024
1 parent 218e3dd commit bfffc64
Showing 1 changed file with 96 additions and 79 deletions.
175 changes: 96 additions & 79 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.drools.compiler.rule.builder.PackageBuildContext;
import org.jbpm.bpmn2.activity.UserTaskWithParametrizedInputModel;
import org.jbpm.bpmn2.activity.UserTaskWithParametrizedInputProcess;
import org.jbpm.bpmn2.flow.UserTaskModel;
import org.jbpm.bpmn2.flow.UserTaskProcess;
import org.jbpm.bpmn2.handler.ReceiveTaskHandler;
import org.jbpm.bpmn2.handler.SendTaskHandler;
import org.jbpm.bpmn2.handler.ServiceTaskHandler;
Expand All @@ -34,8 +39,16 @@
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.CallActivitySubProcessModel;
import org.jbpm.bpmn2.subprocess.CallActivitySubProcessProcess;
import org.jbpm.bpmn2.subprocess.SubProcessWithEntryExitScriptsModel;
import org.jbpm.bpmn2.subprocess.SubProcessWithEntryExitScriptsProcess;
import org.jbpm.bpmn2.subprocess.SubProcessWithTypeVariableModel;
import org.jbpm.bpmn2.subprocess.SubProcessWithTypeVariableProcess;
import org.jbpm.bpmn2.test.RequirePersistence;
import org.jbpm.process.builder.ActionBuilder;
import org.jbpm.process.builder.AssignmentBuilder;
Expand All @@ -62,10 +75,10 @@
import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl;
import org.jbpm.workflow.instance.node.DynamicUtils;
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 @@ -79,10 +92,9 @@
import org.kie.api.event.rule.MatchCancelledEvent;
import org.kie.api.event.rule.MatchCreatedEvent;
import org.kie.api.runtime.process.DataTransformer;
import org.kie.api.runtime.process.NodeInstance;
import org.kie.kogito.Application;
import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener;
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 @@ -373,40 +385,38 @@ public void testUserTask() throws Exception {
}

@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 = ((WorkItemNodeInstance) nodeInstance.get()).getWorkItem().getDeploymentId();
String nodeInstanceId = ((WorkItemNodeInstance) nodeInstance.get()).getWorkItem().getNodeInstanceStringId();
WorkflowElementIdentifier nodeId = ((WorkItemNodeInstance) nodeInstance.get()).getWorkItem().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 @@ -469,13 +479,13 @@ public void testCallActivity() throws Exception {
}

@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 @@ -484,47 +494,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 @@ -1252,36 +1262,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 bfffc64

Please sign in to comment.