This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new b8e63d23801 Use PropertiesBuilder in mask module (#23264)
b8e63d23801 is described below
commit b8e63d2380109120183d3c0ac0a0dbf53505e9f6
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jan 2 22:21:49 2023 +0800
Use PropertiesBuilder in mask module (#23264)
---
features/mask/core/pom.xml | 7 ++++
.../cover/KeepFirstNLastMMaskAlgorithmTest.java | 37 ++++++++---------
.../cover/KeepFromXToYMaskAlgorithmTest.java | 40 +++++++++---------
.../cover/MaskAfterSpecialCharsAlgorithmTest.java | 38 +++++++----------
.../cover/MaskBeforeSpecialCharsAlgorithmTest.java | 38 +++++++----------
.../cover/MaskFirstNLastMMaskAlgorithmTest.java | 24 ++++++-----
.../cover/MaskFromXToYMaskAlgorithmTest.java | 24 ++++++-----
.../mask/algorithm/hash/MD5MaskAlgorithmTest.java | 21 +++-------
...alIdentityNumberRandomReplaceAlgorithmTest.java | 12 ++----
.../TelephoneRandomReplaceAlgorithmTest.java | 18 +++------
features/mask/distsql/handler/pom.xml | 7 ++++
.../converter/MaskRuleStatementConverterTest.java | 11 ++---
.../metrics/result/MetricsMetaDataResult.java | 1 -
.../agent/metrics/result/MetricsQueryResult.java | 2 +-
test/pom.xml | 2 +
{features/mask/core => test/util}/pom.xml | 22 +---------
.../test/util/PropertiesBuilder.java} | 47 ++++++++++++----------
17 files changed, 154 insertions(+), 197 deletions(-)
diff --git a/features/mask/core/pom.xml b/features/mask/core/pom.xml
index ad9f7fd5fea..38d5b975075 100644
--- a/features/mask/core/pom.xml
+++ b/features/mask/core/pom.xml
@@ -39,6 +39,13 @@
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-util</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFirstNLastMMaskAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFirstNLastMMaskAlgorithmTest.java
index d17aa7a366f..6c2f257c9fd 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFirstNLastMMaskAlgorithmTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFirstNLastMMaskAlgorithmTest.java
@@ -18,11 +18,11 @@
package org.apache.shardingsphere.mask.algorithm.cover;
import
org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -33,34 +33,31 @@ public final class KeepFirstNLastMMaskAlgorithmTest {
@Before
public void setUp() {
maskAlgorithm = new KeepFirstNLastMMaskAlgorithm();
- maskAlgorithm.init(createProperties("2", "5", "*"));
- }
-
- private Properties createProperties(final String firstN, final String
lastM, final String replaceChar) {
- Properties result = new Properties();
- result.setProperty("first-n", firstN);
- result.setProperty("last-m", lastM);
- result.setProperty("replace-char", replaceChar);
- return result;
+ maskAlgorithm.init(PropertiesBuilder.build(new Property("first-n",
"2"), new Property("last-m", "5"), new Property("replace-char", "*")));
}
@Test
public void assertMask() {
- String actual = maskAlgorithm.mask("abc123456");
- assertThat(actual, is("ab**23456"));
+ assertThat(maskAlgorithm.mask("abc123456"), is("ab**23456"));
}
@Test
public void assertMaskWhenPlainValueLengthLessThenFirstNLastMSum() {
- String actual = maskAlgorithm.mask("abc");
- assertThat(actual, is("abc"));
+ assertThat(maskAlgorithm.mask("abc"), is("abc"));
+ }
+
+ @Test(expected = MaskAlgorithmInitializationException.class)
+ public void assertInitWhenFirstNIsEmpty() {
+ new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("first-n", ""), new Property("last-m", "5"), new
Property("replace-char", "*")));
+ }
+
+ @Test(expected = MaskAlgorithmInitializationException.class)
+ public void assertInitWhenLastMIsEmpty() {
+ new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("first-n", "2"), new Property("last-m", ""), new
Property("replace-char", "*")));
}
@Test(expected = MaskAlgorithmInitializationException.class)
- public void assertInitWhenConfigWrongProps() {
- KeepFirstNLastMMaskAlgorithm maskAlgorithm = new
KeepFirstNLastMMaskAlgorithm();
- maskAlgorithm.init(createProperties("", "3", "+"));
- maskAlgorithm.init(createProperties("2", "", "+"));
- maskAlgorithm.init(createProperties("2", "5", ""));
+ public void assertInitWhenReplaceCharIsEmpty() {
+ new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("first-n", "2"), new Property("last-m", "5"), new
Property("replace-char", "")));
}
}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFromXToYMaskAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFromXToYMaskAlgorithmTest.java
index 148aba3e1c4..f32d4be7100 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFromXToYMaskAlgorithmTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/KeepFromXToYMaskAlgorithmTest.java
@@ -18,11 +18,11 @@
package org.apache.shardingsphere.mask.algorithm.cover;
import
org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -33,40 +33,36 @@ public final class KeepFromXToYMaskAlgorithmTest {
@Before
public void setUp() {
maskAlgorithm = new KeepFromXToYMaskAlgorithm();
- maskAlgorithm.init(createProperties("2", "5", "*"));
- }
-
- private Properties createProperties(final String fromX, final String toY,
final String replaceChar) {
- Properties result = new Properties();
- result.setProperty("from-x", fromX);
- result.setProperty("to-y", toY);
- result.setProperty("replace-char", replaceChar);
- return result;
+ maskAlgorithm.init(PropertiesBuilder.build(new Property("from-x",
"2"), new Property("to-y", "5"), new Property("replace-char", "*")));
}
@Test
public void assertMask() {
- String actual = maskAlgorithm.mask("abc123456");
- assertThat(actual, is("**c123***"));
+ assertThat(maskAlgorithm.mask("abc123456"), is("**c123***"));
}
@Test
public void assertMaskWhenPlainValueLengthLessThanToY() {
- String actual = maskAlgorithm.mask("abc");
- assertThat(actual, is("**c"));
+ assertThat(maskAlgorithm.mask("abc"), is("**c"));
}
@Test
public void assertMaskWhenPlainValueLengthLessThanFromX() {
- String actual = maskAlgorithm.mask("a");
- assertThat(actual, is("a"));
+ assertThat(maskAlgorithm.mask("a"), is("a"));
+ }
+
+ @Test(expected = MaskAlgorithmInitializationException.class)
+ public void assertInitWhenFromXIsEmpty() {
+ new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", ""), new Property("to-y", "5"), new Property("replace-char",
"*")));
+ }
+
+ @Test(expected = MaskAlgorithmInitializationException.class)
+ public void assertInitWhenToYIsEmpty() {
+ new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", "2"), new Property("to-y", ""), new Property("replace-char",
"*")));
}
@Test(expected = MaskAlgorithmInitializationException.class)
- public void assertInitWhenConfigWrongProps() {
- KeepFirstNLastMMaskAlgorithm maskAlgorithm = new
KeepFirstNLastMMaskAlgorithm();
- maskAlgorithm.init(createProperties("", "3", "+"));
- maskAlgorithm.init(createProperties("2", "", "+"));
- maskAlgorithm.init(createProperties("2", "5", ""));
+ public void assertInitWhenReplaceCharIsEmpty() {
+ new KeepFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", "2"), new Property("to-y", "5"), new
Property("replace-char", "")));
}
}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskAfterSpecialCharsAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskAfterSpecialCharsAlgorithmTest.java
index 072d5db4b3b..8e749ce0dc4 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskAfterSpecialCharsAlgorithmTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskAfterSpecialCharsAlgorithmTest.java
@@ -18,11 +18,11 @@
package org.apache.shardingsphere.mask.algorithm.cover;
import
org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -34,49 +34,41 @@ public final class MaskAfterSpecialCharsAlgorithmTest {
@Before
public void setUp() {
maskAlgorithm = new MaskAfterSpecialCharsAlgorithm();
- maskAlgorithm.init(createProperties("d1"));
- }
-
- private Properties createProperties(final String specialChars) {
- Properties result = new Properties();
- result.setProperty("special-chars", specialChars);
- result.setProperty("replace-char", "*");
- return result;
+ maskAlgorithm.init(PropertiesBuilder.build(new
Property("special-chars", "d1"), new Property("replace-char", "*")));
}
@Test
public void assertMask() {
- String actual = maskAlgorithm.mask("abcd134");
- assertThat(actual, is("abcd1**"));
+ assertThat(maskAlgorithm.mask("abcd134"), is("abcd1**"));
}
@Test
public void assertMaskWhenPlainValueMatchedMultipleSpecialChars() {
- String actual = maskAlgorithm.mask("abcd1234d1234");
- assertThat(actual, is("abcd1********"));
+ assertThat(maskAlgorithm.mask("abcd1234d1234"), is("abcd1********"));
}
@Test
public void assertMaskEmptyString() {
- String actual = maskAlgorithm.mask("");
- assertThat(actual, is(""));
+ assertThat(maskAlgorithm.mask(""), is(""));
}
@Test
public void assertMaskNull() {
- String actual = maskAlgorithm.mask(null);
- assertThat(actual, is(nullValue()));
+ assertThat(maskAlgorithm.mask(null), is(nullValue()));
}
@Test
public void assertMaskWhenPlainValueNotMatchedSpecialChars() {
- String actual = maskAlgorithm.mask("abcd234");
- assertThat(actual, is("abcd234"));
+ assertThat(maskAlgorithm.mask("abcd234"), is("abcd234"));
+ }
+
+ @Test(expected = MaskAlgorithmInitializationException.class)
+ public void assertInitWhenSpecialCharsIsEmpty() {
+ new MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new
Property("special-chars", ""), new Property("replace-char", "*")));
}
@Test(expected = MaskAlgorithmInitializationException.class)
- public void assertInitWhenConfigWrongProps() {
- MaskBeforeSpecialCharsAlgorithm maskAlgorithm = new
MaskBeforeSpecialCharsAlgorithm();
- maskAlgorithm.init(createProperties(""));
+ public void assertInitWhenReplaceCharIsEmpty() {
+ new MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new
Property("special-chars", "d1"), new Property("replace-char", "")));
}
}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskBeforeSpecialCharsAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskBeforeSpecialCharsAlgorithmTest.java
index d39de0a0441..64dcd685aff 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskBeforeSpecialCharsAlgorithmTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskBeforeSpecialCharsAlgorithmTest.java
@@ -18,11 +18,11 @@
package org.apache.shardingsphere.mask.algorithm.cover;
import
org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -34,49 +34,41 @@ public final class MaskBeforeSpecialCharsAlgorithmTest {
@Before
public void setUp() {
maskAlgorithm = new MaskBeforeSpecialCharsAlgorithm();
- maskAlgorithm.init(createProperties("d1"));
- }
-
- private Properties createProperties(final String specialChars) {
- Properties result = new Properties();
- result.setProperty("special-chars", specialChars);
- result.setProperty("replace-char", "*");
- return result;
+ maskAlgorithm.init(PropertiesBuilder.build(new
Property("special-chars", "d1"), new Property("replace-char", "*")));
}
@Test
public void assertMask() {
- String actual = maskAlgorithm.mask("abcd134");
- assertThat(actual, is("***d134"));
+ assertThat(maskAlgorithm.mask("abcd134"), is("***d134"));
}
@Test
public void assertMaskWhenPlainValueMatchedMultipleSpecialChars() {
- String actual = maskAlgorithm.mask("abcd1234d1234");
- assertThat(actual, is("***d1234d1234"));
+ assertThat(maskAlgorithm.mask("abcd1234d1234"), is("***d1234d1234"));
}
@Test
public void assertMaskEmptyString() {
- String actual = maskAlgorithm.mask("");
- assertThat(actual, is(""));
+ assertThat(maskAlgorithm.mask(""), is(""));
}
@Test
public void assertMaskNull() {
- String actual = maskAlgorithm.mask(null);
- assertThat(actual, is(nullValue()));
+ assertThat(maskAlgorithm.mask(null), is(nullValue()));
}
@Test
public void assertMaskWhenPlainValueNotMatchedSpecialChars() {
- String actual = maskAlgorithm.mask("abcd234");
- assertThat(actual, is("abcd234"));
+ assertThat(maskAlgorithm.mask("abcd234"), is("abcd234"));
+ }
+
+ @Test(expected = MaskAlgorithmInitializationException.class)
+ public void assertInitWhenSpecialCharsIsEmpty() {
+ new MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new
Property("special-chars", ""), new Property("replace-char", "*")));
}
@Test(expected = MaskAlgorithmInitializationException.class)
- public void assertInitWhenConfigWrongProps() {
- MaskBeforeSpecialCharsAlgorithm maskAlgorithm = new
MaskBeforeSpecialCharsAlgorithm();
- maskAlgorithm.init(createProperties(""));
+ public void assertInitWhenReplaceCharIsEmpty() {
+ new MaskBeforeSpecialCharsAlgorithm().init(PropertiesBuilder.build(new
Property("special-chars", "d1"), new Property("replace-char", "")));
}
}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFirstNLastMMaskAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFirstNLastMMaskAlgorithmTest.java
index df71fc8db2a..eeb6da1e093 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFirstNLastMMaskAlgorithmTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFirstNLastMMaskAlgorithmTest.java
@@ -18,11 +18,11 @@
package org.apache.shardingsphere.mask.algorithm.cover;
import
org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -33,7 +33,7 @@ public final class MaskFirstNLastMMaskAlgorithmTest {
@Before
public void setUp() {
maskAlgorithm = new MaskFirstNLastMMaskAlgorithm();
- maskAlgorithm.init(createProperties("3", "5", "*"));
+ maskAlgorithm.init(PropertiesBuilder.build(new Property("first-n",
"3"), new Property("last-m", "5"), new Property("replace-char", "*")));
}
@Test
@@ -47,15 +47,17 @@ public final class MaskFirstNLastMMaskAlgorithmTest {
}
@Test(expected = MaskAlgorithmInitializationException.class)
- public void assertInitWhenConfigWrongProps() {
- maskAlgorithm.init(createProperties("", "3", "+"));
+ public void assertInitWhenFirstNIsEmpty() {
+ new MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("first-n", ""), new Property("last-m", "5"), new
Property("replace-char", "*")));
}
- private Properties createProperties(final String firstN, final String
lastM, final String replaceChar) {
- Properties result = new Properties();
- result.setProperty("first-n", firstN);
- result.setProperty("last-m", lastM);
- result.setProperty("replace-char", replaceChar);
- return result;
+ @Test(expected = MaskAlgorithmInitializationException.class)
+ public void assertInitWhenLastMIsEmpty() {
+ new MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("first-n", "3"), new Property("last-m", ""), new
Property("replace-char", "*")));
+ }
+
+ @Test(expected = MaskAlgorithmInitializationException.class)
+ public void assertInitWhenReplaceCharIsEmpty() {
+ new MaskFirstNLastMMaskAlgorithm().init(PropertiesBuilder.build(new
Property("first-n", "3"), new Property("last-m", "5"), new
Property("replace-char", "")));
}
}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithmTest.java
index a7643177297..e103a972b28 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithmTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/cover/MaskFromXToYMaskAlgorithmTest.java
@@ -18,11 +18,11 @@
package org.apache.shardingsphere.mask.algorithm.cover;
import
org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -33,7 +33,7 @@ public final class MaskFromXToYMaskAlgorithmTest {
@Before
public void setUp() {
maskAlgorithm = new MaskFromXToYMaskAlgorithm();
- maskAlgorithm.init(createProperties("3", "5", "*"));
+ maskAlgorithm.init(PropertiesBuilder.build(new Property("from-x",
"3"), new Property("to-y", "5"), new Property("replace-char", "*")));
}
@Test
@@ -52,15 +52,17 @@ public final class MaskFromXToYMaskAlgorithmTest {
}
@Test(expected = MaskAlgorithmInitializationException.class)
- public void assertInitWhenConfigWrongProps() {
- maskAlgorithm.init(createProperties("5", "", "+"));
+ public void assertInitWhenFromXIsEmpty() {
+ new MaskFromXToYMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", ""), new Property("to-y", "5"), new Property("replace-char",
"*")));
}
- private Properties createProperties(final String fromX, final String toY,
final String replaceChar) {
- Properties result = new Properties();
- result.setProperty("from-x", fromX);
- result.setProperty("to-y", toY);
- result.setProperty("replace-char", replaceChar);
- return result;
+ @Test(expected = MaskAlgorithmInitializationException.class)
+ public void assertInitWhenToYIsEmpty() {
+ new MaskFromXToYMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", "3"), new Property("to-y", ""), new Property("replace-char",
"*")));
+ }
+
+ @Test(expected = MaskAlgorithmInitializationException.class)
+ public void assertInitWhenReplaceCharIsEmpty() {
+ new MaskFromXToYMaskAlgorithm().init(PropertiesBuilder.build(new
Property("from-x", "3"), new Property("to-y", "5"), new
Property("replace-char", "")));
}
}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/hash/MD5MaskAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/hash/MD5MaskAlgorithmTest.java
index 5cd612404d4..099b9892992 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/hash/MD5MaskAlgorithmTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/hash/MD5MaskAlgorithmTest.java
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.mask.algorithm.hash;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull;
@@ -29,31 +29,22 @@ public final class MD5MaskAlgorithmTest {
@Test
public void assertMask() {
- String actual = createMaskAlgorithm("").mask("abc123456");
- assertThat(actual, is("0659c7992e268962384eb17fafe88364"));
+ assertThat(createMaskAlgorithm("").mask("abc123456"),
is("0659c7992e268962384eb17fafe88364"));
}
@Test
public void assertMaskWhenPlainValueIsNull() {
- String actual = createMaskAlgorithm("").mask(null);
- assertNull(actual);
+ assertNull(createMaskAlgorithm("").mask(null));
}
@Test
public void assertMaskWhenConfigSalt() {
- String actual =
createMaskAlgorithm("202cb962ac5907").mask("abc123456");
- assertThat(actual, is("02d44390e9354b72dd2aa78d55016f7f"));
+ assertThat(createMaskAlgorithm("202cb962ac5907").mask("abc123456"),
is("02d44390e9354b72dd2aa78d55016f7f"));
}
private MD5MaskAlgorithm createMaskAlgorithm(final String salt) {
MD5MaskAlgorithm result = new MD5MaskAlgorithm();
- result.init(createProperties(salt));
- return result;
- }
-
- private Properties createProperties(final String salt) {
- Properties result = new Properties();
- result.setProperty("salt", salt);
+ result.init(PropertiesBuilder.build(new Property("salt", salt)));
return result;
}
}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/PersonalIdentityNumberRandomReplaceAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/PersonalIdentityNumberRandomReplaceAlgorithmTest.java
index ad5394c819a..861a4ce2e47 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/PersonalIdentityNumberRandomReplaceAlgorithmTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/PersonalIdentityNumberRandomReplaceAlgorithmTest.java
@@ -17,11 +17,11 @@
package org.apache.shardingsphere.mask.algorithm.replace;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -33,7 +33,7 @@ public final class
PersonalIdentityNumberRandomReplaceAlgorithmTest {
@Before
public void setUp() {
maskAlgorithm = new PersonalIdentityNumberRandomReplaceAlgorithm();
- maskAlgorithm.init(createProperties());
+ maskAlgorithm.init(PropertiesBuilder.build(new
Property("alpha-two-country-area-code", "CN")));
}
@Test
@@ -44,10 +44,4 @@ public final class
PersonalIdentityNumberRandomReplaceAlgorithmTest {
assertThat(maskAlgorithm.mask("123456"), is("123456"));
assertThat(maskAlgorithm.mask(""), is(""));
}
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("alpha-two-country-area-code", "CN");
- return result;
- }
}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithmTest.java
index 8a566312587..827840e3bc6 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithmTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/TelephoneRandomReplaceAlgorithmTest.java
@@ -18,11 +18,11 @@
package org.apache.shardingsphere.mask.algorithm.replace;
import
org.apache.shardingsphere.mask.exception.algorithm.MaskAlgorithmInitializationException;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Before;
import org.junit.Test;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -35,12 +35,7 @@ public final class TelephoneRandomReplaceAlgorithmTest {
@Before
public void setUp() {
maskAlgorithm = new TelephoneRandomReplaceAlgorithm();
- maskAlgorithm.init(createProperties("130, 130, 155,1702"));
- }
-
- @Test(expected = MaskAlgorithmInitializationException.class)
- public void assertInitWhenConfigNotNumberProps() {
- maskAlgorithm.init(createProperties("130, x130, 155,1702"));
+ maskAlgorithm.init(PropertiesBuilder.build(new
Property("network-numbers", "130, 130, 155,1702")));
}
@Test
@@ -55,9 +50,8 @@ public final class TelephoneRandomReplaceAlgorithmTest {
assertThat(maskAlgorithm.mask("13012345678"), not("13012345678"));
}
- private Properties createProperties(final String networkNumbers) {
- Properties result = new Properties();
- result.setProperty("network-numbers", networkNumbers);
- return result;
+ @Test(expected = MaskAlgorithmInitializationException.class)
+ public void assertInitWhenConfigNotNumberProps() {
+ maskAlgorithm.init(PropertiesBuilder.build(new
Property("network-numbers", "130, x130, 155,1702")));
}
}
diff --git a/features/mask/distsql/handler/pom.xml
b/features/mask/distsql/handler/pom.xml
index 5029c87f132..ed5cae24009 100644
--- a/features/mask/distsql/handler/pom.xml
+++ b/features/mask/distsql/handler/pom.xml
@@ -48,5 +48,12 @@
<artifactId>shardingsphere-mask-distsql-parser</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-util</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git
a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/converter/MaskRuleStatementConverterTest.java
b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/converter/MaskRuleStatementConverterTest.java
index c34d3e8be65..b5d50937c6e 100644
---
a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/converter/MaskRuleStatementConverterTest.java
+++
b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/converter/MaskRuleStatementConverterTest.java
@@ -21,11 +21,12 @@ import
org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
import org.apache.shardingsphere.mask.distsql.parser.segment.MaskColumnSegment;
import org.apache.shardingsphere.mask.distsql.parser.segment.MaskRuleSegment;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -44,12 +45,6 @@ public final class MaskRuleStatementConverterTest {
}
private Collection<MaskColumnSegment> createColumns() {
- return Collections.singleton(new MaskColumnSegment("user_id", new
AlgorithmSegment("MD5", createProperties())));
- }
-
- private Properties createProperties() {
- Properties result = new Properties();
- result.setProperty("salt", "test_salt");
- return result;
+ return Collections.singleton(new MaskColumnSegment("user_id", new
AlgorithmSegment("MD5", PropertiesBuilder.build(new Property("salt",
"test_salt")))));
}
}
diff --git
a/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/result/MetricsMetaDataResult.java
b/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/result/MetricsMetaDataResult.java
index 26fbfc0da6f..1c2e27b961e 100644
---
a/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/result/MetricsMetaDataResult.java
+++
b/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/result/MetricsMetaDataResult.java
@@ -23,7 +23,6 @@ import lombok.Setter;
import java.util.List;
import java.util.Map;
-
/**
* Metrics meta data result.
*/
diff --git
a/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/result/MetricsQueryResult.java
b/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/result/MetricsQueryResult.java
index 11f74dd7ea0..ebf2ef07f54 100644
---
a/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/result/MetricsQueryResult.java
+++
b/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/result/MetricsQueryResult.java
@@ -62,7 +62,7 @@ public final class MetricsQueryResult implements
JsonConfiguration {
* Query data result metric.
*/
public static final class QueryDataResultMetric {
-
+
@SerializedName("__name__")
private String name;
diff --git a/test/pom.xml b/test/pom.xml
index 040280c8908..1f4f696a472 100644
--- a/test/pom.xml
+++ b/test/pom.xml
@@ -30,6 +30,8 @@
<modules>
<module>fixture</module>
+ <module>util</module>
+
<module>it</module>
<module>e2e</module>
</modules>
diff --git a/features/mask/core/pom.xml b/test/util/pom.xml
similarity index 63%
copy from features/mask/core/pom.xml
copy to test/util/pom.xml
index ad9f7fd5fea..f5c31a22ff3 100644
--- a/features/mask/core/pom.xml
+++ b/test/util/pom.xml
@@ -21,27 +21,9 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-mask</artifactId>
+ <artifactId>shardingsphere-test</artifactId>
<version>5.3.1-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-mask-core</artifactId>
+ <artifactId>shardingsphere-test-util</artifactId>
<name>${project.artifactId}</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-mask-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-infra-merge</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- </dependency>
- </dependencies>
</project>
diff --git
a/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/result/MetricsMetaDataResult.java
b/test/util/src/main/java/org/apache/shardingsphere/test/util/PropertiesBuilder.java
similarity index 51%
copy from
test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/result/MetricsMetaDataResult.java
copy to
test/util/src/main/java/org/apache/shardingsphere/test/util/PropertiesBuilder.java
index 26fbfc0da6f..2c7f4655fb5 100644
---
a/test/e2e/agent/plugins/metrics/src/test/java/org/apache/shardingsphere/test/e2e/agent/metrics/result/MetricsMetaDataResult.java
+++
b/test/util/src/main/java/org/apache/shardingsphere/test/util/PropertiesBuilder.java
@@ -15,37 +15,42 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.e2e.agent.metrics.result;
+package org.apache.shardingsphere.test.util;
-import lombok.Getter;
-import lombok.Setter;
-
-import java.util.List;
-import java.util.Map;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.RequiredArgsConstructor;
+import java.util.Properties;
/**
- * Metrics meta data result.
+ * Properties builder.
*/
-@Getter
-@Setter
-public final class MetricsMetaDataResult implements JsonConfiguration {
-
- private String status;
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class PropertiesBuilder {
- private Map<String, List<Metric>> data;
+ /**
+ * Build properties.
+ *
+ * @param properties to be built properties
+ * @return built properties
+ */
+ public static Properties build(final Property... properties) {
+ Properties result = new Properties();
+ for (Property each : properties) {
+ result.setProperty(each.key, each.value);
+ }
+ return result;
+ }
/**
- * Metric.
+ * Property.
*/
- @Getter
- @Setter
- public static final class Metric {
-
- private String type;
+ @RequiredArgsConstructor
+ public static class Property {
- private String help;
+ private final String key;
- private String unit;
+ private final String value;
}
}