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 4cd44dc commit 74e328a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 76 deletions.
84 changes: 43 additions & 41 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.stream.Collectors;

import org.drools.compiler.rule.builder.PackageBuildContext;
import org.jbpm.bpmn2.activity.DataOutputAssignmentCustomExpressionLangModel;
import org.jbpm.bpmn2.activity.DataOutputAssignmentCustomExpressionLangProcess;
import org.jbpm.bpmn2.activity.ScriptTaskModel;
import org.jbpm.bpmn2.activity.ScriptTaskProcess;
import org.jbpm.bpmn2.activity.ScriptTaskWithIOModel;
Expand Down Expand Up @@ -89,6 +91,8 @@
import org.jbpm.bpmn2.subprocess.CallActivityWithBoundaryEventProcess;
import org.jbpm.bpmn2.subprocess.CallActivityWithIOexpressionModel;
import org.jbpm.bpmn2.subprocess.CallActivityWithIOexpressionProcess;
import org.jbpm.bpmn2.subprocess.ErrorsBetweenProcessModel;
import org.jbpm.bpmn2.subprocess.ErrorsBetweenProcessProcess;
import org.jbpm.bpmn2.subprocess.InputMappingUsingValueModel;
import org.jbpm.bpmn2.subprocess.InputMappingUsingValueProcess;
import org.jbpm.bpmn2.subprocess.MainGroupAssignmentModel;
Expand Down Expand Up @@ -125,6 +129,7 @@
import org.jbpm.test.util.ProcessCompletedCountDownProcessEventListener;
import org.jbpm.test.utils.EventTrackerProcessListener;
import org.jbpm.test.utils.ProcessTestHelper;
import org.jbpm.workflow.core.WorkflowProcess;
import org.jbpm.workflow.core.impl.DataAssociation;
import org.jbpm.workflow.core.impl.DataDefinition;
import org.jbpm.workflow.core.node.ActionNode;
Expand Down Expand Up @@ -168,6 +173,7 @@
import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance;
import org.kie.kogito.process.ProcessInstance;
import org.kie.kogito.process.impl.AbstractProcess;
import org.kie.kogito.process.workitems.InternalKogitoWorkItem;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -1456,20 +1462,22 @@ public void testServiceTaskWithMvelJaxbTransformation() throws Exception {

@Test
public void testErrorBetweenProcessesProcess() throws Exception {
kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/subprocess/BPMN2-ErrorsBetweenProcess.bpmn2",
"org/jbpm/bpmn2/subprocess/BPMN2-ErrorsBetweenSubProcess.bpmn2");

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

variables.put("tipoEvento", "error");
variables.put("pasoVariable", 3);
KogitoProcessInstance processInstance = kruntime.startProcess("ErrorsBetweenProcess", variables);

assertProcessInstanceCompleted(processInstance.getStringId(), kruntime);
assertProcessInstanceAborted(processInstance.getStringId() + 1, kruntime);

assertProcessVarValue(processInstance, "event", "error desde Subproceso");
Application app = ProcessTestHelper.newApplication();
org.kie.kogito.process.Process<ErrorsBetweenProcessModel> process = ErrorsBetweenProcessProcess.newProcess(app);
ErrorsBetweenProcessModel model = process.createModel();
model.setTipoEvento("error");
model.setPasoVariable(3);
ProcessInstance<ErrorsBetweenProcessModel> processInstance = process.createInstance(model);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(model.getEvent()).isEqualTo("error desde Subproceso");
}
/*errors:
java.lang.NullPointerException: Cannot invoke "org.kie.kogito.process.Process.createInstance(org.kie.kogito.Model)" because the return value of "org.kie.kogito.process.Processes.processById(String)" is null
org.opentest4j.AssertionFailedError:
expected: 2
but was: 5*/


@Test
public void testProcessCustomDescriptionMetaData() {
Expand Down Expand Up @@ -1903,90 +1911,84 @@ public void testBusinessRuleTaskWithExpressionsForIO() throws Exception {
assertThat(account.getPerson()).isNotNull();
}


@Test
@Disabled("this was not working")
public void testUserTaskWithAssignment() throws Exception {
Application app = ProcessTestHelper.newApplication();
ProcessDialectRegistry.setDialect("custom", new ProcessDialect() {

@Override
public ReturnValueEvaluatorBuilder getReturnValueEvaluatorBuilder() {
// TODO Auto-generated method stub
return null;
}

@Override
public ProcessClassBuilder getProcessClassBuilder() {
return null;
}

@Override
public AssignmentBuilder getAssignmentBuilder() {
return new AssignmentBuilder() {

@Override
public void build(PackageBuildContext context, Assignment assignment,
List<DataDefinition> sourceExpr, DataDefinition targetExpr) {
List<DataDefinition> sourceExpr, DataDefinition targetExpr) {
assertThat(assignment.getFrom().getExpression()).isEqualTo("from_expression");
assertThat(assignment.getTo().getExpression()).isEqualTo("to_expression");
}
};
}

@Override
public ActionBuilder getActionBuilder() {
return null;
}

@Override
public void addProcess(ProcessBuildContext context) {

}
});
kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/activity/BPMN2-DataOutputAssignmentCustomExpressionLang.bpmn2");
org.kie.kogito.process.Process<DataOutputAssignmentCustomExpressionLangModel> process =
DataOutputAssignmentCustomExpressionLangProcess.newProcess(app);

Process scriptProcess = kruntime.getKieBase().getProcess("DataOutputAssignmentCustomExpressionLang");
assertThat(scriptProcess).isNotNull();
Node[] nodes = ((NodeContainer) scriptProcess).getNodes();
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler);
assertThat(process).isNotNull();
WorkflowProcess workflowProcess = ((AbstractProcess<?>) process).process();
Node[] nodes = workflowProcess.getNodes();
assertThat(nodes).hasSize(3);
assertThat(nodes).filteredOn(n -> n instanceof WorkItemNode).allMatch(this::matchExpectedAssociationSetup);
DataOutputAssignmentCustomExpressionLangModel model = process.createModel();
model.setName("John");
ProcessInstance<DataOutputAssignmentCustomExpressionLangModel> processInstance = process.createInstance(model);
processInstance.start();

TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);

Map<String, Object> params = new HashMap<>();
params.put("name", "John");
KogitoProcessInstance processInstance = kruntime.startProcess("DataOutputAssignmentCustomExpressionLang", params);

kruntime.abortProcessInstance(processInstance.getStringId());
KogitoWorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
processInstance.completeWorkItem(workItem.getStringId(), null);

assertProcessInstanceAborted(processInstance);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}

protected boolean matchExpectedAssociationSetup(Node node) {
List<DataAssociation> inputs = ((WorkItemNode) node).getInAssociations();
List<DataAssociation> outputs = ((WorkItemNode) node).getOutAssociations();

assertThat(inputs).hasSize(1);
assertThat(outputs).hasSize(1);

DataAssociation association = inputs.get(0);
assertThat(association.getAssignments()).hasSize(1);
assertThat(association.getSources()).hasSize(2);

Assignment assignment = association.getAssignments().get(0);
assertThat(assignment.getDialect()).isEqualTo("custom");
assertThat(assignment.getFrom().getExpression()).isEqualTo("from_expression");
assertThat(assignment.getTo().getExpression()).isEqualTo("to_expression");

association = outputs.get(0);
assertThat(association.getAssignments()).hasSize(1);
assertThat(association.getSources()).hasSize(2);

assignment = association.getAssignments().get(0);
assertThat(assignment.getDialect()).isEqualTo("custom");
assertThat(assignment.getFrom().getExpression()).isEqualTo("from_expression");
assertThat(assignment.getTo().getExpression()).isEqualTo("to_expression");

return true;
}
/*error: WorkflowProcess workflowProcess = ((AbstractProcess<?>) process).process();
process()' has protected access in 'org.kie.kogito.process.impl.AbstractProcess'*/


}
40 changes: 28 additions & 12 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/CompensationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.jbpm.bpmn2.compensation.BookingModel;
import org.jbpm.bpmn2.compensation.BookingProcess;
import org.jbpm.bpmn2.compensation.CancelResourceProcess;
import org.jbpm.bpmn2.compensation.InSubSubProcessModel;
import org.jbpm.bpmn2.compensation.InSubSubProcessProcess;
import org.jbpm.bpmn2.compensation.IntermediateThrowEventModel;
import org.jbpm.bpmn2.compensation.IntermediateThrowEventProcess;
import org.jbpm.bpmn2.compensation.ParallelOrderedCompensationIntermediateThrowEventModel;
Expand Down Expand Up @@ -195,22 +197,36 @@ public void orderedCompensation() {

@Test
public void compensationInSubSubProcesses() throws Exception {
kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/compensation/BPMN2-InSubSubProcess.bpmn2");
Application app = ProcessTestHelper.newApplication();

TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<>();
params.put("x", "0");
KogitoProcessInstance processInstance = kruntime.startProcess("InSubSubProcess", params);
ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler);

kruntime.signalEvent("Compensation", "_C-2", processInstance.getStringId());
org.kie.kogito.process.Process<InSubSubProcessModel> definition = InSubSubProcessProcess.newProcess(app);
InSubSubProcessModel model = definition.createModel();
model.setX("0");

kruntime.getKogitoWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getStringId(), null);
kruntime.getKogitoWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getStringId(), null);
kruntime.getKogitoWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getStringId(), null);
ProcessInstance<InSubSubProcessModel> processInstance = definition.createInstance(model);
processInstance.start();

processInstance.send(Sig.of("Compensation", "_C-2"));

processInstance.completeWorkItem(workItemHandler.getWorkItem().getStringId(), null);
processInstance.completeWorkItem(workItemHandler.getWorkItem().getStringId(), null);
processInstance.completeWorkItem(workItemHandler.getWorkItem().getStringId(), null);

assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(processInstance.variables().getX()).isEqualTo("2");

/*the nodes have no connection in the bpmn file,
java.lang.IllegalStateException: Process could not be validated ![Process 'Default Process' [InSubSubProcess]: Node 'Boundary Compensate 3' [_X-1] Event has no outgoing connection
Process 'Default Process' [InSubSubProcess]: Node 'Compensate Handler 3' [_X-2] Action has no incoming connection.,
Process 'Default Process' [InSubSubProcess]: Node 'Boundary Compensate 2' [_Y-1] Event has no outgoing connection,
Process 'Default Process' [InSubSubProcess]: Node 'Compensate Handler 2' [_Y-2] Action has no incoming connection.,
Process 'Default Process' [InSubSubProcess]: Node 'Compensate Handler 3' [_X-2] Has no connection to the start node.,
Process 'Default Process' [InSubSubProcess]: Node 'Compensate Handler 2' [_Y-2] Has no connection to the start node.]*/
*/

// compensation activity (assoc. with script task) signaled *after* script task
assertProcessInstanceCompleted(processInstance.getStringId(), kruntime);
assertProcessVarValue(processInstance, "x", "2");
}

@Test
Expand Down
67 changes: 44 additions & 23 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/DataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
import org.jbpm.bpmn2.core.Association;
import org.jbpm.bpmn2.core.DataStore;
import org.jbpm.bpmn2.core.Definitions;
import org.jbpm.bpmn2.data.AssociationModel;
import org.jbpm.bpmn2.data.AssociationProcess;
import org.jbpm.bpmn2.data.CorrelationKeyModel;
import org.jbpm.bpmn2.data.CorrelationKeyProcess;
import org.jbpm.bpmn2.data.DataInputAssociationsLazyCreatingModel;
import org.jbpm.bpmn2.data.DataInputAssociationsLazyCreatingProcess;
import org.jbpm.bpmn2.data.DataInputAssociationsModel;
Expand All @@ -50,6 +54,8 @@
import org.jbpm.bpmn2.data.DataOutputAssociationsProcess;
import org.jbpm.bpmn2.data.DataOutputAssociationsXmlNodeModel;
import org.jbpm.bpmn2.data.DataOutputAssociationsXmlNodeProcess;
import org.jbpm.bpmn2.data.DataStoreModel;
import org.jbpm.bpmn2.data.DataStoreProcess;
import org.jbpm.bpmn2.data.Evaluation2Model;
import org.jbpm.bpmn2.data.Evaluation2Process;
import org.jbpm.bpmn2.data.Evaluation3Model;
Expand All @@ -60,7 +66,6 @@
import org.jbpm.bpmn2.data.ImportProcess;
import org.jbpm.bpmn2.flow.DataOutputAssociationsHumanTaskModel;
import org.jbpm.bpmn2.flow.DataOutputAssociationsHumanTaskProcess;
import org.jbpm.bpmn2.xml.ProcessHandler;
import org.jbpm.process.core.datatype.impl.type.ObjectDataType;
import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler;
import org.jbpm.test.utils.ProcessTestHelper;
Expand All @@ -71,7 +76,6 @@
import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemManager;
import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance;
import org.kie.kogito.process.ProcessInstance;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -106,31 +110,46 @@ public void testDataObject() {

@Test
public void testDataStore() throws Exception {
kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/data/BPMN2-DataStore.bpmn2");
KogitoProcessInstance processInstance = kruntime.startProcess("DataStore");
Definitions def = (Definitions) processInstance.getProcess()
.getMetaData().get("Definitions");
assertThat(def.getDataStores()).isNotNull().hasSize(1);
Application app = ProcessTestHelper.newApplication();

org.kie.kogito.process.Process<DataStoreModel> processDefinition = DataStoreProcess.newProcess(app);
DataStoreModel model = processDefinition.createModel();
org.kie.kogito.process.ProcessInstance<DataStoreModel> instance = processDefinition.createInstance(model);
instance.start();

/*
* metaData is not present, I think it is protected and hence cannot import.
* How to get process metadata from the process object(only then we can get the definition metadata)
*/

Definitions def = (Definitions) instance.process().metaData().get("Definitions");
assertThat(def.getDataStores()).isNotNull().hasSize(1);
DataStore dataStore = def.getDataStores().get(0);
assertThat(dataStore.getId()).isEqualTo("employee");
assertThat(dataStore.getName()).isEqualTo("employeeStore");
assertThat(((ObjectDataType) dataStore.getType()).getClassName()).isEqualTo(String.class.getCanonicalName());

}

@Test
public void testAssociation() throws Exception {
kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/data/BPMN2-Association.bpmn2");
KogitoProcessInstance processInstance = kruntime.startProcess("Association");
List<Association> associations = (List<Association>) processInstance.getProcess().getMetaData().get(ProcessHandler.ASSOCIATIONS);
assertThat(associations).isNotNull().hasSize(1);
Application app = ProcessTestHelper.newApplication();
org.kie.kogito.process.Process<AssociationModel> processDefinition = AssociationProcess.newProcess(app);
AssociationModel model = processDefinition.createModel();
org.kie.kogito.process.ProcessInstance<AssociationModel> instance = processDefinition.createInstance(model);
instance.start();

/*
* metaData is not present, I think it is protected and hence cannot import.
* How to get process metadata from the process object(only then we can get the definition metadata)
*/

Definitions def = (Definitions) instance.process().metaData().get("Definitions");
List<Association> associations = def.getAssociations();
assertThat(associations).isNotNull().hasSize(1);
Association assoc = associations.get(0);
assertThat(assoc.getId()).isEqualTo("_1234");
assertThat(assoc.getSourceRef()).isEqualTo("_1");
assertThat(assoc.getTargetRef()).isEqualTo("_2");

}

@Test
Expand Down Expand Up @@ -482,17 +501,19 @@ public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr)
instance.start();
}

@Test
public void testDefaultProcessVariableValue() throws Exception {

kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/data/BPMN2-CorrelationKey.bpmn2");

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

KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime.startProcess("CorrelationKey", parameters);
public void testDefaultProcessVariableValue() {
Application app = ProcessTestHelper.newApplication();
org.kie.kogito.process.Process<CorrelationKeyModel> processDefinition = CorrelationKeyProcess.newProcess(app);
CorrelationKeyModel model = processDefinition.createModel();
org.kie.kogito.process.ProcessInstance<CorrelationKeyModel> instance = processDefinition.createInstance(model);
instance.start();

assertThat(processInstance.getVariable("procVar")).isEqualTo("defaultProc");
assertThat(processInstance.getVariable("intVar")).isEqualTo(1);
/*
* CorrelationKeyModel class does not have methods named getProcVar and getIntVar .
* This is due to acutal variables/methods being different in the CorrelationKeyModel class.
*/
assertThat(model.getProcVar()).isEqualTo("defaultProc");
assertThat(model.getIntVar()).isEqualTo(1);

}

Expand Down

0 comments on commit 74e328a

Please sign in to comment.