Skip to content

Commit

Permalink
Merge pull request #58 from rgdoliveira/sync_main
Browse files Browse the repository at this point in the history
Sync main branch with Apache main branch
  • Loading branch information
rgdoliveira authored Sep 9, 2024
2 parents 42e3f79 + db9adfa commit 75278d6
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Objects;

public final class SourceFile {
Expand All @@ -39,18 +40,30 @@ public SourceFile() {
* @param uri the URI of the source file
*/
public SourceFile(String uri) {
this.uri = Objects.requireNonNull(uri);
this.uri = toPosixPath(Path.of(Objects.requireNonNull(uri)));
}

// Needed for serialization
public void setUri(String uri) {
this.uri = uri;
this.uri = toPosixPath(Path.of(uri));
}

public String getUri() {
return uri;
}

public static String toPosixPath(Path path) {
if (path == null) {
return null;
}

if (path.getFileSystem().getSeparator().equals("/")) {
return path.toString();
}

return path.toString().replace(path.getFileSystem().getSeparator(), "/");
}

public byte[] readContents() throws IOException {
try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(getUri())) {
if (inputStream == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.kie.kogito.source.files;

import java.nio.file.Path;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class SourceFileTests {

@Test
void toPosixPath() {
assertThat(SourceFile.toPosixPath(null)).isNull();
assertThat(SourceFile.toPosixPath(Path.of("test/petstore.json"))).isEqualTo("test/petstore.json");
assertThat(SourceFile.toPosixPath(Path.of("foo/bar/test/petstore.json"))).isEqualTo("foo/bar/test/petstore.json");
assertThat(SourceFile.toPosixPath(Path.of("test\\petstore.json"))).isEqualTo("test/petstore.json");
assertThat(SourceFile.toPosixPath(Path.of("foo\\bar\\test\\petstore.json"))).isEqualTo("foo/bar/test/petstore.json");
assertThat(SourceFile.toPosixPath(Path.of("petstore.json"))).isEqualTo("petstore.json");
}
}
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

0 comments on commit 75278d6

Please sign in to comment.