From 8f01443b6b35e3f997f6b067f31da010cb60220e Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Thu, 2 Nov 2023 12:50:14 -0700 Subject: [PATCH] Fix tests Signed-off-by: Daniel Widdis --- .../FlowFrameworkPluginTests.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/opensearch/flowframework/FlowFrameworkPluginTests.java b/src/test/java/org/opensearch/flowframework/FlowFrameworkPluginTests.java index cbbc6d7fe..57afbf1e4 100644 --- a/src/test/java/org/opensearch/flowframework/FlowFrameworkPluginTests.java +++ b/src/test/java/org/opensearch/flowframework/FlowFrameworkPluginTests.java @@ -11,13 +11,21 @@ import org.opensearch.client.AdminClient; import org.opensearch.client.Client; import org.opensearch.client.ClusterAdminClient; +import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.settings.ClusterSettings; +import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; +import org.opensearch.env.Environment; +import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.TestThreadPool; import org.opensearch.threadpool.ThreadPool; import java.io.IOException; +import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -31,6 +39,9 @@ public class FlowFrameworkPluginTests extends OpenSearchTestCase { private ClusterAdminClient clusterAdminClient; private ThreadPool threadPool; private Settings settings; + Environment environment; + ClusterSettings clusterSettings; + ClusterService clusterService; @Override public void setUp() throws Exception { @@ -41,7 +52,18 @@ public void setUp() throws Exception { when(client.admin()).thenReturn(adminClient); when(adminClient.cluster()).thenReturn(clusterAdminClient); threadPool = new TestThreadPool(FlowFrameworkPluginTests.class.getName()); - settings = Settings.EMPTY; + + environment = mock(Environment.class); + settings = Settings.builder().build(); + when(environment.settings()).thenReturn(settings); + + final Set> settingsSet = Stream.concat( + ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), + Stream.of(FlowFrameworkFeatureEnabledSetting.FLOW_FRAMEWORK_ENABLED) + ).collect(Collectors.toSet()); + clusterSettings = new ClusterSettings(settings, settingsSet); + clusterService = mock(ClusterService.class); + when(clusterService.getClusterSettings()).thenReturn(clusterSettings); } @Override @@ -52,7 +74,10 @@ public void tearDown() throws Exception { public void testPlugin() throws IOException { try (FlowFrameworkPlugin ffp = new FlowFrameworkPlugin()) { - assertEquals(3, ffp.createComponents(client, null, threadPool, null, null, null, null, null, null, null, null).size()); + assertEquals( + 3, + ffp.createComponents(client, clusterService, threadPool, null, null, null, environment, null, null, null, null).size() + ); assertEquals(2, ffp.getRestHandlers(null, null, null, null, null, null, null).size()); assertEquals(2, ffp.getActions().size()); assertEquals(1, ffp.getExecutorBuilders(settings).size());