Skip to content

Commit

Permalink
Add more test cases on GenericTableRandomReplaceAlgorithm (#33438)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Oct 28, 2024
1 parent 2f67bd0 commit da1bbad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public String mask(final Object plainValue) {
char[] chars = result.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
if ('A' <= c && c <= 'Z') {
if (c >= 'A' && c <= 'Z') {
chars[i] = uppercaseLetterCodes.get(random.nextInt(uppercaseLetterCodes.size()));
} else if ('a' <= c && c <= 'z') {
} else if (c >= 'a' && c <= 'z') {
chars[i] = lowercaseLetterCodes.get(random.nextInt(lowercaseLetterCodes.size()));
} else if ('0' <= c && c <= '9') {
} else if (c >= '0' && c <= '9') {
chars[i] = digitalCodes.get(random.nextInt(digitalCodes.size()));
} else {
chars[i] = specialCodes.get(random.nextInt(specialCodes.size()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNull;

class GenericTableRandomReplaceAlgorithmTest {

Expand All @@ -39,6 +40,7 @@ void assertMask() {
GenericTableRandomReplaceAlgorithm maskAlgorithm = (GenericTableRandomReplaceAlgorithm) TypedSPILoader.getService(MaskAlgorithm.class, "GENERIC_TABLE_RANDOM_REPLACE",
PropertiesBuilder.build(new Property("uppercase-letter-codes", "A,B,C,D"),
new Property("lowercase-letter-codes", "a,b,c,d"), new Property("digital-codes", "1,2,3,4"), new Property("special-codes", "~!@#")));
assertNull(maskAlgorithm.mask(null));
assertThat(maskAlgorithm.mask(""), is(""));
assertThat(maskAlgorithm.mask("Ab1!").charAt(0), anyOf(is('A'), is('B'), is('C'), is('D')));
assertThat(maskAlgorithm.mask("Ab1!").charAt(1), anyOf(is('a'), is('b'), is('c'), is('d')));
Expand All @@ -49,6 +51,7 @@ void assertMask() {
@Test
void assertMaskWithEmptyProps() {
GenericTableRandomReplaceAlgorithm maskAlgorithm = (GenericTableRandomReplaceAlgorithm) TypedSPILoader.getService(MaskAlgorithm.class, "GENERIC_TABLE_RANDOM_REPLACE", new Properties());
assertNull(maskAlgorithm.mask(null));
assertThat(maskAlgorithm.mask("Ab1!").substring(0, 1), anyOf(Arrays.stream("ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("")).map(CoreMatchers::is).collect(Collectors.toList())));
assertThat(maskAlgorithm.mask("Ab1!").substring(1, 2), anyOf(Arrays.stream("abcdefghijklmnopqrstuvwxyz".split("")).map(CoreMatchers::is).collect(Collectors.toList())));
assertThat(maskAlgorithm.mask("Ab1!").substring(2, 3), anyOf(Arrays.stream("0123456789".split("")).map(CoreMatchers::is).collect(Collectors.toList())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@

class MppdbDecodingPluginTest {

private final LogSequenceNumber pgSequenceNumber = LogSequenceNumber.valueOf("0/14EFDB8");

private final OpenGaussLogSequenceNumber logSequenceNumber = new OpenGaussLogSequenceNumber(pgSequenceNumber);
private final OpenGaussLogSequenceNumber logSequenceNumber = new OpenGaussLogSequenceNumber(LogSequenceNumber.valueOf("0/14EFDB8"));

@Test
void assertDecodeWriteRowEvent() {
Expand Down

0 comments on commit da1bbad

Please sign in to comment.