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 Sep 20, 2024
1 parent 34389fe commit 251f40f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 48 deletions.
15 changes: 15 additions & 0 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ErrorEventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.jbpm.bpmn2.error.EndErrorProcess;
import org.jbpm.bpmn2.error.EndErrorWithEventSubprocessModel;
import org.jbpm.bpmn2.error.EndErrorWithEventSubprocessProcess;
import org.jbpm.bpmn2.error.ErrorBoundaryEventInterruptingModel;
import org.jbpm.bpmn2.error.ErrorBoundaryEventInterruptingProcess;
import org.jbpm.bpmn2.error.ErrorBoundaryEventOnServiceTaskModel;
import org.jbpm.bpmn2.error.ErrorBoundaryEventOnServiceTaskProcess;
import org.jbpm.bpmn2.error.ErrorVariableModel;
Expand Down Expand Up @@ -64,6 +66,7 @@
import org.jbpm.bpmn2.subprocess.ExceptionServiceProcessSignallingModel;
import org.jbpm.bpmn2.subprocess.ExceptionServiceProcessSignallingProcess;
import org.jbpm.process.instance.event.listeners.RuleAwareProcessEventListener;
import org.jbpm.process.workitem.builtin.DoNothingWorkItemHandler;
import org.jbpm.process.workitem.builtin.SignallingTaskHandlerDecorator;
import org.jbpm.process.workitem.builtin.SystemOutWorkItemHandler;
import org.jbpm.test.utils.EventTrackerProcessListener;
Expand All @@ -89,6 +92,7 @@
import org.kie.kogito.internal.process.workitem.KogitoWorkItemManager;
import org.kie.kogito.internal.process.workitem.WorkItemExecutionException;
import org.kie.kogito.internal.process.workitem.WorkItemTransition;
import org.kie.kogito.process.Process;
import org.kie.kogito.process.ProcessInstance;
import org.kie.kogito.process.workitems.impl.DefaultKogitoWorkItemHandler;

Expand Down Expand Up @@ -231,6 +235,17 @@ public void afterNodeLeft(ProcessNodeLeftEvent event) {

}

@Test
public void testErrorBoundaryEvent() {
Application application = ProcessTestHelper.newApplication();
ProcessTestHelper.registerHandler(application, "MyTask",
new DoNothingWorkItemHandler());
Process<ErrorBoundaryEventInterruptingModel> process = ErrorBoundaryEventInterruptingProcess.newProcess(application);
ProcessInstance<ErrorBoundaryEventInterruptingModel> instance = process.createInstance(process.createModel());
instance.start();
assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}

@Test
public void testErrorBoundaryEventOnTask() throws Exception {
kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/error/BPMN2-ErrorBoundaryEventOnTask.bpmn2");
Expand Down
79 changes: 31 additions & 48 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.xml.parsers.DocumentBuilderFactory;

Expand Down Expand Up @@ -82,6 +83,8 @@
import org.jbpm.bpmn2.flow.MultiConnEnabledProcess;
import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessModel;
import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessProcess;
import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessWithORgatewayModel;
import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessWithORgatewayProcess;
import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessWithOutputCmpCondModel;
import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessWithOutputCmpCondProcess;
import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessWithOutputModel;
Expand All @@ -104,10 +107,8 @@
import org.jbpm.test.utils.EventTrackerProcessListener;
import org.jbpm.test.utils.ProcessTestHelper;
import org.jbpm.workflow.instance.impl.NodeInstanceImpl;
import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl;
import org.jbpm.workflow.instance.node.CompositeContextNodeInstance;
import org.jbpm.workflow.instance.node.ForEachNodeInstance;
import org.jbpm.workflow.instance.node.ForEachNodeInstance.ForEachJoinNodeInstance;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
Expand All @@ -122,6 +123,7 @@
import org.kie.internal.command.RegistryContext;
import org.kie.kogito.Application;
import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener;
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.workitem.KogitoWorkItem;
Expand Down Expand Up @@ -896,69 +898,50 @@ public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
}

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

public void testMultiInstanceLoopCharacteristicsProcessWithORGateway() {
Application app = ProcessTestHelper.newApplication();
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task",
workItemHandler);
Map<String, Object> params = new HashMap<>();
ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler);
org.kie.kogito.process.Process<MultiInstanceLoopCharacteristicsProcessWithORgatewayModel> definition = MultiInstanceLoopCharacteristicsProcessWithORgatewayProcess.newProcess(app);
MultiInstanceLoopCharacteristicsProcessWithORgatewayModel model = definition.createModel();
List<Integer> myList = new ArrayList<>();
myList.add(12);
myList.add(15);
params.put("list", myList);
KogitoProcessInstance processInstance = kruntime.startProcess(
"MultiInstanceLoopCharacteristicsProcessWithORgateway", params);

model.setList(myList);
ProcessInstance<MultiInstanceLoopCharacteristicsProcessWithORgatewayModel> processInstance = definition.createInstance(model);
processInstance.start();
List<KogitoWorkItem> workItems = workItemHandler.getWorkItems();
assertThat(workItems).hasSize(4);

Collection<NodeInstance> nodeInstances = ((WorkflowProcessInstanceImpl) processInstance)
.getNodeInstances();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Collection<KogitoNodeInstance> nodeInstances = processInstance.findNodes(node -> node instanceof ForEachNodeInstance);
assertThat(nodeInstances).hasSize(1);
NodeInstance nodeInstance = nodeInstances.iterator().next();
KogitoNodeInstance nodeInstance = nodeInstances.iterator().next();
assertThat(nodeInstance).isInstanceOf(ForEachNodeInstance.class);

Collection<NodeInstance> nodeInstancesChild = ((ForEachNodeInstance) nodeInstance)
.getNodeInstances();
Collection<KogitoNodeInstance> nodeInstancesChild = ((ForEachNodeInstance) nodeInstance).getNodeInstances().stream()
.map(n -> (KogitoNodeInstance) n)
.collect(Collectors.toList());
assertThat(nodeInstancesChild).hasSize(2);

for (NodeInstance child : nodeInstancesChild) {
for (KogitoNodeInstance child : nodeInstancesChild) {
assertThat(child).isInstanceOf(CompositeContextNodeInstance.class);
assertThat(((CompositeContextNodeInstance) child)
.getNodeInstances()).hasSize(2);
assertThat(((CompositeContextNodeInstance) child).getNodeInstances()).hasSize(2);
}

kruntime.getKogitoWorkItemManager().completeWorkItem(
workItems.get(0).getStringId(), null);
kruntime.getKogitoWorkItemManager().completeWorkItem(
workItems.get(1).getStringId(), null);

processInstance = kruntime.getProcessInstance(processInstance.getStringId());
nodeInstances = ((WorkflowProcessInstanceImpl) processInstance)
.getNodeInstances();
processInstance.completeWorkItem(workItems.get(0).getStringId(), null);
processInstance.completeWorkItem(workItems.get(1).getStringId(), null);
nodeInstances = processInstance.findNodes(node -> node instanceof ForEachNodeInstance);
assertThat(nodeInstances).hasSize(1);
nodeInstance = nodeInstances.iterator().next();
assertThat(nodeInstance).isInstanceOf(ForEachNodeInstance.class);

nodeInstancesChild = ((ForEachNodeInstance) nodeInstance)
.getNodeInstances();
nodeInstancesChild = ((ForEachNodeInstance) nodeInstance).getNodeInstances().stream()
.map(n -> (KogitoNodeInstance) n)
.collect(Collectors.toList());
assertThat(nodeInstancesChild).hasSize(2);

Iterator<NodeInstance> childIterator = nodeInstancesChild
.iterator();

Iterator<KogitoNodeInstance> childIterator = nodeInstancesChild.iterator();
assertThat(childIterator.next()).isInstanceOf(CompositeContextNodeInstance.class);
assertThat(childIterator.next()).isInstanceOf(ForEachJoinNodeInstance.class);

kruntime.getKogitoWorkItemManager().completeWorkItem(
workItems.get(2).getStringId(), null);
kruntime.getKogitoWorkItemManager().completeWorkItem(
workItems.get(3).getStringId(), null);

assertProcessInstanceFinished(processInstance, kruntime);

assertThat(childIterator.next()).isInstanceOf(ForEachNodeInstance.ForEachJoinNodeInstance.class);
processInstance.completeWorkItem(workItems.get(2).getStringId(), null);
processInstance.completeWorkItem(workItems.get(3).getStringId(), null);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}

@Test
Expand Down

0 comments on commit 251f40f

Please sign in to comment.