Skip to content

Commit

Permalink
Changed the test for RegexValidator class (#608)
Browse files Browse the repository at this point in the history
* Created the MapperExtension interface and added the MapperPlugin content

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* deleted comments

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add javadoc

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add unit test

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* refactor for unit test

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* fix bugs

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* change test

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code refactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* shortened the code

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* add false parametr

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* code rafactoring

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>

* Remove stray file from old commit that survived rebase

Signed-off-by: Daniel Widdis <widdis@gmail.com>

---------

Signed-off-by: Kuanysh <kuanysh4646@gmail.com>
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Co-authored-by: Daniel Widdis <widdis@gmail.com>
  • Loading branch information
Kuanysh-kst and dbwiddis authored Apr 7, 2023
1 parent ec6a8e6 commit a7a8164
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> VALIDATED_SETTING = Setting.simpleString(
"custom.validate",
new RegexValidator(FORBIDDEN_REGEX),
new RegexValidator(FORBIDDEN_VALUE, false),
Property.NodeScope,
Property.Dynamic
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit a7a8164

Please sign in to comment.