From ae8e99667ffca77954ab4a733f1943bfa13a6db8 Mon Sep 17 00:00:00 2001 From: Joanne Wang <109310487+jowg-amazon@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:35:13 -0800 Subject: [PATCH] fix TIF integ test (#774) Signed-off-by: Joanne Wang --- .../integTests/TIFJobExtensionPluginIT.java | 49 ++++++------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/src/test/java/org/opensearch/securityanalytics/threatIntel/integTests/TIFJobExtensionPluginIT.java b/src/test/java/org/opensearch/securityanalytics/threatIntel/integTests/TIFJobExtensionPluginIT.java index ff682e6dd..57b1fcbb1 100644 --- a/src/test/java/org/opensearch/securityanalytics/threatIntel/integTests/TIFJobExtensionPluginIT.java +++ b/src/test/java/org/opensearch/securityanalytics/threatIntel/integTests/TIFJobExtensionPluginIT.java @@ -8,42 +8,25 @@ */ package org.opensearch.securityanalytics.threatIntel.integTests; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.opensearch.action.admin.cluster.health.ClusterHealthRequest; -import org.opensearch.action.admin.cluster.health.ClusterHealthResponse; -import org.opensearch.action.admin.cluster.node.info.NodeInfo; -import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest; -import org.opensearch.action.admin.cluster.node.info.NodesInfoResponse; -import org.opensearch.action.admin.cluster.node.info.PluginsAndModules; -import org.opensearch.cluster.health.ClusterHealthStatus; -import org.opensearch.plugins.PluginInfo; -import org.opensearch.securityanalytics.threatIntel.jobscheduler.TIFJobRunner; -import org.opensearch.test.OpenSearchIntegTestCase; +import org.opensearch.client.Request; +import org.opensearch.client.Response; +import org.opensearch.common.xcontent.LoggingDeprecationHandler; +import org.opensearch.common.xcontent.json.JsonXContent; +import org.opensearch.core.xcontent.NamedXContentRegistry; +import org.opensearch.securityanalytics.SecurityAnalyticsRestTestCase; import org.junit.Assert; +import java.io.IOException; import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; +import java.util.Map; -public class TIFJobExtensionPluginIT extends OpenSearchIntegTestCase { - private static final Logger log = LogManager.getLogger(TIFJobExtensionPluginIT.class); - - public void testPluginsAreInstalled() { - ClusterHealthRequest request = new ClusterHealthRequest(); - ClusterHealthResponse response = OpenSearchIntegTestCase.client().admin().cluster().health(request).actionGet(); - Assert.assertEquals(ClusterHealthStatus.GREEN, response.getStatus()); - - NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(); - nodesInfoRequest.addMetric(NodesInfoRequest.Metric.PLUGINS.metricName()); - NodesInfoResponse nodesInfoResponse = OpenSearchIntegTestCase.client().admin().cluster().nodesInfo(nodesInfoRequest).actionGet(); - List pluginInfos = nodesInfoResponse.getNodes() - .stream() - .flatMap( - (Function>) nodeInfo -> nodeInfo.getInfo(PluginsAndModules.class).getPluginInfos().stream() - ) - .collect(Collectors.toList()); - Assert.assertTrue(pluginInfos.stream().anyMatch(pluginInfo -> pluginInfo.getName().equals("opensearch-job-scheduler"))); +public class TIFJobExtensionPluginIT extends SecurityAnalyticsRestTestCase { + public void testPluginsAreInstalled() throws IOException { + Request request = new Request("GET", "/_cat/plugins?s=component&h=name,component,version,description&format=json"); + Response response = client().performRequest(request); + List pluginsList = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, + LoggingDeprecationHandler.INSTANCE, response.getEntity().getContent()).list(); + Assert.assertTrue(pluginsList.stream().map(o -> (Map) o).anyMatch(plugin -> plugin.get("component") + .equals("opensearch-job-scheduler"))); } }