|
| 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.analysis.common; |
| 21 | + |
| 22 | +import org.elasticsearch.Version; |
| 23 | +import org.elasticsearch.cluster.metadata.IndexMetaData; |
| 24 | +import org.elasticsearch.common.settings.Settings; |
| 25 | +import org.elasticsearch.env.Environment; |
| 26 | +import org.elasticsearch.index.IndexSettings; |
| 27 | +import org.elasticsearch.index.analysis.CharFilterFactory; |
| 28 | +import org.elasticsearch.test.ESTestCase; |
| 29 | +import org.elasticsearch.test.IndexSettingsModule; |
| 30 | +import org.elasticsearch.test.VersionUtils; |
| 31 | + |
| 32 | +import java.io.IOException; |
| 33 | +import java.io.StringReader; |
| 34 | +import java.util.Map; |
| 35 | + |
| 36 | + |
| 37 | +public class HtmlStripCharFilterFactoryTests extends ESTestCase { |
| 38 | + |
| 39 | + /** |
| 40 | + * Check that the deprecated name "htmlStrip" issues a deprecation warning for indices created since 6.3.0 |
| 41 | + */ |
| 42 | + public void testDeprecationWarning() throws IOException { |
| 43 | + Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) |
| 44 | + .put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_6_3_0, Version.CURRENT)) |
| 45 | + .build(); |
| 46 | + |
| 47 | + IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings); |
| 48 | + try (CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin()) { |
| 49 | + Map<String, CharFilterFactory> charFilters = createTestAnalysis(idxSettings, settings, commonAnalysisPlugin).charFilter; |
| 50 | + CharFilterFactory charFilterFactory = charFilters.get("htmlStrip"); |
| 51 | + assertNotNull(charFilterFactory.create(new StringReader("input"))); |
| 52 | + assertWarnings("The [htmpStrip] char filter name is deprecated and will be removed in a future version. " |
| 53 | + + "Please change the filter name to [html_strip] instead."); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Check that the deprecated name "htmlStrip" does NOT issues a deprecation warning for indices created before 6.3.0 |
| 59 | + */ |
| 60 | + public void testNoDeprecationWarningPre6_3() throws IOException { |
| 61 | + Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) |
| 62 | + .put(IndexMetaData.SETTING_VERSION_CREATED, |
| 63 | + VersionUtils.randomVersionBetween(random(), Version.V_5_0_0, Version.V_6_2_4)) |
| 64 | + .build(); |
| 65 | + |
| 66 | + IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings); |
| 67 | + try (CommonAnalysisPlugin commonAnalysisPlugin = new CommonAnalysisPlugin()) { |
| 68 | + Map<String, CharFilterFactory> charFilters = createTestAnalysis(idxSettings, settings, commonAnalysisPlugin).charFilter; |
| 69 | + CharFilterFactory charFilterFactory = charFilters.get("htmlStrip"); |
| 70 | + assertNotNull(charFilterFactory.create(new StringReader(""))); |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments