Skip to content

Commit

Permalink
Adding validate/toXContent tests for workflow request/responses
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Palis <[email protected]>
  • Loading branch information
joshpalis committed Oct 5, 2023
1 parent a51c681 commit 524407e
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

import org.opensearch.Version;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.core.common.io.stream.BytesStreamInput;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.flowframework.model.Template;
import org.opensearch.flowframework.model.Workflow;
import org.opensearch.flowframework.model.WorkflowEdge;
Expand Down Expand Up @@ -55,6 +59,7 @@ public void testNullIdWorkflowRequest() throws IOException {
WorkflowRequest nullIdRequest = new WorkflowRequest(null, template);
assertNull(nullIdRequest.getWorkflowId());
assertEquals(template, nullIdRequest.getTemplate());
assertNull(nullIdRequest.validate());

BytesStreamOutput out = new BytesStreamOutput();
nullIdRequest.writeTo(out);
Expand All @@ -70,6 +75,7 @@ public void testNullTemplateWorkflowRequest() throws IOException {
WorkflowRequest nullTemplateRequest = new WorkflowRequest("123", null);
assertNotNull(nullTemplateRequest.getWorkflowId());
assertNull(nullTemplateRequest.getTemplate());
assertNull(nullTemplateRequest.validate());

BytesStreamOutput out = new BytesStreamOutput();
nullTemplateRequest.writeTo(out);
Expand All @@ -85,6 +91,7 @@ public void testWorkflowRequest() throws IOException {
WorkflowRequest workflowRequest = new WorkflowRequest("123", template);
assertNotNull(workflowRequest.getWorkflowId());
assertEquals(template, workflowRequest.getTemplate());
assertNull(workflowRequest.validate());

BytesStreamOutput out = new BytesStreamOutput();
workflowRequest.writeTo(out);
Expand All @@ -106,8 +113,12 @@ public void testWorkflowResponse() throws IOException {
BytesStreamInput in = new BytesStreamInput(BytesReference.toBytes(out.bytes()));

WorkflowResponse streamInputResponse = new WorkflowResponse(in);

assertEquals(response.getWorkflowId(), streamInputResponse.getWorkflowId());

XContentBuilder builder = MediaTypeRegistry.contentBuilder(XContentType.JSON);
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertNotNull(builder);
assertEquals("{\"workflow_id\":\"123\"}", builder.toString());
}

}

0 comments on commit 524407e

Please sign in to comment.