You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/05/17 15:34:45 UTC

[shardingsphere] branch master updated: Add test cases for default schema and global RuleConfigurationBuilderFactory . (#17652)

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

duanzhengqiang 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 69932aaed2b Add test cases for default schema and global RuleConfigurationBuilderFactory . (#17652)
69932aaed2b is described below

commit 69932aaed2bcb4e2aeb0d35864f6b86ee806f35b
Author: VOPEN.XYZ <x_...@yeah.net>
AuthorDate: Tue May 17 23:34:38 2022 +0800

    Add test cases for default schema and global RuleConfigurationBuilderFactory . (#17652)
    
    * Add test case for DefaultSchemaRuleConfigurationBuilderFactory .
    
    * Modify the parameter modifier with final .
    
    * Add the final modifier for test classes and removed useless blank lines .
    
    * Add test case for DefaultGlobalRuleConfigurationBuilderFactory .
    
    * Add test case for SchemaRuleBuilderFactory and GlobalRuleBuilderFactory .
    
    * Improve assertion statements and fix invalid code style .
---
 .../FixtureGlobalRule.java}                        | 21 ++-----
 .../FixtureGlobalRuleBuilder.java}                 | 28 +++++----
 .../FixtureGlobalRuleConfiguration.java}           | 20 +------
 .../FixtureGlobalRuleConfigurationBuilder.java}    | 29 ++++-----
 .../FixtureSchemaRule.java}                        | 21 ++-----
 .../builder/fixture/FixtureSchemaRuleBuilder.java  | 45 ++++++++++++++
 .../FixtureSchemaRuleConfiguration.java}           | 20 +------
 .../FixtureSchemaRuleConfigurationBuilder.java}    | 29 ++++-----
 ...GlobalRuleConfigurationBuilderFactoryTest.java} | 21 ++++---
 .../global/GlobalRuleBuilderFactoryTest.java       | 66 +++++++++++++++++++++
 .../builder/global/GlobalRulesBuilderTest.java     |  9 ++-
 ...SchemaRuleConfigurationBuilderFactoryTest.java} | 23 +++-----
 .../schema/SchemaRuleBuilderFactoryTest.java       | 69 ++++++++++++++++++++++
 .../builder/schema/SchemaRulesBuilderTest.java     |  8 ++-
 ...r.global.DefaultGlobalRuleConfigurationBuilder} |  2 +-
 ...re.infra.rule.builder.global.GlobalRuleBuilder} |  2 +-
 ...r.schema.DefaultSchemaRuleConfigurationBuilder} |  2 +-
 ...ere.infra.rule.builder.schema.SchemaRuleBuilder |  1 +
 18 files changed, 279 insertions(+), 137 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRule.java
similarity index 53%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRule.java
index 33424deed4d..39c677c208d 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRule.java
@@ -15,23 +15,14 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.rule.builder.global;
+package org.apache.shardingsphere.infra.rule.builder.fixture;
 
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.junit.Test;
+import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule;
 
-import java.util.Collections;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public final class GlobalRulesBuilderTest {
+public final class FixtureGlobalRule implements GlobalRule {
     
-    @Test
-    public void assertBuildRulesWithoutGlobalRules() {
-        assertTrue(GlobalRulesBuilder.buildRules(Collections.singletonList(mock(RuleConfiguration.class)), Collections.singletonMap("logic_db", mock(ShardingSphereMetaData.class))).isEmpty());
+    @Override
+    public String getType() {
+        return FixtureGlobalRule.class.getSimpleName();
     }
-    
-    // TODO add more test cases for BuildRulesWithGlobalRules
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleBuilder.java
similarity index 57%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleBuilder.java
index 33424deed4d..98c03ba2c88 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleBuilder.java
@@ -15,23 +15,27 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.rule.builder.global;
+package org.apache.shardingsphere.infra.rule.builder.fixture;
 
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.junit.Test;
+import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder;
 
-import java.util.Collections;
+import java.util.Map;
 
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public final class GlobalRulesBuilderTest {
+public final class FixtureGlobalRuleBuilder implements GlobalRuleBuilder<FixtureGlobalRuleConfiguration> {
+    
+    @Override
+    public FixtureGlobalRule build(final FixtureGlobalRuleConfiguration ruleConfig, final Map<String, ShardingSphereMetaData> metaDataMap) {
+        return new FixtureGlobalRule();
+    }
     
-    @Test
-    public void assertBuildRulesWithoutGlobalRules() {
-        assertTrue(GlobalRulesBuilder.buildRules(Collections.singletonList(mock(RuleConfiguration.class)), Collections.singletonMap("logic_db", mock(ShardingSphereMetaData.class))).isEmpty());
+    @Override
+    public int getOrder() {
+        return 0;
     }
     
-    // TODO add more test cases for BuildRulesWithGlobalRules
+    @Override
+    public Class<FixtureGlobalRuleConfiguration> getTypeClass() {
+        return FixtureGlobalRuleConfiguration.class;
+    }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleConfiguration.java
similarity index 52%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleConfiguration.java
index 33424deed4d..fd149d6ffbb 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleConfiguration.java
@@ -15,23 +15,9 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.rule.builder.global;
+package org.apache.shardingsphere.infra.rule.builder.fixture;
 
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.junit.Test;
+import org.apache.shardingsphere.infra.config.scope.GlobalRuleConfiguration;
 
-import java.util.Collections;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public final class GlobalRulesBuilderTest {
-    
-    @Test
-    public void assertBuildRulesWithoutGlobalRules() {
-        assertTrue(GlobalRulesBuilder.buildRules(Collections.singletonList(mock(RuleConfiguration.class)), Collections.singletonMap("logic_db", mock(ShardingSphereMetaData.class))).isEmpty());
-    }
-    
-    // TODO add more test cases for BuildRulesWithGlobalRules
+public final class FixtureGlobalRuleConfiguration implements GlobalRuleConfiguration {
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleConfigurationBuilder.java
similarity index 54%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleConfigurationBuilder.java
index 33424deed4d..35806255bc8 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleConfigurationBuilder.java
@@ -15,23 +15,24 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.rule.builder.global;
+package org.apache.shardingsphere.infra.rule.builder.fixture;
 
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.junit.Test;
+import org.apache.shardingsphere.infra.rule.builder.global.DefaultGlobalRuleConfigurationBuilder;
 
-import java.util.Collections;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public final class GlobalRulesBuilderTest {
+public final class FixtureGlobalRuleConfigurationBuilder implements DefaultGlobalRuleConfigurationBuilder<FixtureGlobalRuleConfiguration, FixtureGlobalRuleBuilder> {
     
-    @Test
-    public void assertBuildRulesWithoutGlobalRules() {
-        assertTrue(GlobalRulesBuilder.buildRules(Collections.singletonList(mock(RuleConfiguration.class)), Collections.singletonMap("logic_db", mock(ShardingSphereMetaData.class))).isEmpty());
+    @Override
+    public FixtureGlobalRuleConfiguration build() {
+        return new FixtureGlobalRuleConfiguration();
     }
     
-    // TODO add more test cases for BuildRulesWithGlobalRules
+    @Override
+    public int getOrder() {
+        return 0;
+    }
+    
+    @Override
+    public Class<FixtureGlobalRuleBuilder> getTypeClass() {
+        return FixtureGlobalRuleBuilder.class;
+    }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureSchemaRule.java
similarity index 53%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureSchemaRule.java
index 33424deed4d..ba907eff06f 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureSchemaRule.java
@@ -15,23 +15,14 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.rule.builder.global;
+package org.apache.shardingsphere.infra.rule.builder.fixture;
 
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.junit.Test;
+import org.apache.shardingsphere.infra.rule.identifier.scope.SchemaRule;
 
-import java.util.Collections;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public final class GlobalRulesBuilderTest {
+public final class FixtureSchemaRule implements SchemaRule {
     
-    @Test
-    public void assertBuildRulesWithoutGlobalRules() {
-        assertTrue(GlobalRulesBuilder.buildRules(Collections.singletonList(mock(RuleConfiguration.class)), Collections.singletonMap("logic_db", mock(ShardingSphereMetaData.class))).isEmpty());
+    @Override
+    public String getType() {
+        return FixtureSchemaRule.class.getSimpleName();
     }
-    
-    // TODO add more test cases for BuildRulesWithGlobalRules
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureSchemaRuleBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureSchemaRuleBuilder.java
new file mode 100644
index 00000000000..b9f1a7701b8
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureSchemaRuleBuilder.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.infra.rule.builder.fixture;
+
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder;
+
+import javax.sql.DataSource;
+import java.util.Collection;
+import java.util.Map;
+
+public final class FixtureSchemaRuleBuilder implements SchemaRuleBuilder<FixtureSchemaRuleConfiguration> {
+    
+    @Override
+    public FixtureSchemaRule build(final FixtureSchemaRuleConfiguration config, final String databaseName, final Map<String, DataSource> dataSources, final Collection<ShardingSphereRule> builtRules,
+                                   final ConfigurationProperties props) {
+        return new FixtureSchemaRule();
+    }
+    
+    @Override
+    public int getOrder() {
+        return 0;
+    }
+    
+    @Override
+    public Class<FixtureSchemaRuleConfiguration> getTypeClass() {
+        return FixtureSchemaRuleConfiguration.class;
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureSchemaRuleConfiguration.java
similarity index 52%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureSchemaRuleConfiguration.java
index 33424deed4d..4ac825f9adc 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureSchemaRuleConfiguration.java
@@ -15,23 +15,9 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.rule.builder.global;
+package org.apache.shardingsphere.infra.rule.builder.fixture;
 
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.junit.Test;
+import org.apache.shardingsphere.infra.config.scope.SchemaRuleConfiguration;
 
-import java.util.Collections;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public final class GlobalRulesBuilderTest {
-    
-    @Test
-    public void assertBuildRulesWithoutGlobalRules() {
-        assertTrue(GlobalRulesBuilder.buildRules(Collections.singletonList(mock(RuleConfiguration.class)), Collections.singletonMap("logic_db", mock(ShardingSphereMetaData.class))).isEmpty());
-    }
-    
-    // TODO add more test cases for BuildRulesWithGlobalRules
+public final class FixtureSchemaRuleConfiguration implements SchemaRuleConfiguration {
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureSchemaRuleConfigurationBuilder.java
similarity index 54%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureSchemaRuleConfigurationBuilder.java
index 33424deed4d..1a7d534e1ea 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureSchemaRuleConfigurationBuilder.java
@@ -15,23 +15,24 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.rule.builder.global;
+package org.apache.shardingsphere.infra.rule.builder.fixture;
 
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.junit.Test;
+import org.apache.shardingsphere.infra.rule.builder.schema.DefaultSchemaRuleConfigurationBuilder;
 
-import java.util.Collections;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public final class GlobalRulesBuilderTest {
+public final class FixtureSchemaRuleConfigurationBuilder implements DefaultSchemaRuleConfigurationBuilder<FixtureSchemaRuleConfiguration, FixtureSchemaRuleBuilder> {
     
-    @Test
-    public void assertBuildRulesWithoutGlobalRules() {
-        assertTrue(GlobalRulesBuilder.buildRules(Collections.singletonList(mock(RuleConfiguration.class)), Collections.singletonMap("logic_db", mock(ShardingSphereMetaData.class))).isEmpty());
+    @Override
+    public FixtureSchemaRuleConfiguration build() {
+        return new FixtureSchemaRuleConfiguration();
     }
     
-    // TODO add more test cases for BuildRulesWithGlobalRules
+    @Override
+    public int getOrder() {
+        return 0;
+    }
+    
+    @Override
+    public Class<FixtureSchemaRuleBuilder> getTypeClass() {
+        return FixtureSchemaRuleBuilder.class;
+    }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/DefaultGlobalRuleConfigurationBuilderFactoryTest.java
similarity index 54%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/DefaultGlobalRuleConfigurationBuilderFactoryTest.java
index 33424deed4d..f0ad18ee5e8 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/DefaultGlobalRuleConfigurationBuilderFactoryTest.java
@@ -17,21 +17,24 @@
 
 package org.apache.shardingsphere.infra.rule.builder.global;
 
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRuleBuilder;
+import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRuleConfigurationBuilder;
 import org.junit.Test;
 
 import java.util.Collections;
+import java.util.Map;
 
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
 
-public final class GlobalRulesBuilderTest {
+public final class DefaultGlobalRuleConfigurationBuilderFactoryTest {
     
     @Test
-    public void assertBuildRulesWithoutGlobalRules() {
-        assertTrue(GlobalRulesBuilder.buildRules(Collections.singletonList(mock(RuleConfiguration.class)), Collections.singletonMap("logic_db", mock(ShardingSphereMetaData.class))).isEmpty());
+    @SuppressWarnings("rawtypes")
+    public void assertGetInstance() {
+        FixtureGlobalRuleBuilder builder = new FixtureGlobalRuleBuilder();
+        Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> actual = DefaultGlobalRuleConfigurationBuilderFactory.getInstance(
+                Collections.singleton(builder));
+        assertThat(actual.get(builder), instanceOf(FixtureGlobalRuleConfigurationBuilder.class));
     }
-    
-    // TODO add more test cases for BuildRulesWithGlobalRules
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilderFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilderFactoryTest.java
new file mode 100644
index 00000000000..1e5f020086e
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilderFactoryTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.infra.rule.builder.global;
+
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRuleBuilder;
+import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRuleConfiguration;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+public final class GlobalRuleBuilderFactoryTest {
+    
+    @SuppressWarnings("rawtypes")
+    @Test
+    public void assertGetInstanceMap() {
+        FixtureGlobalRuleConfiguration configuration = new FixtureGlobalRuleConfiguration();
+        Map<RuleConfiguration, GlobalRuleBuilder> actual = GlobalRuleBuilderFactory.getInstanceMap(Collections.singletonList(configuration));
+        assertThat(actual.get(configuration), instanceOf(FixtureGlobalRuleBuilder.class));
+    }
+    
+    @SuppressWarnings("rawtypes")
+    @Test
+    public void assertGetInstancesWithoutAssignedGlobalRuleBuilderClasses() {
+        Collection<GlobalRuleBuilder> actual = GlobalRuleBuilderFactory.getInstances(Collections.emptyList());
+        assertThat(actual.size(), is(1));
+        assertThat(actual.iterator().next(), instanceOf(FixtureGlobalRuleBuilder.class));
+    }
+    
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    @Test
+    public void assertGetInstancesWithAssignedGlobalRuleBuilderClasses() {
+        List<GlobalRuleBuilder> configuredBuilders = new ArrayList<>(1);
+        FixtureGlobalRuleBuilder builder = mock(FixtureGlobalRuleBuilder.class);
+        configuredBuilders.add(builder);
+        Collection<Class<GlobalRuleBuilder>> configuredBuilderClasses = configuredBuilders.stream().map(each -> (Class<GlobalRuleBuilder>) each.getClass()).collect(Collectors.toSet());
+        Collection<GlobalRuleBuilder> actual = GlobalRuleBuilderFactory.getInstances(configuredBuilderClasses);
+        assertTrue(actual.isEmpty());
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
index 33424deed4d..c82c1c9d97a 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilderTest.java
@@ -23,15 +23,14 @@ import org.junit.Test;
 
 import java.util.Collections;
 
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 
 public final class GlobalRulesBuilderTest {
     
     @Test
-    public void assertBuildRulesWithoutGlobalRules() {
-        assertTrue(GlobalRulesBuilder.buildRules(Collections.singletonList(mock(RuleConfiguration.class)), Collections.singletonMap("logic_db", mock(ShardingSphereMetaData.class))).isEmpty());
+    public void assertBuildRulesWithGlobalRules() {
+        assertThat(GlobalRulesBuilder.buildRules(Collections.singletonList(mock(RuleConfiguration.class)), Collections.singletonMap("logic_db", mock(ShardingSphereMetaData.class))).size(), is(1));
     }
-    
-    // TODO add more test cases for BuildRulesWithGlobalRules
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/DefaultSchemaRuleConfigurationBuilderFactoryTest.java
similarity index 51%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/DefaultSchemaRuleConfigurationBuilderFactoryTest.java
index efd408b3851..8ab38699ee4 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/DefaultSchemaRuleConfigurationBuilderFactoryTest.java
@@ -17,28 +17,23 @@
 
 package org.apache.shardingsphere.infra.rule.builder.schema;
 
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.config.database.impl.DataSourceProvidedDatabaseConfiguration;
-import org.apache.shardingsphere.infra.fixture.TestRuleConfiguration;
-import org.apache.shardingsphere.infra.fixture.TestShardingSphereRule;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureSchemaRuleBuilder;
+import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureSchemaRuleConfigurationBuilder;
 import org.junit.Test;
 
-import java.util.Collection;
 import java.util.Collections;
-import java.util.Properties;
+import java.util.Map;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
-public final class SchemaRulesBuilderTest {
+public final class DefaultSchemaRuleConfigurationBuilderFactoryTest {
     
     @Test
-    public void assertBuild() {
-        Collection<ShardingSphereRule> actual = SchemaRulesBuilder.buildRules(
-                "schema_name", new DataSourceProvidedDatabaseConfiguration(Collections.emptyMap(), Collections.singleton(new TestRuleConfiguration())), new ConfigurationProperties(new Properties()));
-        assertThat(actual.size(), is(1));
-        assertThat(actual.iterator().next(), instanceOf(TestShardingSphereRule.class));
+    @SuppressWarnings("rawtypes")
+    public void assertGetInstances() {
+        FixtureSchemaRuleBuilder builder = new FixtureSchemaRuleBuilder();
+        Map<SchemaRuleBuilder, DefaultSchemaRuleConfigurationBuilder> actual = DefaultSchemaRuleConfigurationBuilderFactory.getInstances(Collections.singleton(builder));
+        assertThat(actual.get(builder), instanceOf(FixtureSchemaRuleConfigurationBuilder.class));
     }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRuleBuilderFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRuleBuilderFactoryTest.java
new file mode 100644
index 00000000000..a97b2bb8542
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRuleBuilderFactoryTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.infra.rule.builder.schema;
+
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.fixture.TestRuleConfiguration;
+import org.apache.shardingsphere.infra.fixture.TestShardingSphereRuleBuilder;
+import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureSchemaRuleBuilder;
+import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureSchemaRuleConfiguration;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class SchemaRuleBuilderFactoryTest {
+    
+    @SuppressWarnings("rawtypes")
+    @Test
+    public void assertGetInstances() {
+        Collection<SchemaRuleBuilder> actual = SchemaRuleBuilderFactory.getInstances();
+        assertThat(actual.size(), is(2));
+        Iterator<SchemaRuleBuilder> iterator = actual.iterator();
+        assertThat(iterator.next(), instanceOf(TestShardingSphereRuleBuilder.class));
+        assertThat(iterator.next(), instanceOf(FixtureSchemaRuleBuilder.class));
+    }
+    
+    @SuppressWarnings("rawtypes")
+    @Test
+    public void assertGetInstanceMap() {
+        FixtureSchemaRuleConfiguration configuration = new FixtureSchemaRuleConfiguration();
+        Map<RuleConfiguration, SchemaRuleBuilder> actual = SchemaRuleBuilderFactory.getInstanceMap(Collections.singleton(configuration));
+        assertThat(actual.get(configuration), instanceOf(FixtureSchemaRuleBuilder.class));
+    }
+    
+    @SuppressWarnings("rawtypes")
+    @Test
+    public void assertGetInstanceMapWithComparator() {
+        Collection<RuleConfiguration> ruleConfigs = new ArrayList<>(2);
+        ruleConfigs.add(new FixtureSchemaRuleConfiguration());
+        ruleConfigs.add(new TestRuleConfiguration());
+        Map<RuleConfiguration, SchemaRuleBuilder> actual = SchemaRuleBuilderFactory.getInstanceMap(ruleConfigs, Comparator.naturalOrder());
+        Iterator<RuleConfiguration> iterator = actual.keySet().iterator();
+        assertThat(iterator.next(), instanceOf(TestRuleConfiguration.class));
+        assertThat(iterator.next(), instanceOf(FixtureSchemaRuleConfiguration.class));
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java
index efd408b3851..a596b37b3a3 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/schema/SchemaRulesBuilderTest.java
@@ -22,10 +22,12 @@ import org.apache.shardingsphere.infra.config.database.impl.DataSourceProvidedDa
 import org.apache.shardingsphere.infra.fixture.TestRuleConfiguration;
 import org.apache.shardingsphere.infra.fixture.TestShardingSphereRule;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureSchemaRule;
 import org.junit.Test;
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
@@ -38,7 +40,9 @@ public final class SchemaRulesBuilderTest {
     public void assertBuild() {
         Collection<ShardingSphereRule> actual = SchemaRulesBuilder.buildRules(
                 "schema_name", new DataSourceProvidedDatabaseConfiguration(Collections.emptyMap(), Collections.singleton(new TestRuleConfiguration())), new ConfigurationProperties(new Properties()));
-        assertThat(actual.size(), is(1));
-        assertThat(actual.iterator().next(), instanceOf(TestShardingSphereRule.class));
+        assertThat(actual.size(), is(2));
+        Iterator<ShardingSphereRule> iterator = actual.iterator();
+        assertThat(iterator.next(), instanceOf(TestShardingSphereRule.class));
+        assertThat(iterator.next(), instanceOf(FixtureSchemaRule.class));
     }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.global.DefaultGlobalRuleConfigurationBuilder
similarity index 89%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder
copy to shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.global.DefaultGlobalRuleConfigurationBuilder
index d29ceb5811a..b1e8f37eefa 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.global.DefaultGlobalRuleConfigurationBuilder
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.shardingsphere.infra.fixture.TestShardingSphereRuleBuilder
+org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRuleConfigurationBuilder
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder
similarity index 90%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder
copy to shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder
index d29ceb5811a..e00b0c9f354 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.shardingsphere.infra.fixture.TestShardingSphereRuleBuilder
+org.apache.shardingsphere.infra.rule.builder.fixture.FixtureGlobalRuleBuilder
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.DefaultSchemaRuleConfigurationBuilder
similarity index 89%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder
copy to shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.DefaultSchemaRuleConfigurationBuilder
index d29ceb5811a..2ff4849d0b6 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.DefaultSchemaRuleConfigurationBuilder
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.shardingsphere.infra.fixture.TestShardingSphereRuleBuilder
+org.apache.shardingsphere.infra.rule.builder.fixture.FixtureSchemaRuleConfigurationBuilder
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder
index d29ceb5811a..440f5ced5d3 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.schema.SchemaRuleBuilder
@@ -16,3 +16,4 @@
 #
 
 org.apache.shardingsphere.infra.fixture.TestShardingSphereRuleBuilder
+org.apache.shardingsphere.infra.rule.builder.fixture.FixtureSchemaRuleBuilder