diff --git a/src/test/java/org/opensearch/flowframework/bwc/FlowFrameworkBackwardsCompatibilityIT.java b/src/test/java/org/opensearch/flowframework/bwc/FlowFrameworkBackwardsCompatibilityIT.java index d082a5c08..eea28555c 100644 --- a/src/test/java/org/opensearch/flowframework/bwc/FlowFrameworkBackwardsCompatibilityIT.java +++ b/src/test/java/org/opensearch/flowframework/bwc/FlowFrameworkBackwardsCompatibilityIT.java @@ -22,13 +22,14 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.stream.Collectors; +import static org.opensearch.flowframework.common.CommonValue.WORKFLOW_ID; + public class FlowFrameworkBackwardsCompatibilityIT extends OpenSearchRestTestCase { private static final ClusterType CLUSTER_TYPE = ClusterType.parse(System.getProperty("tests.rest.bwcsuite")); @@ -115,18 +116,35 @@ public void testBackwardsCompatibility() throws Exception { // mapping for 2.12 does not include time stamps assertNull(t.createdTime()); assertNull(t.lastUpdatedTime()); + assertNull(t.lastProvisionedTime()); break; case MIXED: assertTrue(pluginNames.contains("opensearch-flow-framework")); // Time stamps may or may not be null depending on whether index has been accessed by new version node // So just test that the template parses - assertEquals("test", t.name()); + assertNull(t.lastProvisionedTime()); break; case UPGRADED: assertTrue(pluginNames.contains("opensearch-flow-framework")); // mapping for 2.13+ includes time stamps - assertNotNull(t.createdTime()); - assertNotNull(t.lastUpdatedTime()); + Instant createdTime = t.createdTime(); + Instant lastUpdatedTime = t.lastUpdatedTime(); + assertNotNull(createdTime); + assertEquals(createdTime, lastUpdatedTime); + assertNull(t.lastProvisionedTime()); + + updateNoopTemplate(workflowId); + t = getTemplate(workflowId); + assertEquals(createdTime, t.createdTime()); + assertTrue(t.lastUpdatedTime().isAfter(lastUpdatedTime)); + lastUpdatedTime = t.lastUpdatedTime(); + assertNull(t.lastProvisionedTime()); + + provisionNoopTemplate(workflowId); + t = getTemplate(workflowId); + assertEquals(createdTime, t.createdTime()); + assertEquals(lastUpdatedTime, t.lastUpdatedTime()); + assertTrue(t.lastProvisionedTime().isAfter(lastUpdatedTime)); break; } break; @@ -164,10 +182,44 @@ private String createNoopTemplate() throws IOException, ParseException { ); assertEquals(RestStatus.CREATED.getStatus(), response.getStatusLine().getStatusCode()); - Pattern p = Pattern.compile("\"workflow_id\"\\s*:\\s*\"([^\"]+)\""); - Matcher m = p.matcher(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8)); - assertTrue(m.find()); - return m.group(1); + Map responseMap = entityAsMap(response); + String workflowId = (String) responseMap.get(WORKFLOW_ID); + assertNotNull(workflowId); + return workflowId; + } + + private String updateNoopTemplate(String workflowId) throws IOException, ParseException { + Response response = TestHelpers.makeRequest( + client(), + "PUT", + "_plugins/_flow_framework/workflow/" + workflowId, + null, + "{\"name\":\"test2\", \"workflows\":{\"provision\": {\"nodes\": [{\"id\":\"test-step\", \"type\":\"noop\"}]}}}", + List.of(new BasicHeader(HttpHeaders.USER_AGENT, "")) + ); + assertEquals(RestStatus.CREATED.getStatus(), response.getStatusLine().getStatusCode()); + + Map responseMap = entityAsMap(response); + String responseWorkflowId = (String) responseMap.get(WORKFLOW_ID); + assertEquals(workflowId, responseWorkflowId); + return responseWorkflowId; + } + + private String provisionNoopTemplate(String workflowId) throws IOException, ParseException { + Response response = TestHelpers.makeRequest( + client(), + "POST", + "_plugins/_flow_framework/workflow/" + workflowId + "/_provision", + null, + "", + List.of(new BasicHeader(HttpHeaders.USER_AGENT, "")) + ); + assertEquals(RestStatus.OK.getStatus(), response.getStatusLine().getStatusCode()); + + Map responseMap = entityAsMap(response); + String responseWorkflowId = (String) responseMap.get(WORKFLOW_ID); + assertEquals(workflowId, responseWorkflowId); + return responseWorkflowId; } private Template getTemplate(String workflowId) throws IOException, ParseException {