diff --git a/src/main/java/org/opensearch/sdk/sample/helloworld/ExampleCustomSettingConfig.java b/src/main/java/org/opensearch/sdk/sample/helloworld/ExampleCustomSettingConfig.java index dc2409af..b5c7e38e 100644 --- a/src/main/java/org/opensearch/sdk/sample/helloworld/ExampleCustomSettingConfig.java +++ b/src/main/java/org/opensearch/sdk/sample/helloworld/ExampleCustomSettingConfig.java @@ -17,16 +17,14 @@ * {@link ExampleCustomSettingConfig} contains the custom settings value and their static declarations. */ public class ExampleCustomSettingConfig { - private static final String FORBIDDEN_REGEX = "forbidden"; - + private static final String FORBIDDEN_VALUE = "forbidden"; /** - * A string setting. If the string setting matches the FORBIDDEN_REGEX string, the validation will fail. + * A string setting. If the string setting matches the FORBIDDEN_REGEX string and parameter isMatching is true the validation will fail. */ public static final Setting VALIDATED_SETTING = Setting.simpleString( "custom.validate", - new RegexValidator(FORBIDDEN_REGEX), + new RegexValidator(FORBIDDEN_VALUE, false), Property.NodeScope, Property.Dynamic ); - } diff --git a/src/test/java/org/opensearch/sdk/sample/helloworld/TestHelloWorldExtension.java b/src/test/java/org/opensearch/sdk/sample/helloworld/TestHelloWorldExtension.java index 6a8a787e..a78355e0 100644 --- a/src/test/java/org/opensearch/sdk/sample/helloworld/TestHelloWorldExtension.java +++ b/src/test/java/org/opensearch/sdk/sample/helloworld/TestHelloWorldExtension.java @@ -245,15 +245,17 @@ public void onFailure(Exception e) { assertEquals("failed to find action [" + UnregisteredAction.INSTANCE + "] to execute", ex.getMessage()); } + @Test public void testValidatedSettings() { - final String expected = randomAlphaOfLengthBetween(1, 5); + final String expected = "foo"; final String actual = VALIDATED_SETTING.get(Settings.builder().put(VALIDATED_SETTING.getKey(), expected).build()); assertEquals(expected, actual); - final IllegalArgumentException exception = expectThrows( + final IllegalArgumentException exceptionTrue = expectThrows( IllegalArgumentException.class, - () -> VALIDATED_SETTING.get(Settings.builder().put("custom.validated", "it's forbidden").build()) + () -> VALIDATED_SETTING.get(Settings.builder().put(VALIDATED_SETTING.getKey(), "it's forbidden").build()) ); - assertEquals("Setting must not contain [forbidden]", exception.getMessage()); + + assertEquals("Setting [it's forbidden] must match regex [forbidden]", exceptionTrue.getMessage()); } }