You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/01/01 07:24:49 UTC

[shardingsphere] branch master updated: Add `MaskRuleStatementConverter` unit test (#23238)

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 1eb1a18aeca Add `MaskRuleStatementConverter` unit test (#23238)
1eb1a18aeca is described below

commit 1eb1a18aeca681967c8c11dddd7eaaf0019ca117
Author: Zichao <57...@users.noreply.github.com>
AuthorDate: Sun Jan 1 20:24:43 2023 +1300

    Add `MaskRuleStatementConverter` unit test (#23238)
    
    * Add `MaskRuleStatementConverter` unit test
    
    * Add `MaskRuleStatementConverter` unit test
---
 .../converter/MaskRuleStatementConverterTest.java  | 55 ++++++++++++++++++++++
 1 file changed, 55 insertions(+)

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
new file mode 100644
index 00000000000..c34d3e8be65
--- /dev/null
+++ b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/converter/MaskRuleStatementConverterTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.distsql.handler.converter;
+
+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.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;
+import static org.junit.Assert.assertTrue;
+
+public final class MaskRuleStatementConverterTest {
+    
+    @Test
+    public void assertCovert() {
+        MaskRuleConfiguration actual = MaskRuleStatementConverter.convert(Collections.singleton(new MaskRuleSegment("t_mask", createColumns())));
+        assertThat(actual.getTables().iterator().next().getName(), is("t_mask"));
+        assertThat(actual.getTables().iterator().next().getColumns().iterator().next().getLogicColumn(), is("user_id"));
+        assertThat(actual.getTables().iterator().next().getColumns().iterator().next().getMaskAlgorithm(), is("t_mask_user_id_md5"));
+        assertThat(actual.getMaskAlgorithms().keySet().iterator().next(), is("t_mask_user_id_md5"));
+        assertTrue(actual.getMaskAlgorithms().values().iterator().next().getType().contains("MD5"));
+    }
+    
+    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;
+    }
+}