|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.rest.action.admin.cluster; |
| 21 | + |
| 22 | +import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse; |
| 23 | +import org.elasticsearch.cluster.ClusterState; |
| 24 | +import org.elasticsearch.cluster.metadata.MetaData; |
| 25 | +import org.elasticsearch.common.settings.ClusterSettings; |
| 26 | +import org.elasticsearch.common.settings.Setting; |
| 27 | +import org.elasticsearch.common.settings.Settings; |
| 28 | +import org.elasticsearch.common.settings.SettingsFilter; |
| 29 | +import org.elasticsearch.test.ESTestCase; |
| 30 | + |
| 31 | +import java.util.Collections; |
| 32 | +import java.util.Set; |
| 33 | +import java.util.function.BiConsumer; |
| 34 | +import java.util.function.Function; |
| 35 | +import java.util.stream.Collectors; |
| 36 | +import java.util.stream.Stream; |
| 37 | + |
| 38 | + |
| 39 | +public class RestClusterGetSettingsActionTests extends ESTestCase { |
| 40 | + |
| 41 | + public void testFilterPersistentSettings() { |
| 42 | + runTestFilterSettingsTest(MetaData.Builder::persistentSettings, ClusterGetSettingsResponse::getPersistentSettings); |
| 43 | + } |
| 44 | + |
| 45 | + public void testFilterTransientSettings() { |
| 46 | + runTestFilterSettingsTest(MetaData.Builder::transientSettings, ClusterGetSettingsResponse::getTransientSettings); |
| 47 | + } |
| 48 | + |
| 49 | + private void runTestFilterSettingsTest( |
| 50 | + final BiConsumer<MetaData.Builder, Settings> md, final Function<ClusterGetSettingsResponse, Settings> s) { |
| 51 | + final MetaData.Builder mdBuilder = new MetaData.Builder(); |
| 52 | + final Settings settings = Settings.builder().put("foo.filtered", "bar").put("foo.non_filtered", "baz").build(); |
| 53 | + md.accept(mdBuilder, settings); |
| 54 | + final ClusterState.Builder builder = new ClusterState.Builder(ClusterState.EMPTY_STATE).metaData(mdBuilder); |
| 55 | + final SettingsFilter filter = new SettingsFilter(Settings.EMPTY, Collections.singleton("foo.filtered")); |
| 56 | + final Setting.Property[] properties = {Setting.Property.Dynamic, Setting.Property.Filtered, Setting.Property.NodeScope}; |
| 57 | + final Set<Setting<?>> settingsSet = Stream.concat( |
| 58 | + ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), |
| 59 | + Stream.concat( |
| 60 | + Stream.of(Setting.simpleString("foo.filtered", properties)), |
| 61 | + Stream.of(Setting.simpleString("foo.non_filtered", properties)))) |
| 62 | + .collect(Collectors.toSet()); |
| 63 | + final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, settingsSet); |
| 64 | + final ClusterGetSettingsResponse response = |
| 65 | + RestClusterGetSettingsAction.response(builder.build(), randomBoolean(), filter, clusterSettings, Settings.EMPTY); |
| 66 | + assertFalse(s.apply(response).hasValue("foo.filtered")); |
| 67 | + assertTrue(s.apply(response).hasValue("foo.non_filtered")); |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments