Skip to content

Commit

Permalink
Fix forbidden APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed May 17, 2024
1 parent 059ff81 commit 177f515
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": [
Expand All @@ -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": [
Expand All @@ -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": [
Expand All @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit 177f515

Please sign in to comment.