From c0b56ea5f42b35611bd5d369f77630cc84c91202 Mon Sep 17 00:00:00 2001 From: Abhiram Gundala <164050036+Abhitocode@users.noreply.github.com> Date: Mon, 9 Sep 2024 08:50:02 -0400 Subject: [PATCH] [incubator-kie-issues-1131] v7 migration to code generation (#3614) --- .../test/java/org/jbpm/bpmn2/DataTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/DataTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/DataTest.java index 44a3b38a017..3183b0b06cb 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/DataTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/DataTest.java @@ -19,6 +19,7 @@ package org.jbpm.bpmn2; import java.io.ByteArrayInputStream; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -75,6 +76,7 @@ import org.kie.kogito.process.ProcessInstance; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.NodeList; import static org.assertj.core.api.Assertions.assertThat; @@ -388,6 +390,8 @@ public void executeWorkItem(KogitoWorkItem workItem, @Test public void testDataOutputAssociationsforHumanTask() { Application app = ProcessTestHelper.newApplication(); + List documents = new ArrayList<>(); + List workItems = new ArrayList<>(); ProcessTestHelper.registerHandler(app, "Human Task", new KogitoWorkItemHandler() { @Override public void abortWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) { @@ -408,7 +412,9 @@ public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) org.w3c.dom.Element processMetadata = processMetadaDoc.createElement("previoustasksowner"); processMetadaDoc.appendChild(processMetadata); processMetadata.setAttribute("primaryname", "my_result"); + documents.add(processMetadaDoc); results.put("output", processMetadata); + workItems.add(workItem); mgr.completeWorkItem(workItem.getStringId(), results); } }); @@ -418,6 +424,16 @@ public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); instance.start(); + assertThat(instance.status()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED); + assertThat(documents.size()).isEqualTo(1); + NodeList nodeList = documents.get(0).getElementsByTagName("previoustasksowner"); + assertThat(nodeList.getLength()).isEqualTo(1); + assertThat(nodeList.item(0).getAttributes().getNamedItem("primaryname")).isNotNull(); + assertThat(nodeList.item(0).getAttributes().getNamedItem("primaryname").getNodeValue()).isEqualTo("my_result"); + assertThat(workItems.size()).isGreaterThanOrEqualTo(1); + KogitoWorkItem workItem = workItems.get(0); + assertThat(workItem.getResults().get("output")).isInstanceOf(org.w3c.dom.Node.class); + assertThat((org.w3c.dom.Node) (workItem.getResults().get("output"))).isEqualTo(nodeList.item(0)); } @Test @@ -454,6 +470,8 @@ public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) @Test public void testDataOutputAssociationsXmlNode() { Application app = ProcessTestHelper.newApplication(); + List workItems = new ArrayList<>(); + List documents = new ArrayList<>(); ProcessTestHelper.registerHandler(app, "Human Task", new KogitoWorkItemHandler() { @Override public void abortWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) { @@ -468,6 +486,8 @@ public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) .parse(new ByteArrayInputStream("".getBytes())); Map params = new HashMap<>(); params.put("output", document.getFirstChild()); + workItems.add(workItem); + documents.add(document); mgr.completeWorkItem(workItem.getStringId(), params); } catch (Throwable e) { throw new RuntimeException(e); @@ -480,6 +500,14 @@ public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); instance.start(); + assertThat(instance.status()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED); + assertThat(workItems.size()).isGreaterThanOrEqualTo(1); + KogitoWorkItem workItem = workItems.get(0); + assertThat(workItem).isNotNull(); + assertThat(documents.size()).isGreaterThanOrEqualTo(1); + org.w3c.dom.Node node = documents.get(0).getFirstChild(); + assertThat(workItem.getResults().get("output")).isInstanceOf(org.w3c.dom.Node.class); + assertThat((org.w3c.dom.Node) (workItem.getResults().get("output"))).isEqualTo(node); } @Test