This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 779d583e806 Add test cases for MaskAlgorithmChangedProcessor (#30606)
779d583e806 is described below
commit 779d583e80625db9b14b76691da42dc08937039e
Author: roopsai <[email protected]>
AuthorDate: Wed Mar 27 21:11:06 2024 +0530
Add test cases for MaskAlgorithmChangedProcessor (#30606)
* Add test cases for MaskAlgorithmChangedProcessor
* Add test cases for mask.rule.changed module
* Add test cases for mask.rule.changed module
* Add test cases for package rule.changed of mask-core module
* Fix Spotless
---------
Co-authored-by: Roopsai Developers <[email protected]>
---
.../changed/MaskAlgorithmChangedProcessorTest.java | 75 +++++++++++++++++++++
.../changed/MaskTableChangedProcessorTest.java | 76 ++++++++++++++++++++++
2 files changed, 151 insertions(+)
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskAlgorithmChangedProcessorTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskAlgorithmChangedProcessorTest.java
new file mode 100644
index 00000000000..a8ca86e00d2
--- /dev/null
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskAlgorithmChangedProcessorTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.rule.changed;
+
+import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import
org.apache.shardingsphere.infra.rule.event.rule.alter.AlterNamedRuleItemEvent;
+import
org.apache.shardingsphere.infra.rule.event.rule.drop.DropNamedRuleItemEvent;
+import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+class MaskAlgorithmChangedProcessorTest {
+
+ @Test
+ void assertSwapRuleItemConfiguration() {
+ MaskAlgorithmChangedProcessor processor = new
MaskAlgorithmChangedProcessor();
+ AlterNamedRuleItemEvent event = mock(AlterNamedRuleItemEvent.class);
+ AlgorithmConfiguration algorithmConfiguration =
processor.swapRuleItemConfiguration(event, "type: TEST");
+ assertThat(algorithmConfiguration.getType(), is("TEST"));
+ }
+
+ @Test
+ void assertFindRuleConfiguration() {
+ MaskAlgorithmChangedProcessor processor = new
MaskAlgorithmChangedProcessor();
+ ResourceMetaData resourceMetaData = new
ResourceMetaData(Collections.emptyMap());
+ RuleMetaData ruleMetaData = new
RuleMetaData(Collections.singleton(mock(ShardingSphereRule.class)));
+ ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db",
mock(DatabaseType.class), resourceMetaData, ruleMetaData,
Collections.emptyMap());
+ MaskRuleConfiguration maskRuleConfiguration =
processor.findRuleConfiguration(database);
+ assertThat(maskRuleConfiguration.getMaskAlgorithms().size(), is(0));
+
+ }
+
+ @Test
+ void assertDropRuleItemConfiguration() {
+ MaskAlgorithmChangedProcessor processor =
mock(MaskAlgorithmChangedProcessor.class);
+ DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class);
+ MaskRuleConfiguration currentRuleConfig = new
MaskRuleConfiguration(Collections.emptyList(), Collections.singletonMap("type:
TEST", mock(AlgorithmConfiguration.class)));
+ processor.dropRuleItemConfiguration(event, currentRuleConfig);
+ verify(processor).dropRuleItemConfiguration(event, currentRuleConfig);
+ }
+
+ @Test
+ void assertGetType() {
+ MaskAlgorithmChangedProcessor processor = new
MaskAlgorithmChangedProcessor();
+ String type = processor.getType();
+ assertEquals("mask.mask_algorithms", type);
+ }
+}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskTableChangedProcessorTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskTableChangedProcessorTest.java
new file mode 100644
index 00000000000..9e51f8c1b16
--- /dev/null
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/changed/MaskTableChangedProcessorTest.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.rule.changed;
+
+import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import
org.apache.shardingsphere.infra.rule.event.rule.alter.AlterRuleItemEvent;
+import
org.apache.shardingsphere.infra.rule.event.rule.drop.DropNamedRuleItemEvent;
+import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
+import
org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
+import
org.apache.shardingsphere.mask.metadata.nodepath.MaskRuleNodePathProvider;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+class MaskTableChangedProcessorTest {
+
+ @Test
+ void assertSwapRuleItemConfiguration() {
+ AlterRuleItemEvent event = mock(AlterRuleItemEvent.class);
+ MaskTableChangedProcessor processor = new MaskTableChangedProcessor();
+ MaskTableRuleConfiguration maskTableRuleConfiguration =
processor.swapRuleItemConfiguration(event, "name: test_table");
+ assertThat(maskTableRuleConfiguration.getName(), is("test_table"));
+ }
+
+ @Test
+ void assertFindRuleConfiguration() {
+ MaskTableChangedProcessor processor = new MaskTableChangedProcessor();
+ ResourceMetaData resourceMetaData = new
ResourceMetaData(Collections.emptyMap());
+ RuleMetaData ruleMetaData = new
RuleMetaData(Collections.singleton(mock(ShardingSphereRule.class)));
+ ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db",
mock(DatabaseType.class), resourceMetaData, ruleMetaData,
Collections.emptyMap());
+ MaskRuleConfiguration maskRuleConfiguration =
processor.findRuleConfiguration(database);
+ assertThat(maskRuleConfiguration.getTables().size(), is(0));
+ }
+
+ @Test
+ void assertDropRuleItemConfiguration() {
+ MaskTableChangedProcessor processor =
mock(MaskTableChangedProcessor.class);
+ DropNamedRuleItemEvent event = mock(DropNamedRuleItemEvent.class);
+ MaskRuleConfiguration currentRuleConfig = new
MaskRuleConfiguration(Collections.emptyList(), Collections.singletonMap("name:
test_table", mock(AlgorithmConfiguration.class)));
+ processor.dropRuleItemConfiguration(event, currentRuleConfig);
+ verify(processor).dropRuleItemConfiguration(event, currentRuleConfig);
+ }
+
+ @Test
+ void assertGetType() {
+ MaskTableChangedProcessor processor = new MaskTableChangedProcessor();
+ String result = processor.getType();
+ assertEquals(MaskRuleNodePathProvider.RULE_TYPE + "." +
MaskRuleNodePathProvider.TABLES, result);
+ }
+}