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

jianglongtao 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 95e6edd9cfc Improve properties verification of ShadowAlgorithms #24749 
(#25075)
95e6edd9cfc is described below

commit 95e6edd9cfc21b566cca2d1396c3caa40374ce5f
Author: Jiajun Zhang <[email protected]>
AuthorDate: Wed Apr 12 15:59:11 2023 +0800

    Improve properties verification of ShadowAlgorithms #24749 (#25075)
    
    * add test cases(#24749)
    
    * add test cases(#24749)
    
    * add test cases(#24749)
---
 .../shadow/column/ColumnRegexMatchShadowAlgorithmTest.java | 14 ++++++++++++++
 .../shadow/column/ColumnValueMatchShadowAlgorithmTest.java | 14 ++++++++++++++
 2 files changed, 28 insertions(+)

diff --git 
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
 
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
index 9471be803b1..e63623ecf16 100644
--- 
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
+++ 
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnRegexMatchShadowAlgorithmTest.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.shadow.algorithm.shadow.column;
 
 import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
+import 
org.apache.shardingsphere.shadow.exception.algorithm.ShadowAlgorithmInitializationException;
 import 
org.apache.shardingsphere.shadow.exception.data.UnsupportedShadowColumnTypeException;
 import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
 import org.apache.shardingsphere.test.util.PropertiesBuilder;
@@ -49,4 +50,17 @@ class ColumnRegexMatchShadowAlgorithmTest {
         assertThrows(UnsupportedShadowColumnTypeException.class,
                 () -> 
PreciseColumnShadowValueFixtureBuilder.createExceptionCase(SHADOW_TABLE, 
SHADOW_COLUMN).forEach(each -> assertFalse(shadowAlgorithm.isShadow(each))));
     }
+
+    @Test
+    void assertPropertiesWithoutColumn() {
+        assertThrows(ShadowAlgorithmInitializationException.class, () ->
+                TypedSPILoader.getService(ShadowAlgorithm.class, 
"REGEX_MATCH", PropertiesBuilder.build(new Property("operation", "insert"), new 
Property("value", "[1]"))));
+    }
+
+    @Test
+    void assertPropertiesWithWrongOperation() {
+        assertThrows(ShadowAlgorithmInitializationException.class, () ->
+                TypedSPILoader.getService(ShadowAlgorithm.class, "REGEX_MATCH",
+                                          PropertiesBuilder.build(new 
Property("column", SHADOW_COLUMN), new Property("operation", "wrong"), new 
Property("value", "[1]"))));
+    }
 }
diff --git 
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnValueMatchShadowAlgorithmTest.java
 
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnValueMatchShadowAlgorithmTest.java
index 88f8113397e..d404ce6d4d6 100644
--- 
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnValueMatchShadowAlgorithmTest.java
+++ 
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/algorithm/shadow/column/ColumnValueMatchShadowAlgorithmTest.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.shadow.algorithm.shadow.column;
 
 import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
+import 
org.apache.shardingsphere.shadow.exception.algorithm.ShadowAlgorithmInitializationException;
 import 
org.apache.shardingsphere.shadow.exception.data.UnsupportedShadowColumnTypeException;
 import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
 import org.apache.shardingsphere.test.util.PropertiesBuilder;
@@ -49,4 +50,17 @@ class ColumnValueMatchShadowAlgorithmTest {
         assertThrows(UnsupportedShadowColumnTypeException.class,
                 () -> 
PreciseColumnShadowValueFixtureBuilder.createExceptionCase(SHADOW_TABLE, 
SHADOW_COLUMN).forEach(each -> assertFalse(shadowAlgorithm.isShadow(each))));
     }
+
+    @Test
+    void assertPropertiesWithoutColumn() {
+        assertThrows(ShadowAlgorithmInitializationException.class, () ->
+                TypedSPILoader.getService(ShadowAlgorithm.class, 
"VALUE_MATCH", PropertiesBuilder.build(new Property("operation", "insert"), new 
Property("value", "1"))));
+    }
+
+    @Test
+    void assertPropertiesWithWrongOperation() {
+        assertThrows(ShadowAlgorithmInitializationException.class, () ->
+                TypedSPILoader.getService(ShadowAlgorithm.class, "VALUE_MATCH",
+                                          PropertiesBuilder.build(new 
Property("column", SHADOW_COLUMN), new Property("operation", "wrong"), new 
Property("value", "1"))));
+    }
 }

Reply via email to