-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Daniel Widdis <[email protected]>
- Loading branch information
Showing
5 changed files
with
140 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/org/opensearch/flowframework/template/WorkflowNodeTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.flowframework.template; | ||
|
||
import org.opensearch.core.xcontent.XContentParser; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public class WorkflowNodeTests extends OpenSearchTestCase { | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
} | ||
|
||
public void testNode() throws IOException { | ||
WorkflowNode nodeA = new WorkflowNode("A", "a-type", Map.of("foo", "bar")); | ||
assertEquals("A", nodeA.id()); | ||
assertEquals("a-type", nodeA.type()); | ||
assertEquals(Map.of("foo", "bar"), nodeA.inputs()); | ||
|
||
// node equality is based only on ID | ||
WorkflowNode nodeA2 = new WorkflowNode("A", "a2-type", Map.of("bar", "baz")); | ||
assertEquals(nodeA, nodeA2); | ||
|
||
WorkflowNode nodeB = new WorkflowNode("B", "b-type", Map.of("baz", "qux")); | ||
assertNotEquals(nodeA, nodeB); | ||
|
||
String expectedJson = "{\"id\":\"A\",\"type\":\"a-type\",\"inputs\":{\"foo\":\"bar\"}}"; | ||
String json = TemplateTestJsonUtil.parseToJson(nodeA); | ||
assertEquals(expectedJson, json); | ||
|
||
XContentParser parser = TemplateTestJsonUtil.jsonToParser(json); | ||
WorkflowNode nodeX = WorkflowNode.parse(parser); | ||
assertEquals("A", nodeX.id()); | ||
assertEquals("a-type", nodeX.type()); | ||
assertEquals(Map.of("foo", "bar"), nodeX.inputs()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/org/opensearch/flowframework/template/WorkflowTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.flowframework.template; | ||
|
||
import org.opensearch.core.xcontent.XContentParser; | ||
import org.opensearch.flowframework.workflow.Workflow; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class WorkflowTests extends OpenSearchTestCase { | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
} | ||
|
||
public void testWorkflow() throws IOException { | ||
WorkflowNode nodeA = new WorkflowNode("A", "a-type", Map.of("foo", "bar")); | ||
WorkflowNode nodeB = new WorkflowNode("B", "b-type", Map.of("baz", "qux")); | ||
WorkflowEdge edgeAB = new WorkflowEdge("A", "B"); | ||
List<WorkflowNode> nodes = List.of(nodeA, nodeB); | ||
List<WorkflowEdge> edges = List.of(edgeAB); | ||
|
||
Workflow workflow = new Workflow(Map.of("key", "value"), nodes, edges); | ||
assertEquals(Map.of("key", "value"), workflow.userParams()); | ||
assertEquals(List.of(nodeA, nodeB), workflow.nodes()); | ||
assertEquals(List.of(edgeAB), workflow.edges()); | ||
|
||
String expectedJson = "{\"user_params\":{\"key\":\"value\"}," | ||
+ "\"nodes\":[{\"id\":\"A\",\"type\":\"a-type\",\"inputs\":{\"foo\":\"bar\"}}," | ||
+ "{\"id\":\"B\",\"type\":\"b-type\",\"inputs\":{\"baz\":\"qux\"}}]," | ||
+ "\"edges\":[{\"source\":\"A\",\"dest\":\"B\"}]}"; | ||
String json = TemplateTestJsonUtil.parseToJson(workflow); | ||
assertEquals(expectedJson, json); | ||
|
||
XContentParser parser = TemplateTestJsonUtil.jsonToParser(json); | ||
Workflow workflowX = Workflow.parse(parser); | ||
assertEquals(Map.of("key", "value"), workflowX.userParams()); | ||
assertEquals(List.of(nodeA, nodeB), workflowX.nodes()); | ||
assertEquals(List.of(edgeAB), workflowX.edges()); | ||
} | ||
} |