This is an automated email from the ASF dual-hosted git repository.

yx9o 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 293fe3674d4 Use PropertiesBuilder in encrypt module (#23267)
293fe3674d4 is described below

commit 293fe3674d42920cb9b6985a6a5291c1fe009610
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jan 2 23:26:30 2023 +0800

    Use PropertiesBuilder in encrypt module (#23267)
---
 features/encrypt/core/pom.xml                      |  6 +++++
 .../algorithm/encrypt/AESEncryptAlgorithmTest.java | 10 +++------
 .../algorithm/encrypt/MD5EncryptAlgorithmTest.java |  6 ++---
 .../algorithm/encrypt/RC4EncryptAlgorithmTest.java | 26 ++++++----------------
 .../like/CharDigestLikeEncryptAlgorithmTest.java   | 12 ++++------
 features/encrypt/distsql/handler/pom.xml           |  7 ++++++
 .../EncryptRuleStatementConverterTest.java         | 15 +++++--------
 features/encrypt/distsql/parser/pom.xml            |  7 ++++++
 features/encrypt/plugin/sm/pom.xml                 |  7 ++++++
 .../sm/algorithm/SM3EncryptAlgorithmTest.java      | 10 +++------
 .../sm/algorithm/SM4EncryptAlgorithmTest.java      | 26 ++++++----------------
 11 files changed, 59 insertions(+), 73 deletions(-)

diff --git a/features/encrypt/core/pom.xml b/features/encrypt/core/pom.xml
index 579fd5c89d1..060c01e67ac 100644
--- a/features/encrypt/core/pom.xml
+++ b/features/encrypt/core/pom.xml
@@ -55,6 +55,12 @@
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-test-util</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
             <artifactId>shardingsphere-single-core</artifactId>
diff --git 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/AESEncryptAlgorithmTest.java
 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/AESEncryptAlgorithmTest.java
index 7f77b1fc8a3..a2571f6f475 100644
--- 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/AESEncryptAlgorithmTest.java
+++ 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/AESEncryptAlgorithmTest.java
@@ -22,6 +22,8 @@ import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
 import 
org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -38,13 +40,7 @@ public final class AESEncryptAlgorithmTest {
     
     @Before
     public void setUp() {
-        encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new 
AlgorithmConfiguration("AES", createProperties()), EncryptAlgorithm.class);
-    }
-    
-    private Properties createProperties() {
-        Properties result = new Properties();
-        result.setProperty("aes-key-value", "test");
-        return result;
+        encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new 
AlgorithmConfiguration("AES", PropertiesBuilder.build(new 
Property("aes-key-value", "test"))), EncryptAlgorithm.class);
     }
     
     @Test(expected = IllegalArgumentException.class)
diff --git 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/MD5EncryptAlgorithmTest.java
 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/MD5EncryptAlgorithmTest.java
index 74bc23751fa..db01507703b 100644
--- 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/MD5EncryptAlgorithmTest.java
+++ 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/MD5EncryptAlgorithmTest.java
@@ -22,6 +22,8 @@ import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
 import 
org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -54,9 +56,7 @@ public final class MD5EncryptAlgorithmTest {
     
     @Test
     public void assertEncryptWhenConfigSalt() {
-        Properties props = new Properties();
-        props.setProperty("salt", "202cb962ac5907");
-        encryptAlgorithm.init(props);
+        encryptAlgorithm.init(PropertiesBuilder.build(new Property("salt", 
"202cb962ac5907")));
         assertThat(encryptAlgorithm.encrypt("test", 
mock(EncryptContext.class)), is("0c243d2934937738f36514035d95344a"));
     }
     
diff --git 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/RC4EncryptAlgorithmTest.java
 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/RC4EncryptAlgorithmTest.java
index 5ac3cc3b6be..ed1f08aa361 100644
--- 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/RC4EncryptAlgorithmTest.java
+++ 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/encrypt/RC4EncryptAlgorithmTest.java
@@ -23,10 +23,13 @@ import 
org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
 import 
org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+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 java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -39,13 +42,8 @@ public final class RC4EncryptAlgorithmTest {
     
     @Before
     public void setUp() {
-        encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new 
AlgorithmConfiguration("RC4", createProperties()), EncryptAlgorithm.class);
-    }
-    
-    private Properties createProperties() {
-        Properties result = new Properties();
-        result.setProperty("rc4-key-value", "test-sharding");
-        return result;
+        encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(
+                new AlgorithmConfiguration("RC4", PropertiesBuilder.build(new 
Property("rc4-key-value", "test-sharding"))), EncryptAlgorithm.class);
     }
     
     @Test
@@ -60,17 +58,7 @@ public final class RC4EncryptAlgorithmTest {
     
     @Test(expected = EncryptAlgorithmInitializationException.class)
     public void assertKeyIsToLong() {
-        encryptAlgorithm.init(createInvalidProperties());
-    }
-    
-    private Properties createInvalidProperties() {
-        Properties result = new Properties();
-        StringBuilder keyBuffer = new StringBuilder();
-        for (int i = 0; i < 100; i++) {
-            keyBuffer.append("test");
-        }
-        result.setProperty("rc4-key-value", keyBuffer.toString());
-        return result;
+        encryptAlgorithm.init(PropertiesBuilder.build(new 
Property("rc4-key-value", IntStream.range(0, 100).mapToObj(each -> 
"test").collect(Collectors.joining()))));
     }
     
     @Test
diff --git 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithmTest.java
 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithmTest.java
index 254a6600fe0..4b0358a3137 100644
--- 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithmTest.java
+++ 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithmTest.java
@@ -22,6 +22,8 @@ import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
 import 
org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -44,14 +46,8 @@ public final class CharDigestLikeEncryptAlgorithmTest {
     public void setUp() {
         englishLikeEncryptAlgorithm = 
ShardingSphereAlgorithmFactory.createAlgorithm(new 
AlgorithmConfiguration("CHAR_DIGEST_LIKE", new Properties()), 
EncryptAlgorithm.class);
         chineseLikeEncryptAlgorithm = 
ShardingSphereAlgorithmFactory.createAlgorithm(new 
AlgorithmConfiguration("CHAR_DIGEST_LIKE", new Properties()), 
EncryptAlgorithm.class);
-        koreanLikeEncryptAlgorithm = 
ShardingSphereAlgorithmFactory.createAlgorithm(new 
AlgorithmConfiguration("CHAR_DIGEST_LIKE", createProperties()), 
EncryptAlgorithm.class);
-    }
-    
-    private Properties createProperties() {
-        Properties result = new Properties();
-        result.setProperty("dict", "한국어시험");
-        result.setProperty("start", "44032");
-        return result;
+        koreanLikeEncryptAlgorithm = 
ShardingSphereAlgorithmFactory.createAlgorithm(
+                new AlgorithmConfiguration("CHAR_DIGEST_LIKE", 
PropertiesBuilder.build(new Property("dict", "한국어시험"), new Property("start", 
"44032"))), EncryptAlgorithm.class);
     }
     
     @Test
diff --git a/features/encrypt/distsql/handler/pom.xml 
b/features/encrypt/distsql/handler/pom.xml
index 6fe4e500826..4eb142671a2 100644
--- a/features/encrypt/distsql/handler/pom.xml
+++ b/features/encrypt/distsql/handler/pom.xml
@@ -48,5 +48,12 @@
             <artifactId>shardingsphere-encrypt-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/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverterTest.java
 
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverterTest.java
index e941cde8ad8..d776b2ae56d 100644
--- 
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverterTest.java
+++ 
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverterTest.java
@@ -21,11 +21,12 @@ import 
org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
 import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSegment;
 import 
org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment;
+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;
@@ -45,14 +46,8 @@ public final class EncryptRuleStatementConverterTest {
     
     private Collection<EncryptColumnSegment> createColumns() {
         return Collections.singleton(new EncryptColumnSegment("user_id", 
"user_cipher", "user_plain", "assisted_column", "like_column",
-                new AlgorithmSegment("MD5", createProperties()),
-                new AlgorithmSegment("MD5", createProperties()),
-                new AlgorithmSegment("CHAR_DIGEST_LIKE", createProperties()), 
null));
-    }
-    
-    private Properties createProperties() {
-        Properties result = new Properties();
-        result.setProperty("MD5-key", "MD5-value");
-        return result;
+                new AlgorithmSegment("MD5", PropertiesBuilder.build(new 
Property("MD5-key", "MD5-value"))),
+                new AlgorithmSegment("MD5", PropertiesBuilder.build(new 
Property("MD5-key", "MD5-value"))),
+                new AlgorithmSegment("CHAR_DIGEST_LIKE", 
PropertiesBuilder.build(new Property("MD5-key", "MD5-value"))), null));
     }
 }
diff --git a/features/encrypt/distsql/parser/pom.xml 
b/features/encrypt/distsql/parser/pom.xml
index 51a9eb7d380..8dd3dc20f4a 100644
--- a/features/encrypt/distsql/parser/pom.xml
+++ b/features/encrypt/distsql/parser/pom.xml
@@ -43,6 +43,13 @@
             <artifactId>shardingsphere-encrypt-distsql-statement</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>
     
     <build>
diff --git a/features/encrypt/plugin/sm/pom.xml 
b/features/encrypt/plugin/sm/pom.xml
index db192cb4f6e..f883ce80cdf 100644
--- a/features/encrypt/plugin/sm/pom.xml
+++ b/features/encrypt/plugin/sm/pom.xml
@@ -38,6 +38,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>org.bouncycastle</groupId>
             <artifactId>bcprov-jdk15on</artifactId>
diff --git 
a/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM3EncryptAlgorithmTest.java
 
b/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM3EncryptAlgorithmTest.java
index 1ffbf8c0837..00910900876 100644
--- 
a/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM3EncryptAlgorithmTest.java
+++ 
b/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM3EncryptAlgorithmTest.java
@@ -22,6 +22,8 @@ import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
 import 
org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -38,13 +40,7 @@ public final class SM3EncryptAlgorithmTest {
     
     @Before
     public void setUp() {
-        encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new 
AlgorithmConfiguration("SM3", createProperties()), EncryptAlgorithm.class);
-    }
-    
-    private Properties createProperties() {
-        Properties result = new Properties();
-        result.setProperty("sm3-salt", "test1234");
-        return result;
+        encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new 
AlgorithmConfiguration("SM3", PropertiesBuilder.build(new Property("sm3-salt", 
"test1234"))), EncryptAlgorithm.class);
     }
     
     @Test
diff --git 
a/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM4EncryptAlgorithmTest.java
 
b/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM4EncryptAlgorithmTest.java
index 26e94349b64..32d9fe3d5bb 100644
--- 
a/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM4EncryptAlgorithmTest.java
+++ 
b/features/encrypt/plugin/sm/src/test/java/org/apache/shardingsphere/encrypt/sm/algorithm/SM4EncryptAlgorithmTest.java
@@ -22,6 +22,8 @@ import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
 import 
org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithmFactory;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
 import org.junit.Test;
 
 import java.util.Properties;
@@ -36,14 +38,7 @@ public final class SM4EncryptAlgorithmTest {
     @Test(expected = IllegalArgumentException.class)
     public void assertInitWithoutKey() {
         StandardEncryptAlgorithm<Object, String> algorithm = 
ShardingSphereAlgorithmFactory.createAlgorithm(new 
AlgorithmConfiguration("SM4", createECBProperties()), EncryptAlgorithm.class);
-        algorithm.init(createInvalidProperties());
-    }
-    
-    private Properties createInvalidProperties() {
-        Properties result = new Properties();
-        result.setProperty("sm4-mode", "ECB");
-        result.setProperty("sm4-padding", "PKCS5Padding");
-        return result;
+        algorithm.init(PropertiesBuilder.build(new Property("sm4-mode", 
"ECB"), new Property("sm4-padding", "PKCS5Padding")));
     }
     
     @Test
@@ -71,11 +66,7 @@ public final class SM4EncryptAlgorithmTest {
     }
     
     private Properties createECBProperties() {
-        Properties result = new Properties();
-        result.setProperty("sm4-key", "4D744E003D713D054E7E407C350E447E");
-        result.setProperty("sm4-mode", "ECB");
-        result.setProperty("sm4-padding", "PKCS5Padding");
-        return result;
+        return PropertiesBuilder.build(new Property("sm4-key", 
"4D744E003D713D054E7E407C350E447E"), new Property("sm4-mode", "ECB"), new 
Property("sm4-padding", "PKCS5Padding"));
     }
     
     @Test
@@ -91,11 +82,8 @@ public final class SM4EncryptAlgorithmTest {
     }
     
     private Properties createCBCProperties() {
-        Properties result = new Properties();
-        result.setProperty("sm4-key", "f201326119911788cFd30575b81059ac");
-        result.setProperty("sm4-iv", "e166c3391294E69cc4c620f594fe00d7");
-        result.setProperty("sm4-mode", "CBC");
-        result.setProperty("sm4-padding", "PKCS7Padding");
-        return result;
+        return PropertiesBuilder.build(
+                new Property("sm4-key", "f201326119911788cFd30575b81059ac"), 
new Property("sm4-iv", "e166c3391294E69cc4c620f594fe00d7"),
+                new Property("sm4-mode", "CBC"), new Property("sm4-padding", 
"PKCS7Padding"));
     }
 }

Reply via email to