From 177f515fa40287ff1d2014983908c0e86641075c Mon Sep 17 00:00:00 2001 From: carlosdelest Date: Fri, 17 May 2024 16:38:15 +0200 Subject: [PATCH] Fix forbidden APIs --- .../mapper/NonDynamicFieldMapperTestCase.java | 22 +++++++------------ .../mapper/NonDynamicFieldMapperTests.java | 7 +++--- ...emanticTextNonDynamicFieldMapperTests.java | 5 +++-- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/index/mapper/NonDynamicFieldMapperTestCase.java b/server/src/test/java/org/elasticsearch/index/mapper/NonDynamicFieldMapperTestCase.java index 67ad3d582b81e..faff3d882096f 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/NonDynamicFieldMapperTestCase.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/NonDynamicFieldMapperTestCase.java @@ -29,9 +29,7 @@ public abstract class NonDynamicFieldMapperTestCase extends ESSingleNodeTestCase protected abstract String getMapping(); public void testCreateExplicitMappingSucceeds() throws Exception { - String mapping = String.format( - Locale.ROOT, - """ + String mapping = String.format(Locale.ROOT, """ { "_doc": { "properties": { @@ -51,8 +49,7 @@ public void testCreateExplicitMappingSucceeds() throws Exception { } public void testCreateDynamicMappingFails() throws Exception { - String mapping = String.format( - Locale.ROOT,""" + String mapping = String.format(Locale.ROOT, """ { "_doc": { "dynamic_templates": [ @@ -72,14 +69,13 @@ public void testCreateDynamicMappingFails() throws Exception { Exception exc = expectThrows(Exception.class, () -> req.get()); assertThat(exc.getCause(), instanceOf(IllegalArgumentException.class)); assertThat(exc.getCause().getCause(), instanceOf(MapperParsingException.class)); - assertThat(exc.getCause().getCause().getMessage(), containsString("["+getTypeName()+"] can't be used in dynamic templates")); + assertThat(exc.getCause().getCause().getMessage(), containsString("[" + getTypeName() + "] can't be used in dynamic templates")); } public void testUpdateDynamicMappingFails() throws Exception { var resp = client().admin().indices().prepareCreate("test").get(); assertTrue(resp.isAcknowledged()); - String mapping = String.format( - Locale.ROOT,""" + String mapping = String.format(Locale.ROOT, """ { "_doc": { "dynamic_templates": [ @@ -99,12 +95,11 @@ public void testUpdateDynamicMappingFails() throws Exception { Exception exc = expectThrows(Exception.class, () -> req.get()); assertThat(exc.getCause(), instanceOf(IllegalArgumentException.class)); assertThat(exc.getCause().getCause(), instanceOf(MapperParsingException.class)); - assertThat(exc.getCause().getCause().getMessage(), containsString("["+getTypeName()+"] can't be used in dynamic templates")); + assertThat(exc.getCause().getCause().getMessage(), containsString("[" + getTypeName() + "] can't be used in dynamic templates")); } public void testCreateDynamicMappingInIndexTemplateFails() throws Exception { - String mapping = String.format( - Locale.ROOT,""" + String mapping = String.format(Locale.ROOT, """ { "_doc": { "dynamic_templates": [ @@ -128,12 +123,11 @@ public void testCreateDynamicMappingInIndexTemplateFails() throws Exception { Exception exc = expectThrows(Exception.class, () -> req.get()); assertThat(exc.getCause(), instanceOf(IllegalArgumentException.class)); assertThat(exc.getCause().getCause(), instanceOf(MapperParsingException.class)); - assertThat(exc.getCause().getCause().getMessage(), containsString("["+getTypeName()+"] can't be used in dynamic templates")); + assertThat(exc.getCause().getCause().getMessage(), containsString("[" + getTypeName() + "] can't be used in dynamic templates")); } public void testCreateExplicitMappingInIndexTemplateSucceeds() throws Exception { - String mapping = String.format( - Locale.ROOT,""" + String mapping = String.format(Locale.ROOT, """ { "_doc": { "properties": { diff --git a/server/src/test/java/org/elasticsearch/index/mapper/NonDynamicFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/NonDynamicFieldMapperTests.java index 403f6d71c04cc..7b8486e5050c2 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/NonDynamicFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/NonDynamicFieldMapperTests.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.util.Collection; import java.util.List; +import java.util.Locale; import java.util.Map; public class NonDynamicFieldMapperTests extends NonDynamicFieldMapperTestCase { @@ -27,9 +28,9 @@ protected String getTypeName() { } protected String getMapping() { - return """ - "type": "%s" - """.formatted(NonDynamicFieldMapper.NAME); + return String.format(Locale.ROOT, """ + "type": "%s" + """, NonDynamicFieldMapper.NAME); } public static class NonDynamicFieldPlugin extends Plugin implements MapperPlugin { diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextNonDynamicFieldMapperTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextNonDynamicFieldMapperTests.java index 7a1e6d7660e77..e75d1c92e0e62 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextNonDynamicFieldMapperTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextNonDynamicFieldMapperTests.java @@ -18,6 +18,7 @@ import java.util.Collection; import java.util.List; +import java.util.Locale; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; @@ -44,10 +45,10 @@ protected String getTypeName() { @Override protected String getMapping() { - return """ + return String.format(Locale.ROOT, """ "type": "%s", "inference_id": "%s" - """.formatted(SemanticTextFieldMapper.CONTENT_TYPE, TestSparseInferenceServiceExtension.TestInferenceService.NAME); + """, SemanticTextFieldMapper.CONTENT_TYPE, TestSparseInferenceServiceExtension.TestInferenceService.NAME); } private void storeSparseModel() throws Exception {