From 809f3bac1ad273d34cae521ee2e5caa62f019270 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Thu, 2 Nov 2023 13:10:35 -0700 Subject: [PATCH] Add test coverage Signed-off-by: Daniel Widdis --- .../FlowFrameworkPluginTests.java | 7 ++- ...owFrameworkFeatureEnabledSettingTests.java | 58 +++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/test/java/org/opensearch/flowframework/common/FlowFrameworkFeatureEnabledSettingTests.java diff --git a/src/test/java/org/opensearch/flowframework/FlowFrameworkPluginTests.java b/src/test/java/org/opensearch/flowframework/FlowFrameworkPluginTests.java index 57afbf1e4..85029cba9 100644 --- a/src/test/java/org/opensearch/flowframework/FlowFrameworkPluginTests.java +++ b/src/test/java/org/opensearch/flowframework/FlowFrameworkPluginTests.java @@ -39,9 +39,9 @@ public class FlowFrameworkPluginTests extends OpenSearchTestCase { private ClusterAdminClient clusterAdminClient; private ThreadPool threadPool; private Settings settings; - Environment environment; - ClusterSettings clusterSettings; - ClusterService clusterService; + private Environment environment; + private ClusterSettings clusterSettings; + private ClusterService clusterService; @Override public void setUp() throws Exception { @@ -81,6 +81,7 @@ public void testPlugin() throws IOException { assertEquals(2, ffp.getRestHandlers(null, null, null, null, null, null, null).size()); assertEquals(2, ffp.getActions().size()); assertEquals(1, ffp.getExecutorBuilders(settings).size()); + assertEquals(1, ffp.getSettings().size()); } } } diff --git a/src/test/java/org/opensearch/flowframework/common/FlowFrameworkFeatureEnabledSettingTests.java b/src/test/java/org/opensearch/flowframework/common/FlowFrameworkFeatureEnabledSettingTests.java new file mode 100644 index 000000000..b022c7789 --- /dev/null +++ b/src/test/java/org/opensearch/flowframework/common/FlowFrameworkFeatureEnabledSettingTests.java @@ -0,0 +1,58 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ +package org.opensearch.flowframework.common; + +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.test.OpenSearchTestCase; + +import java.io.IOException; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class FlowFrameworkFeatureEnabledSettingTests extends OpenSearchTestCase { + + private Settings settings; + private Environment environment; + private ClusterSettings clusterSettings; + private ClusterService clusterService; + + private FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting; + + @Override + public void setUp() throws Exception { + super.setUp(); + + settings = Settings.builder().build(); + 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); + flowFrameworkFeatureEnabledSetting = new FlowFrameworkFeatureEnabledSetting(clusterService, settings); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testSettings() throws IOException { + assertFalse(flowFrameworkFeatureEnabledSetting.isFlowFrameworkEnabled()); + } +}