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 29, 2024
1 parent 1aec3ea commit 57a64d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.Collections;
import java.util.List;

import org.jbpm.bpmn2.escalation.EscalationBoundaryEventInterruptingModel;
import org.jbpm.bpmn2.escalation.EscalationBoundaryEventInterruptingProcess;
import org.jbpm.bpmn2.escalation.EscalationBoundaryEventModel;
import org.jbpm.bpmn2.escalation.EscalationBoundaryEventProcess;
import org.jbpm.bpmn2.escalation.EscalationBoundaryEventWithTaskModel;
Expand Down Expand Up @@ -181,12 +183,16 @@ public void testEscalationBoundaryEvent() {
}

@Test
public void testEscalationBoundaryEventInterrupting() throws Exception {
kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/escalation/BPMN2-EscalationBoundaryEventInterrupting.bpmn2");
TestWorkItemHandler handler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("MyTask", handler);
KogitoProcessInstance processInstance = kruntime.startProcess("EscalationBoundaryEventInterrupting");
assertProcessInstanceCompleted(processInstance);
public void testEscalationBoundaryEventInterrupting() {
Application app = ProcessTestHelper.newApplication();
ProcessTestHelper.registerHandler(app, "MyTask", new TestWorkItemHandler());
org.kie.kogito.process.Process<EscalationBoundaryEventInterruptingModel> processDefinition = EscalationBoundaryEventInterruptingProcess.newProcess(app);
EscalationBoundaryEventInterruptingModel model = processDefinition.createModel();
org.kie.kogito.process.ProcessInstance<EscalationBoundaryEventInterruptingModel> instance = processDefinition.createInstance(model);
instance.start();
instance.workItems().forEach(workItem -> instance.completeWorkItem(workItem.getId(), null));
assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);

}

@Test
Expand Down
81 changes: 18 additions & 63 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/FlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -75,6 +73,8 @@
import org.jbpm.bpmn2.flow.InclusiveSplitAndJoinWithTimerProcess;
import org.jbpm.bpmn2.flow.InclusiveSplitDefaultModel;
import org.jbpm.bpmn2.flow.InclusiveSplitDefaultProcess;
import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessWithORgatewayModel;
import org.jbpm.bpmn2.flow.MultiInstanceLoopCharacteristicsProcessWithORgatewayProcess;
import org.jbpm.bpmn2.flow.InclusiveSplitModel;
import org.jbpm.bpmn2.flow.InclusiveSplitProcess;
import org.jbpm.bpmn2.flow.MultiConnEnabledModel;
Expand Down Expand Up @@ -103,10 +103,6 @@
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 Down Expand Up @@ -892,69 +888,28 @@ 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(nodeInstances).hasSize(1);
NodeInstance nodeInstance = nodeInstances.iterator().next();
assertThat(nodeInstance).isInstanceOf(ForEachNodeInstance.class);

Collection<NodeInstance> nodeInstancesChild = ((ForEachNodeInstance) nodeInstance)
.getNodeInstances();
assertThat(nodeInstancesChild).hasSize(2);

for (NodeInstance child : nodeInstancesChild) {
assertThat(child).isInstanceOf(CompositeContextNodeInstance.class);
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();
assertThat(nodeInstances).hasSize(1);
nodeInstance = nodeInstances.iterator().next();
assertThat(nodeInstance).isInstanceOf(ForEachNodeInstance.class);

nodeInstancesChild = ((ForEachNodeInstance) nodeInstance)
.getNodeInstances();
assertThat(nodeInstancesChild).hasSize(2);

Iterator<NodeInstance> 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(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
processInstance.completeWorkItem(workItems.get(0).getStringId(), null);
processInstance.completeWorkItem(workItems.get(1).getStringId(), null);
processInstance = definition.instances().findById(processInstance.id()).orElseThrow();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
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 57a64d4

Please sign in to comment.