Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[incubator-kie-issues-1131] Improve DataOutput tests within DataTest.Java adding assert statement #3614

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/DataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -388,6 +390,8 @@ public void executeWorkItem(KogitoWorkItem workItem,
@Test
public void testDataOutputAssociationsforHumanTask() {
Application app = ProcessTestHelper.newApplication();
List<org.w3c.dom.Document> documents = new ArrayList<>();
List<KogitoWorkItem> workItems = new ArrayList<>();
ProcessTestHelper.registerHandler(app, "Human Task", new KogitoWorkItemHandler() {
@Override
public void abortWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) {
Expand All @@ -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);
}
});
Expand All @@ -418,6 +424,16 @@ public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr)

org.kie.kogito.process.ProcessInstance<DataOutputAssociationsHumanTaskModel> 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
Expand Down Expand Up @@ -454,6 +470,8 @@ public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr)
@Test
public void testDataOutputAssociationsXmlNode() {
Application app = ProcessTestHelper.newApplication();
List<KogitoWorkItem> workItems = new ArrayList<>();
List<org.w3c.dom.Document> documents = new ArrayList<>();
ProcessTestHelper.registerHandler(app, "Human Task", new KogitoWorkItemHandler() {
@Override
public void abortWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr) {
Expand All @@ -468,6 +486,8 @@ public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr)
.parse(new ByteArrayInputStream("<user hello='hello world' />".getBytes()));
Map<String, Object> 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);
Expand All @@ -480,6 +500,14 @@ public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager mgr)

org.kie.kogito.process.ProcessInstance<DataOutputAssociationsXmlNodeModel> 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
Expand Down
Loading