From 773b5c9560613a33c79b36e7a50c7b15228ea248 Mon Sep 17 00:00:00 2001 From: Joanne Wang <109310487+jowg-amazon@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:13:23 -0700 Subject: [PATCH] verify workflow through post api call (#563) Signed-off-by: jowg-amazon --- .../SecurityAnalyticsRestTestCase.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/opensearch/securityanalytics/SecurityAnalyticsRestTestCase.java b/src/test/java/org/opensearch/securityanalytics/SecurityAnalyticsRestTestCase.java index 522260a0a..4757a23b5 100644 --- a/src/test/java/org/opensearch/securityanalytics/SecurityAnalyticsRestTestCase.java +++ b/src/test/java/org/opensearch/securityanalytics/SecurityAnalyticsRestTestCase.java @@ -157,13 +157,14 @@ protected Map searchWorkflow(String workflowId) throws IOExcepti " }\n" + " }\n" + "}"; - List hits = executeSearch(ScheduledJob.SCHEDULED_JOBS_INDEX, workflowRequest); + List hits = executeWorkflowSearch("/_plugins/_alerting/monitors", workflowRequest); + if (hits.size() == 0) { return new HashMap<>(); } SearchHit hit = hits.get(0); - return (Map) hit.getSourceAsMap().get("workflow"); + return (Map) hit.getSourceAsMap(); } @@ -415,6 +416,16 @@ protected List executeSearch(String index, String request, Boolean re return Arrays.asList(searchResponse.getHits().getHits()); } + protected List executeWorkflowSearch(String url, String request) throws IOException { + + Response response = makeRequest(client(), "POST", String.format(Locale.getDefault(), "%s/_search", url), Collections.emptyMap(), new StringEntity(request), new BasicHeader("Content-Type", "application/json")); + Assert.assertEquals("Workflow search failed", RestStatus.OK, restStatus(response)); + + SearchResponse searchResponse = SearchResponse.fromXContent(createParser(JsonXContent.jsonXContent, response.getEntity().getContent())); + + return Arrays.asList(searchResponse.getHits().getHits()); + } + protected SearchResponse executeSearchAndGetResponse(String index, String request, Boolean refresh) throws IOException { if (refresh) { refreshIndex(index);