strongduanmu commented on code in PR #22825:
URL: https://github.com/apache/shardingsphere/pull/22825#discussion_r1045723992


##########
features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/config/YamlMaskRuleConfiguration.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mask.yaml.config;
+
+import lombok.Getter;
+import lombok.Setter;
+import 
org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration;
+import 
org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
+import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
+import 
org.apache.shardingsphere.mask.yaml.config.rule.YamlMaskTableRuleConfiguration;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Mask rule configuration for YAML.
+ */
+@Getter
+@Setter
+public class YamlMaskRuleConfiguration implements YamlRuleConfiguration {

Review Comment:
   Please add final for YamlMaskRuleConfiguration.



##########
features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/config/rule/YamlMaskColumnRuleConfiguration.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mask.yaml.config.rule;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;
+
+/**
+ * Mask column rule configuration for YAML.
+ */
+@Getter
+@Setter
+public class YamlMaskColumnRuleConfiguration implements YamlConfiguration {

Review Comment:
   Please add final for YamlMaskColumnRuleConfiguration.



##########
features/mask/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper:
##########
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.shardingsphere.mask.algorithm.hash.MD5MaskAlgorithm
+org.apache.shardingsphere.mask.yaml.swapper.YamlMaskRuleConfigurationSwapper

Review Comment:
   Why remove the MaskAlgorithm spi file?



##########
features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/rule/YamlMaskTableRuleConfigurationSwapperTest.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mask.yaml.swapper.rule;
+
+import 
org.apache.shardingsphere.mask.api.config.rule.MaskColumnRuleConfiguration;
+import 
org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
+import 
org.apache.shardingsphere.mask.yaml.config.rule.YamlMaskColumnRuleConfiguration;
+import 
org.apache.shardingsphere.mask.yaml.config.rule.YamlMaskTableRuleConfiguration;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public final class YamlMaskTableRuleConfigurationSwapperTest {
+    
+    private final YamlMaskTableRuleConfigurationSwapper swapper = new 
YamlMaskTableRuleConfigurationSwapper();
+    
+    @Test
+    public void assertSwapToYamlConfiguration() {
+        Collection<MaskColumnRuleConfiguration> encryptColumnRuleConfigs = 
Arrays.asList(
+                new MaskColumnRuleConfiguration("mask_column_1", "md5_mask"),
+                new MaskColumnRuleConfiguration("mask_column_2", 
"keep_from_x_to_y"),
+                new MaskColumnRuleConfiguration("mask_column_3", 
"keep_first_m_last_m"));
+        MaskTableRuleConfiguration encryptTableRuleConfig = new 
MaskTableRuleConfiguration("test_table", encryptColumnRuleConfigs);
+        YamlMaskTableRuleConfiguration actualYamlMaskTableRuleConfig = 
swapper.swapToYamlConfiguration(encryptTableRuleConfig);
+        assertThat(actualYamlMaskTableRuleConfig.getName(), is("test_table"));
+        Map<String, YamlMaskColumnRuleConfiguration> actualColumns = 
actualYamlMaskTableRuleConfig.getColumns();
+        assertThat(actualColumns.size(), is(3));
+        YamlMaskColumnRuleConfiguration actualYamlMaskColumnRuleConfigFirst = 
actualColumns.get("mask_column_1");
+        assertThat(actualYamlMaskColumnRuleConfigFirst.getMaskAlgorithm(), 
is("md5_mask"));
+        YamlMaskColumnRuleConfiguration actualYamlMaskColumnRuleConfigSecond = 
actualColumns.get("mask_column_2");
+        assertThat(actualYamlMaskColumnRuleConfigSecond.getMaskAlgorithm(), 
is("keep_from_x_to_y"));
+        YamlMaskColumnRuleConfiguration actualYamlMaskColumnRuleConfigThird = 
actualColumns.get("mask_column_3");
+        assertThat(actualYamlMaskColumnRuleConfigThird.getMaskAlgorithm(), 
is("keep_first_m_last_m"));
+    }
+    
+    @Test
+    public void assertSwapToObject() {
+        YamlMaskColumnRuleConfiguration encryptColumnRuleConfig = new 
YamlMaskColumnRuleConfiguration();
+        encryptColumnRuleConfig.setLogicColumn("mask_column");
+        encryptColumnRuleConfig.setMaskAlgorithm("md5_mask");
+        Map<String, YamlMaskColumnRuleConfiguration> columns = new 
LinkedHashMap<>(1);
+        columns.put("mask_column", encryptColumnRuleConfig);
+        YamlMaskTableRuleConfiguration yamlMaskTableRuleConfig = new 
YamlMaskTableRuleConfiguration();
+        yamlMaskTableRuleConfig.setName("test_table");
+        yamlMaskTableRuleConfig.setColumns(columns);
+        MaskTableRuleConfiguration actualMaskTableRuleConfig = 
swapper.swapToObject(yamlMaskTableRuleConfig);
+        assertThat(actualMaskTableRuleConfig.getName(), is("test_table"));
+        Collection<MaskColumnRuleConfiguration> actualColumns = 
actualMaskTableRuleConfig.getColumns();
+        assertThat(actualColumns.size(), is(1));
+        MaskColumnRuleConfiguration actualMaskColumnRuleConfig = 
actualColumns.iterator().next();
+        assertThat(actualMaskColumnRuleConfig.getLogicColumn(), 
is("mask_column"));
+        assertThat(actualMaskColumnRuleConfig.getMaskAlgorithm(), 
is("md5_mask"));
+        

Review Comment:
   Please remove this useless blank line.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to