From 810f242aa05269557ccf5ab790ddb6ca72c11ce4 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Thu, 7 Nov 2024 00:40:05 +0800 Subject: [PATCH] Add more test cases on DatabaseRuleConfiguration's impl (#33578) * Add test cases on ReadwriteSplittingRuleConfiguration * Add more test cases on DatabaseRuleConfiguration's impl --- .../BroadcastRuleConfigurationTest.java | 32 +++++++++++++++++++ .../config/EncryptRuleConfigurationTest.java | 32 +++++++++++++++++++ .../config/MaskRuleConfigurationTest.java | 8 ----- ...teSplittingRuleStatementConverterTest.java | 10 +++--- 4 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 features/broadcast/api/src/test/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfigurationTest.java create mode 100644 features/encrypt/api/src/test/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfigurationTest.java diff --git a/features/broadcast/api/src/test/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfigurationTest.java b/features/broadcast/api/src/test/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfigurationTest.java new file mode 100644 index 0000000000000..93500a0f321a0 --- /dev/null +++ b/features/broadcast/api/src/test/java/org/apache/shardingsphere/broadcast/config/BroadcastRuleConfigurationTest.java @@ -0,0 +1,32 @@ +/* + * 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.broadcast.config; + +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +class BroadcastRuleConfigurationTest { + + @Test + void assertIsEmpty() { + assertTrue(new BroadcastRuleConfiguration(Collections.emptyList()).isEmpty()); + } +} diff --git a/features/encrypt/api/src/test/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfigurationTest.java b/features/encrypt/api/src/test/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfigurationTest.java new file mode 100644 index 0000000000000..363652e911389 --- /dev/null +++ b/features/encrypt/api/src/test/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfigurationTest.java @@ -0,0 +1,32 @@ +/* + * 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.encrypt.config; + +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +class EncryptRuleConfigurationTest { + + @Test + void assertIsEmpty() { + assertTrue(new EncryptRuleConfiguration(Collections.emptyList(), Collections.emptyMap()).isEmpty()); + } +} diff --git a/features/mask/api/src/test/java/org/apache/shardingsphere/mask/config/MaskRuleConfigurationTest.java b/features/mask/api/src/test/java/org/apache/shardingsphere/mask/config/MaskRuleConfigurationTest.java index 8b2351b60e26d..4c89f25657bd9 100644 --- a/features/mask/api/src/test/java/org/apache/shardingsphere/mask/config/MaskRuleConfigurationTest.java +++ b/features/mask/api/src/test/java/org/apache/shardingsphere/mask/config/MaskRuleConfigurationTest.java @@ -17,14 +17,11 @@ package org.apache.shardingsphere.mask.config; -import org.apache.shardingsphere.mask.config.rule.MaskTableRuleConfiguration; import org.junit.jupiter.api.Test; import java.util.Collections; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; class MaskRuleConfigurationTest { @@ -32,9 +29,4 @@ class MaskRuleConfigurationTest { void assertIsEmpty() { assertTrue(new MaskRuleConfiguration(Collections.emptyList(), Collections.emptyMap()).isEmpty()); } - - @Test - void assertIsNotEmpty() { - assertFalse(new MaskRuleConfiguration(Collections.singleton(mock(MaskTableRuleConfiguration.class)), Collections.emptyMap()).isEmpty()); - } } diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverterTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverterTest.java index fb530b307bc4e..4e728dbeff624 100644 --- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverterTest.java +++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleStatementConverterTest.java @@ -37,10 +37,12 @@ class ReadwriteSplittingRuleStatementConverterTest { @Test void assertConvert() { - ReadwriteSplittingRuleConfiguration actual = ReadwriteSplittingRuleStatementConverter.convert(Collections.singleton(new ReadwriteSplittingRuleSegment( - "foo_name", "write_ds", Arrays.asList("read_ds0", "read_ds1"), TransactionalReadQueryStrategy.FIXED.name(), new AlgorithmSegment("foo_algo", new Properties())))); - assertThat(actual.getDataSourceGroups(), deepEqual(Collections.singletonList( - new ReadwriteSplittingDataSourceGroupRuleConfiguration("foo_name", "write_ds", Arrays.asList("read_ds0", "read_ds1"), TransactionalReadQueryStrategy.FIXED, "foo_name_foo_algo")))); + ReadwriteSplittingRuleSegment ruleSegment = new ReadwriteSplittingRuleSegment( + "foo_name", "write_ds", Arrays.asList("read_ds0", "read_ds1"), TransactionalReadQueryStrategy.FIXED.name(), new AlgorithmSegment("foo_algo", new Properties())); + ReadwriteSplittingRuleConfiguration actual = ReadwriteSplittingRuleStatementConverter.convert(Collections.singleton(ruleSegment)); + ReadwriteSplittingDataSourceGroupRuleConfiguration expectedDataSourceGroupRuleConfig = new ReadwriteSplittingDataSourceGroupRuleConfiguration( + "foo_name", "write_ds", Arrays.asList("read_ds0", "read_ds1"), TransactionalReadQueryStrategy.FIXED, "foo_name_foo_algo"); + assertThat(actual.getDataSourceGroups(), deepEqual(Collections.singletonList(expectedDataSourceGroupRuleConfig))); assertThat(actual.getLoadBalancers(), deepEqual(Collections.singletonMap("foo_name_foo_algo", new AlgorithmConfiguration("foo_algo", new Properties())))); }