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 dca17d5b7ee Add DefaultRuleConfigurationBuilderTests (#37290)
dca17d5b7ee is described below

commit dca17d5b7ee5dea753fdd81cb88f116b95d1f94e
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Dec 7 13:25:24 2025 +0800

    Add DefaultRuleConfigurationBuilderTests (#37290)
    
    * Add DefaultRuleConfigurationBuilderTests
    
    * Add DefaultRuleConfigurationBuilderTests
    
    * Add DefaultRuleConfigurationBuilderTests
---
 ...faultAuthorityRuleConfigurationBuilderTest.java | 28 ++++++++++++++++++----
 ...ultGlobalClockRuleConfigurationBuilderTest.java |  6 ++---
 ...SQLFederationRuleConfigurationBuilderTest.java} | 22 ++++++++---------
 ...faultSQLParserRuleConfigurationBuilderTest.java | 28 ++++++++++------------
 ...SQLTranslatorRuleConfigurationBuilderTest.java} | 24 +++++++++----------
 ...ultTransactionRuleConfigurationBuilderTest.java | 12 ++++++++--
 6 files changed, 71 insertions(+), 49 deletions(-)

diff --git 
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/builder/DefaultAuthorityRuleConfigurationBuilderTest.java
 
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/builder/DefaultAuthorityRuleConfigurationBuilderTest.java
index efb733b3582..e26082f62f1 100644
--- 
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/builder/DefaultAuthorityRuleConfigurationBuilderTest.java
+++ 
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/builder/DefaultAuthorityRuleConfigurationBuilderTest.java
@@ -18,21 +18,41 @@
 package org.apache.shardingsphere.authority.rule.builder;
 
 import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
+import org.apache.shardingsphere.authority.config.UserConfiguration;
+import 
org.apache.shardingsphere.infra.rule.builder.global.DefaultGlobalRuleConfigurationBuilder;
+import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder;
+import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
 import org.junit.jupiter.api.Test;
 
-import static org.hamcrest.CoreMatchers.is;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Properties;
+
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 class DefaultAuthorityRuleConfigurationBuilderTest {
     
+    @SuppressWarnings("rawtypes")
     @Test
     void assertBuild() {
-        AuthorityRuleConfiguration actual = new 
DefaultAuthorityRuleConfigurationBuilder().build();
+        Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> builders 
= OrderedSPILoader.getServices(
+                DefaultGlobalRuleConfigurationBuilder.class, 
Collections.singleton(new AuthorityRuleBuilder()));
+        AuthorityRuleConfiguration actual = (AuthorityRuleConfiguration) 
builders.values().iterator().next().build();
+        Collection<UserConfiguration> users = actual.getUsers();
+        assertThat(users.size(), is(1));
+        UserConfiguration user = users.iterator().next();
+        assertThat(user.getUsername(), is(DefaultUser.USERNAME));
+        assertThat(user.getPassword(), is(DefaultUser.PASSWORD));
+        assertThat(user.getHostname(), is(DefaultUser.HOSTNAME));
+        assertThat(user.getAuthenticationMethodName(), is(""));
+        assertTrue(user.isAdmin());
         assertThat(actual.getPrivilegeProvider().getType(), 
is("ALL_PERMITTED"));
-        assertThat(actual.getUsers().size(), is(1));
-        assertNull(actual.getDefaultAuthenticator());
+        assertThat(actual.getPrivilegeProvider().getProps(), is(new 
Properties()));
         assertTrue(actual.getAuthenticators().isEmpty());
+        assertNull(actual.getDefaultAuthenticator());
     }
 }
diff --git 
a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/DefaultGlobalClockRuleConfigurationBuilderTest.java
 
b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/DefaultGlobalClockRuleConfigurationBuilderTest.java
index 62f5dcadae1..28050a43dc7 100644
--- 
a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/DefaultGlobalClockRuleConfigurationBuilderTest.java
+++ 
b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/DefaultGlobalClockRuleConfigurationBuilderTest.java
@@ -36,9 +36,9 @@ class DefaultGlobalClockRuleConfigurationBuilderTest {
     @SuppressWarnings("rawtypes")
     @Test
     void assertBuild() {
-        GlobalClockRuleBuilder builder = new GlobalClockRuleBuilder();
-        Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> builders 
= OrderedSPILoader.getServices(DefaultGlobalRuleConfigurationBuilder.class, 
Collections.singleton(builder));
-        GlobalClockRuleConfiguration actual = (GlobalClockRuleConfiguration) 
builders.get(builder).build();
+        Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> builders 
= OrderedSPILoader.getServices(
+                DefaultGlobalRuleConfigurationBuilder.class, 
Collections.singleton(new GlobalClockRuleBuilder()));
+        GlobalClockRuleConfiguration actual = (GlobalClockRuleConfiguration) 
builders.values().iterator().next().build();
         assertThat(actual.getType(), is("TSO"));
         assertThat(actual.getProvider(), is("local"));
         assertFalse(actual.isEnabled());
diff --git 
a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/DefaultGlobalClockRuleConfigurationBuilderTest.java
 
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/rule/builder/DefaultSQLFederationRuleConfigurationBuilderTest.java
similarity index 63%
copy from 
kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/DefaultGlobalClockRuleConfigurationBuilderTest.java
copy to 
kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/rule/builder/DefaultSQLFederationRuleConfigurationBuilderTest.java
index 62f5dcadae1..c033a4522b5 100644
--- 
a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/DefaultGlobalClockRuleConfigurationBuilderTest.java
+++ 
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/rule/builder/DefaultSQLFederationRuleConfigurationBuilderTest.java
@@ -15,33 +15,31 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.globalclock.rule.builder;
+package org.apache.shardingsphere.sqlfederation.rule.builder;
 
-import 
org.apache.shardingsphere.globalclock.config.GlobalClockRuleConfiguration;
 import 
org.apache.shardingsphere.infra.rule.builder.global.DefaultGlobalRuleConfigurationBuilder;
 import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder;
 import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
+import 
org.apache.shardingsphere.sqlfederation.config.SQLFederationRuleConfiguration;
 import org.junit.jupiter.api.Test;
 
 import java.util.Collections;
 import java.util.Map;
 
-import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
 import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
 
-class DefaultGlobalClockRuleConfigurationBuilderTest {
+class DefaultSQLFederationRuleConfigurationBuilderTest {
     
     @SuppressWarnings("rawtypes")
     @Test
     void assertBuild() {
-        GlobalClockRuleBuilder builder = new GlobalClockRuleBuilder();
-        Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> builders 
= OrderedSPILoader.getServices(DefaultGlobalRuleConfigurationBuilder.class, 
Collections.singleton(builder));
-        GlobalClockRuleConfiguration actual = (GlobalClockRuleConfiguration) 
builders.get(builder).build();
-        assertThat(actual.getType(), is("TSO"));
-        assertThat(actual.getProvider(), is("local"));
-        assertFalse(actual.isEnabled());
-        assertTrue(actual.getProps().isEmpty());
+        Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> builders 
= OrderedSPILoader.getServices(
+                DefaultGlobalRuleConfigurationBuilder.class, 
Collections.singleton(new SQLFederationRuleBuilder()));
+        SQLFederationRuleConfiguration actual = 
(SQLFederationRuleConfiguration) builders.values().iterator().next().build();
+        assertFalse(actual.isSqlFederationEnabled());
+        assertFalse(actual.isAllQueryUseSQLFederation());
+        assertThat(actual.getExecutionPlanCache(), 
is(DefaultSQLFederationRuleConfigurationBuilder.DEFAULT_EXECUTION_PLAN_CACHE_OPTION));
     }
 }
diff --git 
a/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/rule/builder/DefaultSQLParserRuleConfigurationBuilderTest.java
 
b/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/rule/builder/DefaultSQLParserRuleConfigurationBuilderTest.java
index 28d1194f551..6d17e109d33 100644
--- 
a/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/rule/builder/DefaultSQLParserRuleConfigurationBuilderTest.java
+++ 
b/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/rule/builder/DefaultSQLParserRuleConfigurationBuilderTest.java
@@ -17,31 +17,27 @@
 
 package org.apache.shardingsphere.parser.rule.builder;
 
+import 
org.apache.shardingsphere.infra.rule.builder.global.DefaultGlobalRuleConfigurationBuilder;
+import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder;
+import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
 import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
-import org.apache.shardingsphere.parser.constant.SQLParserOrder;
 import org.junit.jupiter.api.Test;
 
+import java.util.Collections;
+import java.util.Map;
+
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 
 class DefaultSQLParserRuleConfigurationBuilderTest {
     
+    @SuppressWarnings("rawtypes")
     @Test
     void assertBuild() {
-        SQLParserRuleConfiguration actual = new 
DefaultSQLParserRuleConfigurationBuilder().build();
-        assertThat(actual.getParseTreeCache().getInitialCapacity(), is(128));
-        assertThat(actual.getParseTreeCache().getMaximumSize(), is(1024L));
-        assertThat(actual.getSqlStatementCache().getInitialCapacity(), 
is(2000));
-        assertThat(actual.getSqlStatementCache().getMaximumSize(), is(65535L));
-    }
-    
-    @Test
-    void assertGetOrder() {
-        assertThat(new DefaultSQLParserRuleConfigurationBuilder().getOrder(), 
is(SQLParserOrder.ORDER));
-    }
-    
-    @Test
-    void assertGetTypeClass() {
-        assertThat(new 
DefaultSQLParserRuleConfigurationBuilder().getTypeClass().toString(), 
is(SQLParserRuleBuilder.class.toString()));
+        Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> builders 
= OrderedSPILoader.getServices(
+                DefaultGlobalRuleConfigurationBuilder.class, 
Collections.singleton(new SQLParserRuleBuilder()));
+        SQLParserRuleConfiguration actual = (SQLParserRuleConfiguration) 
builders.values().iterator().next().build();
+        assertThat(actual.getParseTreeCache(), 
is(DefaultSQLParserRuleConfigurationBuilder.PARSE_TREE_CACHE_OPTION));
+        assertThat(actual.getSqlStatementCache(), 
is(DefaultSQLParserRuleConfigurationBuilder.SQL_STATEMENT_CACHE_OPTION));
     }
 }
diff --git 
a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/DefaultGlobalClockRuleConfigurationBuilderTest.java
 
b/kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/rule/builder/DefaultSQLTranslatorRuleConfigurationBuilderTest.java
similarity index 63%
copy from 
kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/DefaultGlobalClockRuleConfigurationBuilderTest.java
copy to 
kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/rule/builder/DefaultSQLTranslatorRuleConfigurationBuilderTest.java
index 62f5dcadae1..ad2eb3e7e74 100644
--- 
a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/DefaultGlobalClockRuleConfigurationBuilderTest.java
+++ 
b/kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/rule/builder/DefaultSQLTranslatorRuleConfigurationBuilderTest.java
@@ -15,33 +15,33 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.globalclock.rule.builder;
+package org.apache.shardingsphere.sqltranslator.rule.builder;
 
-import 
org.apache.shardingsphere.globalclock.config.GlobalClockRuleConfiguration;
 import 
org.apache.shardingsphere.infra.rule.builder.global.DefaultGlobalRuleConfigurationBuilder;
 import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder;
 import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
+import 
org.apache.shardingsphere.sqltranslator.config.SQLTranslatorRuleConfiguration;
 import org.junit.jupiter.api.Test;
 
 import java.util.Collections;
 import java.util.Map;
+import java.util.Properties;
 
-import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-class DefaultGlobalClockRuleConfigurationBuilderTest {
+class DefaultSQLTranslatorRuleConfigurationBuilderTest {
     
     @SuppressWarnings("rawtypes")
     @Test
     void assertBuild() {
-        GlobalClockRuleBuilder builder = new GlobalClockRuleBuilder();
-        Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> builders 
= OrderedSPILoader.getServices(DefaultGlobalRuleConfigurationBuilder.class, 
Collections.singleton(builder));
-        GlobalClockRuleConfiguration actual = (GlobalClockRuleConfiguration) 
builders.get(builder).build();
-        assertThat(actual.getType(), is("TSO"));
-        assertThat(actual.getProvider(), is("local"));
-        assertFalse(actual.isEnabled());
-        assertTrue(actual.getProps().isEmpty());
+        Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> builders 
= OrderedSPILoader.getServices(
+                DefaultGlobalRuleConfigurationBuilder.class, 
Collections.singleton(new SQLTranslatorRuleBuilder()));
+        SQLTranslatorRuleConfiguration actual = 
(SQLTranslatorRuleConfiguration) builders.values().iterator().next().build();
+        assertNull(actual.getType());
+        assertThat(actual.getProps(), is(new Properties()));
+        assertTrue(actual.isUseOriginalSQLWhenTranslatingFailed());
     }
 }
diff --git 
a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/DefaultTransactionRuleConfigurationBuilderTest.java
 
b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/DefaultTransactionRuleConfigurationBuilderTest.java
index ab406a3fb57..2333a5b874a 100644
--- 
a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/DefaultTransactionRuleConfigurationBuilderTest.java
+++ 
b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/DefaultTransactionRuleConfigurationBuilderTest.java
@@ -17,10 +17,15 @@
 
 package org.apache.shardingsphere.transaction.rule.builder;
 
-import 
org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
+import 
org.apache.shardingsphere.infra.rule.builder.global.DefaultGlobalRuleConfigurationBuilder;
+import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder;
+import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
 import org.apache.shardingsphere.transaction.api.TransactionType;
+import 
org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
 import org.junit.jupiter.api.Test;
 
+import java.util.Collections;
+import java.util.Map;
 import java.util.Properties;
 
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -29,9 +34,12 @@ import static org.junit.jupiter.api.Assertions.assertNull;
 
 class DefaultTransactionRuleConfigurationBuilderTest {
     
+    @SuppressWarnings("rawtypes")
     @Test
     void assertBuild() {
-        TransactionRuleConfiguration actual = new 
DefaultTransactionRuleConfigurationBuilder().build();
+        Map<GlobalRuleBuilder, DefaultGlobalRuleConfigurationBuilder> builders 
= OrderedSPILoader.getServices(
+                DefaultGlobalRuleConfigurationBuilder.class, 
Collections.singleton(new TransactionRuleBuilder()));
+        TransactionRuleConfiguration actual = (TransactionRuleConfiguration) 
builders.values().iterator().next().build();
         assertThat(actual.getDefaultType(), is(TransactionType.LOCAL.name()));
         assertNull(actual.getProviderType());
         assertThat(actual.getProps(), is(new Properties()));

Reply via email to