You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2023/06/01 13:51:37 UTC

[shardingsphere] branch master updated: Fix sonar issue on Replace tests with a single Parameterized one (#25995)

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

panjuan 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 5d875955f01 Fix sonar issue on Replace tests with a single Parameterized one (#25995)
5d875955f01 is described below

commit 5d875955f013604e0a064a06eb19903391264944
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Jun 1 21:51:29 2023 +0800

    Fix sonar issue on Replace tests with a single Parameterized one (#25995)
---
 .../integer/MySQLBitBinlogProtocolValueTest.java   |  48 ++++---
 .../PostgreSQLCommandCompletePacketTest.java       |  48 +++----
 .../encrypt/rule/EncryptRuleTest.java              |  54 ++++----
 .../common/IteratorStreamMergedResultTest.java     |  51 ++++----
 .../ddl/fetch/FetchStreamMergedResultTest.java     | 100 ++++++---------
 .../route/engine/type/standard/SQLRouteTest.java   |  55 ++++----
 .../engine/type/standard/SubqueryRouteTest.java    | 132 +++++++------------
 .../metadata/dialect/H2DataSourceMetaDataTest.java | 142 +++++++--------------
 8 files changed, 253 insertions(+), 377 deletions(-)

diff --git a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/integer/MySQLBitBinlogProtocolValueTest.java b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/integer/MySQLBitBinlogProtocolValueTest.java
index f0d03380970..877f8a7ffe6 100644
--- a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/integer/MySQLBitBinlogProtocolValueTest.java
+++ b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/integer/MySQLBitBinlogProtocolValueTest.java
@@ -20,11 +20,17 @@ package org.apache.shardingsphere.db.protocol.mysql.packet.binlog.row.column.val
 import org.apache.shardingsphere.db.protocol.mysql.packet.binlog.row.column.MySQLBinlogColumnDef;
 import org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 
+import java.util.stream.Stream;
+
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.when;
@@ -45,31 +51,23 @@ class MySQLBitBinlogProtocolValueTest {
         actual = new MySQLBitBinlogProtocolValue();
     }
     
-    @Test
-    void assertReadWithLength1() {
-        when(columnDef.getColumnMeta()).thenReturn(1);
-        when(payload.readLong(1)).thenReturn(1L);
-        assertThat(actual.read(columnDef, payload), is(1L));
-    }
-    
-    @Test
-    void assertReadWithLength3() {
-        when(columnDef.getColumnMeta()).thenReturn(516);
-        when(payload.readLong(3)).thenReturn(1L);
-        assertThat(actual.read(columnDef, payload), is(1L));
-    }
-    
-    @Test
-    void assertReadWithLength5() {
-        when(columnDef.getColumnMeta()).thenReturn(1280);
-        when(payload.readLong(5)).thenReturn(1L);
-        assertThat(actual.read(columnDef, payload), is(1L));
+    @ParameterizedTest(name = "withLength{1}")
+    @ArgumentsSource(TestCaseArgumentsProvider.class)
+    void assertRead(final int columnMeta, final int length, final long expected) {
+        when(columnDef.getColumnMeta()).thenReturn(columnMeta);
+        when(payload.readLong(length)).thenReturn(expected);
+        assertThat(actual.read(columnDef, payload), is(expected));
     }
     
-    @Test
-    void assertReadWithLength8() {
-        when(columnDef.getColumnMeta()).thenReturn(2048);
-        when(payload.readLong(8)).thenReturn(-1L);
-        assertThat(actual.read(columnDef, payload), is(-1L));
+    private static class TestCaseArgumentsProvider implements ArgumentsProvider {
+        
+        @Override
+        public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+            return Stream.of(
+                    Arguments.of(1, 1, 1L),
+                    Arguments.of(516, 3, 1L),
+                    Arguments.of(1280, 5, 1L),
+                    Arguments.of(2048, 8, -1L));
+        }
     }
 }
diff --git a/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacketTest.java b/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacketTest.java
index 7b91ab276ac..ae5ee3629f1 100644
--- a/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacketTest.java
+++ b/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacketTest.java
@@ -20,20 +20,25 @@ package org.apache.shardingsphere.db.protocol.postgresql.packet.generic;
 import org.apache.shardingsphere.db.protocol.postgresql.packet.ByteBufTestUtils;
 import org.apache.shardingsphere.db.protocol.postgresql.packet.identifier.PostgreSQLMessagePacketType;
 import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
 
 import java.nio.charset.StandardCharsets;
+import java.util.stream.Stream;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 
 class PostgreSQLCommandCompletePacketTest {
     
-    @Test
-    void assertSelectReadWrite() {
-        String sqlCommand = "SELECT";
+    @ParameterizedTest(name = "{0}")
+    @ArgumentsSource(TestCaseArgumentsProvider.class)
+    void assertReadWrite(final String sqlCommand, final String expectedDelimiter) {
         long rowCount = 1;
-        String expectedString = sqlCommand + " " + rowCount;
+        String expectedString = sqlCommand + expectedDelimiter + rowCount;
         int expectedStringLength = expectedString.length();
         PostgreSQLPacketPayload payload = new PostgreSQLPacketPayload(ByteBufTestUtils.createByteBuf(expectedStringLength + 1), StandardCharsets.ISO_8859_1);
         PostgreSQLCommandCompletePacket packet = new PostgreSQLCommandCompletePacket(sqlCommand, rowCount);
@@ -42,29 +47,14 @@ class PostgreSQLCommandCompletePacketTest {
         assertThat(payload.readStringNul(), is(expectedString));
     }
     
-    @Test
-    void assertInsertReadWrite() {
-        String sqlCommand = "INSERT";
-        long rowCount = 1;
-        String expectedString = sqlCommand + " 0 " + rowCount;
-        int expectedStringLength = expectedString.length();
-        PostgreSQLPacketPayload payload = new PostgreSQLPacketPayload(ByteBufTestUtils.createByteBuf(expectedStringLength + 1), StandardCharsets.ISO_8859_1);
-        PostgreSQLCommandCompletePacket packet = new PostgreSQLCommandCompletePacket(sqlCommand, rowCount);
-        assertThat(packet.getIdentifier(), is(PostgreSQLMessagePacketType.COMMAND_COMPLETE));
-        packet.write(payload);
-        assertThat(payload.readStringNul(), is(expectedString));
-    }
-    
-    @Test
-    void assertMoveReadWrite() {
-        String sqlCommand = "MOVE";
-        long rowCount = 1;
-        String expectedString = sqlCommand + " " + rowCount;
-        int expectedStringLength = expectedString.length();
-        PostgreSQLPacketPayload payload = new PostgreSQLPacketPayload(ByteBufTestUtils.createByteBuf(expectedStringLength + 1), StandardCharsets.ISO_8859_1);
-        PostgreSQLCommandCompletePacket packet = new PostgreSQLCommandCompletePacket(sqlCommand, rowCount);
-        assertThat(packet.getIdentifier(), is(PostgreSQLMessagePacketType.COMMAND_COMPLETE));
-        packet.write(payload);
-        assertThat(payload.readStringNul(), is(expectedString));
+    private static class TestCaseArgumentsProvider implements ArgumentsProvider {
+        
+        @Override
+        public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+            return Stream.of(
+                    Arguments.of("SELECT", " "),
+                    Arguments.of("INSERT", " 0 "),
+                    Arguments.of("MOVE", " "));
+        }
     }
 }
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
index cf35beb090f..055228dc9a7 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
@@ -25,6 +25,11 @@ import org.apache.shardingsphere.encrypt.exception.algorithm.MismatchedEncryptAl
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.database.DefaultDatabase;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -33,6 +38,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.stream.Stream;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -134,9 +140,7 @@ class EncryptRuleTest {
     }
     
     private EncryptRuleConfiguration createEncryptRuleConfiguration() {
-        EncryptColumnRuleConfiguration pwdColumnConfig = new EncryptColumnRuleConfiguration("pwd", new EncryptColumnItemRuleConfiguration("pwd_cipher", "standard_encryptor"));
-        pwdColumnConfig.setAssistedQuery(new EncryptColumnItemRuleConfiguration("pwd_assist", "assisted_encryptor"));
-        pwdColumnConfig.setLikeQuery(new EncryptColumnItemRuleConfiguration("pwd_like", "like_encryptor"));
+        EncryptColumnRuleConfiguration pwdColumnConfig = createEncryptColumnRuleConfiguration("standard_encryptor", "assisted_encryptor", "like_encryptor");
         EncryptColumnRuleConfiguration creditCardColumnConfig = new EncryptColumnRuleConfiguration("credit_card", new EncryptColumnItemRuleConfiguration("credit_card_cipher", "standard_encryptor"));
         EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration("t_encrypt", Arrays.asList(pwdColumnConfig, creditCardColumnConfig));
         return new EncryptRuleConfiguration(Collections.singleton(tableConfig), getEncryptors(new AlgorithmConfiguration("CORE.FIXTURE", new Properties()),
@@ -180,11 +184,11 @@ class EncryptRuleTest {
         return result;
     }
     
-    @Test
-    void assertNewEncryptRuleWhenConfigWrongCipherEncryptorType() {
-        EncryptColumnRuleConfiguration pwdColumnConfig = new EncryptColumnRuleConfiguration("pwd", new EncryptColumnItemRuleConfiguration("pwd_cipher", "assisted_encryptor"));
-        pwdColumnConfig.setAssistedQuery(new EncryptColumnItemRuleConfiguration("pwd_assist", "assisted_encryptor"));
-        pwdColumnConfig.setLikeQuery(new EncryptColumnItemRuleConfiguration("pwd_like", "like_encryptor"));
+    @SuppressWarnings("unused")
+    @ParameterizedTest(name = "Wrong{0}")
+    @ArgumentsSource(TestCaseArgumentsProvider.class)
+    void assertNewEncryptRuleWhenConfigureWrongEncryptorType(final String name, final String encryptorName, final String assistedQueryEncryptorName, final String likeEncryptorName) {
+        EncryptColumnRuleConfiguration pwdColumnConfig = createEncryptColumnRuleConfiguration(encryptorName, assistedQueryEncryptorName, likeEncryptorName);
         EncryptColumnRuleConfiguration creditCardColumnConfig = new EncryptColumnRuleConfiguration("credit_card", new EncryptColumnItemRuleConfiguration("credit_card_cipher", "standard_encryptor"));
         EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration("t_encrypt", Arrays.asList(pwdColumnConfig, creditCardColumnConfig));
         EncryptRuleConfiguration ruleConfig = new EncryptRuleConfiguration(Collections.singleton(tableConfig), getEncryptors(new AlgorithmConfiguration("CORE.FIXTURE", new Properties()),
@@ -192,27 +196,21 @@ class EncryptRuleTest {
         assertThrows(MismatchedEncryptAlgorithmTypeException.class, () -> new EncryptRule(ruleConfig));
     }
     
-    @Test
-    void assertNewEncryptRuleWhenConfigWrongAssistedQueryEncryptorType() {
-        EncryptColumnRuleConfiguration pwdColumnConfig = new EncryptColumnRuleConfiguration("pwd", new EncryptColumnItemRuleConfiguration("pwd_cipher", "standard_encryptor"));
-        pwdColumnConfig.setAssistedQuery(new EncryptColumnItemRuleConfiguration("pwd_assist", "like_encryptor"));
-        pwdColumnConfig.setLikeQuery(new EncryptColumnItemRuleConfiguration("pwd_like", "like_encryptor"));
-        EncryptColumnRuleConfiguration creditCardColumnConfig = new EncryptColumnRuleConfiguration("credit_card", new EncryptColumnItemRuleConfiguration("credit_card_cipher", "standard_encryptor"));
-        EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration("t_encrypt", Arrays.asList(pwdColumnConfig, creditCardColumnConfig));
-        EncryptRuleConfiguration ruleConfig = new EncryptRuleConfiguration(Collections.singleton(tableConfig), getEncryptors(new AlgorithmConfiguration("CORE.FIXTURE", new Properties()),
-                new AlgorithmConfiguration("CORE.QUERY_ASSISTED.FIXTURE", new Properties()), new AlgorithmConfiguration("CORE.QUERY_LIKE.FIXTURE", new Properties())));
-        assertThrows(MismatchedEncryptAlgorithmTypeException.class, () -> new EncryptRule(ruleConfig));
+    private static EncryptColumnRuleConfiguration createEncryptColumnRuleConfiguration(final String encryptorName, final String assistedQueryEncryptorName, final String likeEncryptorName) {
+        EncryptColumnRuleConfiguration result = new EncryptColumnRuleConfiguration("pwd", new EncryptColumnItemRuleConfiguration("pwd_cipher", encryptorName));
+        result.setAssistedQuery(new EncryptColumnItemRuleConfiguration("pwd_assist", assistedQueryEncryptorName));
+        result.setLikeQuery(new EncryptColumnItemRuleConfiguration("pwd_like", likeEncryptorName));
+        return result;
     }
     
-    @Test
-    void assertNewEncryptRuleWhenConfigWrongLikeQueryEncryptorType() {
-        EncryptColumnRuleConfiguration pwdColumnConfig = new EncryptColumnRuleConfiguration("pwd", new EncryptColumnItemRuleConfiguration("pwd_cipher", "standard_encryptor"));
-        pwdColumnConfig.setAssistedQuery(new EncryptColumnItemRuleConfiguration("pwd_assist", "assisted_encryptor"));
-        pwdColumnConfig.setLikeQuery(new EncryptColumnItemRuleConfiguration("pwd_like", "standard_encryptor"));
-        EncryptColumnRuleConfiguration creditCardColumnConfig = new EncryptColumnRuleConfiguration("credit_card", new EncryptColumnItemRuleConfiguration("credit_card_cipher", "standard_encryptor"));
-        EncryptTableRuleConfiguration tableConfig = new EncryptTableRuleConfiguration("t_encrypt", Arrays.asList(pwdColumnConfig, creditCardColumnConfig));
-        EncryptRuleConfiguration ruleConfig = new EncryptRuleConfiguration(Collections.singleton(tableConfig), getEncryptors(new AlgorithmConfiguration("CORE.FIXTURE", new Properties()),
-                new AlgorithmConfiguration("CORE.QUERY_ASSISTED.FIXTURE", new Properties()), new AlgorithmConfiguration("CORE.QUERY_LIKE.FIXTURE", new Properties())));
-        assertThrows(MismatchedEncryptAlgorithmTypeException.class, () -> new EncryptRule(ruleConfig));
+    private static class TestCaseArgumentsProvider implements ArgumentsProvider {
+        
+        @Override
+        public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+            return Stream.of(
+                    Arguments.of("Encryptor", "assisted_encryptor", "assisted_encryptor", "like_encryptor"),
+                    Arguments.of("AssistedQueryEncryptor", "standard_encryptor", "like_encryptor", "like_encryptor"),
+                    Arguments.of("LikeEncryptor", "standard_encryptor", "assisted_encryptor", "standard_encryptor"));
+        }
     }
 }
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/common/IteratorStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/common/IteratorStreamMergedResultTest.java
index 5506f5a67a5..7c9862ce331 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/common/IteratorStreamMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/common/IteratorStreamMergedResultTest.java
@@ -33,11 +33,17 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.Projecti
 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
 
 import java.sql.SQLException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.stream.Stream;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -54,8 +60,7 @@ class IteratorStreamMergedResultTest {
         MySQLSelectStatement selectStatement = new MySQLSelectStatement();
         ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
         selectStatement.setProjections(new ProjectionsSegment(0, 0));
-        selectStatementContext = new SelectStatementContext(
-                createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
+        selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME);
     }
     
     private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
@@ -88,34 +93,11 @@ class IteratorStreamMergedResultTest {
         assertFalse(actual.next());
     }
     
-    @Test
-    void assertNextForFirstResultSetsNotEmptyOnly() throws SQLException {
+    @ParameterizedTest(name = "{0}")
+    @ArgumentsSource(TestCaseArgumentsProvider.class)
+    void assertNextForNotEmpty(final String name, final int index) throws SQLException {
         List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
-        when(queryResults.get(0).next()).thenReturn(true, false);
-        ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPILoader.getService(DatabaseType.class, "MySQL"));
-        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
-        when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
-        MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, database, mock(ConnectionContext.class));
-        assertTrue(actual.next());
-        assertFalse(actual.next());
-    }
-    
-    @Test
-    void assertNextForMiddleResultSetsNotEmpty() throws SQLException {
-        List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
-        when(queryResults.get(1).next()).thenReturn(true, false);
-        ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPILoader.getService(DatabaseType.class, "MySQL"));
-        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
-        when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
-        MergedResult actual = resultMerger.merge(queryResults, selectStatementContext, database, mock(ConnectionContext.class));
-        assertTrue(actual.next());
-        assertFalse(actual.next());
-    }
-    
-    @Test
-    void assertNextForLastResultSetsNotEmptyOnly() throws SQLException {
-        List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
-        when(queryResults.get(2).next()).thenReturn(true, false);
+        when(queryResults.get(index).next()).thenReturn(true, false);
         ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPILoader.getService(DatabaseType.class, "MySQL"));
         ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
         when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
@@ -140,4 +122,15 @@ class IteratorStreamMergedResultTest {
         assertTrue(actual.next());
         assertFalse(actual.next());
     }
+    
+    private static class TestCaseArgumentsProvider implements ArgumentsProvider {
+        
+        @Override
+        public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+            return Stream.of(
+                    Arguments.of("first", 0),
+                    Arguments.of("middle", 1),
+                    Arguments.of("last", 2));
+        }
+    }
 }
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java
index 475db4140c3..beff8848465 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java
@@ -20,14 +20,14 @@ package org.apache.shardingsphere.sharding.merge.ddl.fetch;
 import org.apache.shardingsphere.infra.binder.statement.ddl.CursorStatementContext;
 import org.apache.shardingsphere.infra.binder.statement.ddl.FetchStatementContext;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
-import org.apache.shardingsphere.infra.session.connection.cursor.CursorConnectionContext;
 import org.apache.shardingsphere.infra.database.DefaultDatabase;
 import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
 import org.apache.shardingsphere.infra.merge.result.MergedResult;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
+import org.apache.shardingsphere.infra.session.connection.cursor.CursorConnectionContext;
 import org.apache.shardingsphere.sharding.merge.ddl.ShardingDDLResultMerger;
 import org.apache.shardingsphere.sql.parser.sql.common.enums.DirectionType;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.cursor.CursorNameSegment;
@@ -35,17 +35,25 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.cursor.Direct
 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.FetchStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
 import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCursorStatement;
 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussFetchStatement;
 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.dml.OpenGaussSelectStatement;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
 
 import java.sql.SQLException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.stream.Stream;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -67,10 +75,8 @@ class FetchStreamMergedResultTest {
     
     @BeforeEach
     void setUp() {
-        fetchCountStatementContext = new FetchStatementContext(createFetchStatement(false));
-        fetchCountStatementContext.setUpCursorDefinition(createCursorStatementContext());
-        fetchAllStatementContext = new FetchStatementContext(createFetchStatement(true));
-        fetchAllStatementContext.setUpCursorDefinition(createCursorStatementContext());
+        fetchCountStatementContext = createFetchStatementContext(false);
+        fetchAllStatementContext = createFetchStatementContext(true);
         resultMerger = new ShardingDDLResultMerger();
         database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
         when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
@@ -78,8 +84,14 @@ class FetchStreamMergedResultTest {
         when(connectionContext.getCursorContext()).thenReturn(new CursorConnectionContext());
     }
     
-    private OpenGaussFetchStatement createFetchStatement(final boolean containsAllDirectionType) {
-        OpenGaussFetchStatement result = new OpenGaussFetchStatement();
+    private static FetchStatementContext createFetchStatementContext(final boolean containsAllDirectionType) {
+        FetchStatementContext result = new FetchStatementContext(createFetchStatement(containsAllDirectionType));
+        result.setUpCursorDefinition(createCursorStatementContext());
+        return result;
+    }
+    
+    private static FetchStatement createFetchStatement(final boolean containsAllDirectionType) {
+        FetchStatement result = new OpenGaussFetchStatement();
         result.setCursorName(new CursorNameSegment(0, 0, new IdentifierValue("t_order_cursor")));
         if (containsAllDirectionType) {
             DirectionSegment direction = new DirectionSegment(0, 0);
@@ -89,7 +101,7 @@ class FetchStreamMergedResultTest {
         return result;
     }
     
-    private CursorStatementContext createCursorStatementContext() {
+    private static CursorStatementContext createCursorStatementContext() {
         ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
         when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
         OpenGaussCursorStatement cursorStatement = new OpenGaussCursorStatement();
@@ -97,12 +109,12 @@ class FetchStreamMergedResultTest {
         return new CursorStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), cursorStatement, DefaultDatabase.LOGIC_NAME);
     }
     
-    private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
+    private static ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
         return new ShardingSphereMetaData(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ShardingSphereRuleMetaData.class), mock(ConfigurationProperties.class));
     }
     
-    private OpenGaussSelectStatement createSelectStatement() {
-        OpenGaussSelectStatement result = new OpenGaussSelectStatement();
+    private static SelectStatement createSelectStatement() {
+        SelectStatement result = new OpenGaussSelectStatement();
         result.setProjections(new ProjectionsSegment(0, 0));
         result.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
         return result;
@@ -148,57 +160,27 @@ class FetchStreamMergedResultTest {
         assertFalse(actual.next());
     }
     
-    @Test
-    void assertNextForFirstResultSetsNotEmptyOnly() throws SQLException {
-        List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
-        when(queryResults.get(0).next()).thenReturn(true, false);
-        MergedResult actual = resultMerger.merge(queryResults, fetchCountStatementContext, database, connectionContext);
-        assertTrue(actual.next());
-        assertFalse(actual.next());
-    }
-    
-    @Test
-    void assertNextForFirstResultSetsNotEmptyOnlyWhenConfigAllDirectionType() throws SQLException {
+    @ParameterizedTest(name = "{0}")
+    @ArgumentsSource(TestCaseArgumentsProvider.class)
+    void assertNextForNotEmpty(final String name, final int index, final FetchStatementContext fetchStatementContext) throws SQLException {
         List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
-        when(queryResults.get(0).next()).thenReturn(true, false);
-        MergedResult actual = resultMerger.merge(queryResults, fetchAllStatementContext, database, connectionContext);
+        when(queryResults.get(index).next()).thenReturn(true, false);
+        MergedResult actual = resultMerger.merge(queryResults, fetchStatementContext, database, connectionContext);
         assertTrue(actual.next());
         assertFalse(actual.next());
     }
     
-    @Test
-    void assertNextForMiddleResultSetsNotEmpty() throws SQLException {
-        List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
-        when(queryResults.get(1).next()).thenReturn(true, false);
-        MergedResult actual = resultMerger.merge(queryResults, fetchCountStatementContext, database, connectionContext);
-        assertTrue(actual.next());
-        assertFalse(actual.next());
-    }
-    
-    @Test
-    void assertNextForMiddleResultSetsNotEmptyWhenConfigAllDirectionType() throws SQLException {
-        List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
-        when(queryResults.get(1).next()).thenReturn(true, false);
-        MergedResult actual = resultMerger.merge(queryResults, fetchAllStatementContext, database, connectionContext);
-        assertTrue(actual.next());
-        assertFalse(actual.next());
-    }
-    
-    @Test
-    void assertNextForLastResultSetsNotEmptyOnly() throws SQLException {
-        List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
-        when(queryResults.get(2).next()).thenReturn(true, false);
-        MergedResult actual = resultMerger.merge(queryResults, fetchCountStatementContext, database, connectionContext);
-        assertTrue(actual.next());
-        assertFalse(actual.next());
-    }
-    
-    @Test
-    void assertNextForLastResultSetsNotEmptyOnlyWhenConfigAllDirectionType() throws SQLException {
-        List<QueryResult> queryResults = Arrays.asList(mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS), mock(QueryResult.class, RETURNS_DEEP_STUBS));
-        when(queryResults.get(2).next()).thenReturn(true, false);
-        MergedResult actual = resultMerger.merge(queryResults, fetchAllStatementContext, database, connectionContext);
-        assertTrue(actual.next());
-        assertFalse(actual.next());
+    private static class TestCaseArgumentsProvider implements ArgumentsProvider {
+        
+        @Override
+        public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+            return Stream.of(
+                    Arguments.of("first", 0, createFetchStatementContext(false)),
+                    Arguments.of("middle", 1, createFetchStatementContext(false)),
+                    Arguments.of("last", 2, createFetchStatementContext(false)),
+                    Arguments.of("firstWithAllDirection", 0, createFetchStatementContext(true)),
+                    Arguments.of("middleWithAllDirection", 1, createFetchStatementContext(true)),
+                    Arguments.of("lastWithAllDirection", 2, createFetchStatementContext(true)));
+        }
     }
 }
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/SQLRouteTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/SQLRouteTest.java
index 4583e2bc0dc..07abf56e542 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/SQLRouteTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/SQLRouteTest.java
@@ -18,41 +18,40 @@
 package org.apache.shardingsphere.sharding.route.engine.type.standard;
 
 import org.apache.shardingsphere.sharding.route.engine.type.standard.assertion.ShardingRouteAssert;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
 
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.List;
+import java.util.stream.Stream;
 
-// TODO add assertion for ShardingRouteAssert.assertRoute
 class SQLRouteTest {
     
-    @Test
-    void assertNoTableUnicastRandomDataSource() {
-        String sql = "SELECT id,name ";
-        ShardingRouteAssert.assertRoute(sql, Collections.singletonList(1));
+    @ParameterizedTest(name = "{0}")
+    @ArgumentsSource(TestCaseArgumentsProvider.class)
+    void assertRoute(final String name, final String sql, final List<Object> params) {
+        // TODO add assertion for ShardingRouteAssert.assertRoute
+        ShardingRouteAssert.assertRoute(sql, params);
     }
     
-    @Test
-    void assertWithBroadcastTable() {
-        String sql = "SELECT id,name from t_order_item a join t_product b on a.product_id = b.product_id where user_id = ?";
-        ShardingRouteAssert.assertRoute(sql, Collections.singletonList(1));
-    }
-    
-    @Test
-    void assertAllBindingWithBroadcastTable() {
-        String sql = "SELECT id,name from t_order a join t_order_item b on a.order_id = b.order_id join t_product c on b.product_id = c.product_id where a.user_id = ?";
-        ShardingRouteAssert.assertRoute(sql, Collections.singletonList(1));
-    }
-    
-    @Test
-    void assertComplexTableWithBroadcastTable() {
-        String sql = "SELECT id,name from t_order a join t_user b on a.user_id = b.user_id join t_product c on a.product_id = c.product_id where a.user_id = ? and b.user_id =?";
-        ShardingRouteAssert.assertRoute(sql, Arrays.asList(1, 1));
-    }
-    
-    @Test
-    void assertInsertTable() {
-        String sql = "INSERT INTO t_order (order_id, user_id) VALUES (?, ?)";
-        ShardingRouteAssert.assertRoute(sql, Arrays.asList(1, 1));
+    private static class TestCaseArgumentsProvider implements ArgumentsProvider {
+        
+        @Override
+        public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+            return Stream.of(
+                    Arguments.of("noTableUnicastRandomDataSource", "SELECT id,name ", Collections.singletonList(1)),
+                    Arguments.of("withBroadcastTable", "SELECT id,name from t_order_item a join t_product b on a.product_id = b.product_id where user_id = ?", Collections.singletonList(1)),
+                    Arguments.of("allBindingWithBroadcastTable",
+                            "SELECT id,name from t_order a join t_order_item b on a.order_id = b.order_id join t_product c on b.product_id = c.product_id where a.user_id = ?",
+                            Collections.singletonList(1)),
+                    Arguments.of("complexTableWithBroadcastTable",
+                            "SELECT id,name from t_order a join t_user b on a.user_id = b.user_id join t_product c on a.product_id = c.product_id where a.user_id = ? and b.user_id =?",
+                            Arrays.asList(1, 1)),
+                    Arguments.of("insertTable", "INSERT INTO t_order (order_id, user_id) VALUES (?, ?)", Arrays.asList(1, 1)));
+        }
     }
 }
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/SubqueryRouteTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/SubqueryRouteTest.java
index eb55ac2421f..b52eb80e07a 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/SubqueryRouteTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/SubqueryRouteTest.java
@@ -20,95 +20,28 @@ package org.apache.shardingsphere.sharding.route.engine.type.standard;
 import org.apache.shardingsphere.infra.hint.HintManager;
 import org.apache.shardingsphere.sharding.route.engine.type.standard.assertion.ShardingRouteAssert;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
 
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.List;
+import java.util.stream.Stream;
 
 // TODO add assertion for ShardingRouteAssert.assertRoute
 class SubqueryRouteTest {
     
-    @Test
-    void assertOneTableDifferentConditionWithFederation() {
-        String sql = "select (select max(id) from t_order b where b.user_id =? ) from t_order a where user_id = ? ";
-        ShardingRouteAssert.assertRoute(sql, Arrays.asList(3, 2));
-    }
-    
-    @Test
-    void assertOneTableSameConditionWithFederation() {
-        String sql = "select (select max(id) from t_order b where b.user_id = ? and b.user_id = a.user_id) from t_order a where user_id = ? ";
-        ShardingRouteAssert.assertRoute(sql, Arrays.asList(1, 1));
-    }
-    
-    @Test
-    void assertBindingTableWithFederation() {
-        String sql = "select (select max(id) from t_order_item b where b.user_id = ?) from t_order a where user_id = ? ";
-        ShardingRouteAssert.assertRoute(sql, Arrays.asList(1, 1));
-    }
-    
-    @Test
-    void assertNotShardingTable() {
-        String sql = "select (select max(id) from t_category b where b.id = ?) from t_category a where id = ? ";
-        ShardingRouteAssert.assertRoute(sql, Arrays.asList(1, 1));
-    }
-    
-    @Test
-    void assertBindingTableWithDifferentValueWithFederation() {
-        String sql = "select (select max(id) from t_order_item b where b.user_id = ? ) from t_order a where user_id = ? ";
-        ShardingRouteAssert.assertRoute(sql, Arrays.asList(2, 3));
-    }
-    
-    @Test
-    void assertTwoTableWithDifferentOperatorWithFederation() {
-        String sql = "select (select max(id) from t_order_item b where b.user_id in(?,?)) from t_order a where user_id = ? ";
-        ShardingRouteAssert.assertRoute(sql, Arrays.asList(1, 2, 1));
-    }
-    
-    @Test
-    void assertTwoTableWithInWithFederation() {
-        String sql = "select (select max(id) from t_order_item b where b.user_id in(?,?)) from t_order a where user_id in(?,?) ";
-        ShardingRouteAssert.assertRoute(sql, Arrays.asList(1, 2, 1, 3));
+    @ParameterizedTest(name = "{0}")
+    @ArgumentsSource(TestCaseArgumentsProvider.class)
+    void assertRoute(final String name, final String sql, final List<Object> params) {
+        ShardingRouteAssert.assertRoute(sql, params);
     }
     
     @Test
-    void assertSubqueryInSubqueryError() {
-        String sql = "select (select status from t_order b where b.user_id =? and status = (select status from t_order b where b.user_id =?)) as c from t_order a "
-                + "where status = (select status from t_order b where b.user_id =? and status = (select status from t_order b where b.user_id =?))";
-        ShardingRouteAssert.assertRoute(sql, Arrays.asList(11, 2, 1, 1));
-    }
-    
-    @Test
-    void assertSubqueryInSubquery() {
-        String sql = "select (select status from t_order b where b.user_id =? and status = (select status from t_order b where b.user_id =?)) as c from t_order a "
-                + "where status = (select status from t_order b where b.user_id =? and status = (select status from t_order b where b.user_id =?))";
-        ShardingRouteAssert.assertRoute(sql, Arrays.asList(1, 1, 1, 1));
-    }
-    
-    @Test
-    void assertSubqueryInFromError() {
-        String sql = "select status from t_order b join (select user_id,status from t_order b where b.user_id =?) c on b.user_id = c.user_id where b.user_id =? ";
-        ShardingRouteAssert.assertRoute(sql, Arrays.asList(11, 1));
-    }
-    
-    @Test
-    void assertSubqueryInFrom() {
-        String sql = "select status from t_order b join (select user_id,status from t_order b where b.user_id =?) c on b.user_id = c.user_id where b.user_id =? ";
-        ShardingRouteAssert.assertRoute(sql, Arrays.asList(1, 1));
-    }
-    
-    @Test
-    void assertSubqueryForAggregation() {
-        String sql = "select count(*) from t_order where user_id = (select user_id from t_order where user_id =?) ";
-        ShardingRouteAssert.assertRoute(sql, Collections.singletonList(1));
-    }
-    
-    @Test
-    void assertSubqueryForBinding() {
-        String sql = "select count(*) from t_order where user_id = (select user_id from t_order_item where user_id =?) ";
-        ShardingRouteAssert.assertRoute(sql, Collections.singletonList(1));
-    }
-    
-    @Test
-    void assertSubqueryWithHint() {
+    void assertRouteWithHint() {
         HintManager hintManager = HintManager.getInstance();
         hintManager.addDatabaseShardingValue("t_hint_test", 1);
         hintManager.addTableShardingValue("t_hint_test", 1);
@@ -117,9 +50,42 @@ class SubqueryRouteTest {
         hintManager.close();
     }
     
-    @Test
-    void assertSubqueryWithOneInstance() {
-        String sql = "select count(*) from t_order where user_id =?";
-        ShardingRouteAssert.assertRoute(sql, Collections.singletonList(1));
+    private static class TestCaseArgumentsProvider implements ArgumentsProvider {
+        
+        @Override
+        public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+            return Stream.of(
+                    Arguments.of("oneTableDifferentConditionWithFederation",
+                            "select (select max(id) from t_order b where b.user_id =? ) from t_order a where user_id = ? ", Arrays.asList(3, 2)),
+                    Arguments.of("oneTableSameConditionWithFederation",
+                            "select (select max(id) from t_order b where b.user_id = ? and b.user_id = a.user_id) from t_order a where user_id = ? ", Arrays.asList(1, 1)),
+                    Arguments.of("bindingTableWithFederation",
+                            "select (select max(id) from t_order_item b where b.user_id = ?) from t_order a where user_id = ? ", Arrays.asList(1, 1)),
+                    Arguments.of("notShardingTable",
+                            "select (select max(id) from t_category b where b.id = ?) from t_category a where id = ? ", Arrays.asList(1, 1)),
+                    Arguments.of("bindingTableWithDifferentValueWithFederation",
+                            "select (select max(id) from t_order_item b where b.user_id = ? ) from t_order a where user_id = ? ", Arrays.asList(2, 3)),
+                    Arguments.of("twoTableWithDifferentOperatorWithFederation",
+                            "select (select max(id) from t_order_item b where b.user_id in(?,?)) from t_order a where user_id = ? ", Arrays.asList(1, 2, 1)),
+                    Arguments.of("twoTableWithInWithFederation",
+                            "select (select max(id) from t_order_item b where b.user_id in(?,?)) from t_order a where user_id in(?,?) ", Arrays.asList(1, 2, 1, 3)),
+                    Arguments.of("subqueryInSubqueryError",
+                            "select (select status from t_order b where b.user_id =? and status = (select status from t_order b where b.user_id =?)) as c from t_order a "
+                                    + "where status = (select status from t_order b where b.user_id =? and status = (select status from t_order b where b.user_id =?))",
+                            Arrays.asList(11, 2, 1, 1)),
+                    Arguments.of("subqueryInSubquery",
+                            "select (select status from t_order b where b.user_id =? and status = (select status from t_order b where b.user_id =?)) as c from t_order a "
+                                    + "where status = (select status from t_order b where b.user_id =? and status = (select status from t_order b where b.user_id =?))",
+                            Arrays.asList(1, 1, 1, 1)),
+                    Arguments.of("subqueryInFromError",
+                            "select status from t_order b join (select user_id,status from t_order b where b.user_id =?) c on b.user_id = c.user_id where b.user_id =? ", Arrays.asList(11, 1)),
+                    Arguments.of("subqueryInFrom",
+                            "select status from t_order b join (select user_id,status from t_order b where b.user_id =?) c on b.user_id = c.user_id where b.user_id =? ", Arrays.asList(1, 1)),
+                    Arguments.of("subqueryForAggregation",
+                            "select count(*) from t_order where user_id = (select user_id from t_order where user_id =?) ", Collections.singletonList(1)),
+                    Arguments.of("subqueryForBinding",
+                            "select count(*) from t_order where user_id = (select user_id from t_order_item where user_id =?) ", Collections.singletonList(1)),
+                    Arguments.of("subqueryWithOneInstance", "select count(*) from t_order where user_id =?", Collections.singletonList(1)));
+        }
     }
 }
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/H2DataSourceMetaDataTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/H2DataSourceMetaDataTest.java
index b7d4078399b..7bc156a16c0 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/H2DataSourceMetaDataTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/dialect/H2DataSourceMetaDataTest.java
@@ -17,113 +17,63 @@
 
 package org.apache.shardingsphere.infra.database.metadata.dialect;
 
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+
+import java.util.stream.Stream;
 
 import static org.hamcrest.CoreMatchers.is;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
 
 class H2DataSourceMetaDataTest {
     
-    @Test
-    void assertNewConstructorWithMem() {
-        H2DataSourceMetaData actual = new H2DataSourceMetaData("jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
-        assertThat(actual.getHostname(), is(""));
-        assertThat(actual.getPort(), is(-1));
-        assertThat(actual.getCatalog(), is("ds_0"));
-        assertNull(actual.getSchema());
-    }
-    
-    @Test
-    void assertNewConstructorWithSymbol() {
-        H2DataSourceMetaData actual = new H2DataSourceMetaData("jdbc:h2:~:ds-0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
-        assertThat(actual.getHostname(), is(""));
-        assertThat(actual.getPort(), is(-1));
-        assertNull(actual.getSchema());
-    }
-    
-    @Test
-    void assertNewConstructorWithTcp() {
-        H2DataSourceMetaData actual = new H2DataSourceMetaData("jdbc:h2:tcp://localhost:8082/~/test1/test2;DB_CLOSE_DELAY=-1");
-        assertThat(actual.getHostname(), is("localhost"));
-        assertThat(actual.getPort(), is(8082));
-        assertThat(actual.getCatalog(), is("test2"));
-        assertNull(actual.getSchema());
-    }
-    
-    @Test
-    void assertNewConstructorWithSsl() {
-        H2DataSourceMetaData actual = new H2DataSourceMetaData("jdbc:h2:ssl:180.76.76.76/home/test");
-        assertThat(actual.getHostname(), is("180.76.76.76"));
-        assertThat(actual.getPort(), is(-1));
-        assertThat(actual.getCatalog(), is("test"));
-        assertNull(actual.getSchema());
-    }
-    
-    @Test
-    void assertNewConstructorWithFile() {
-        H2DataSourceMetaData actual = new H2DataSourceMetaData("jdbc:h2:file:/data/sample;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false");
-        assertThat(actual.getHostname(), is(""));
-        assertThat(actual.getPort(), is(-1));
-        assertThat(actual.getCatalog(), is("sample"));
-        assertNull(actual.getSchema());
-    }
-    
-    @Test
-    void assertIsInSameDatabaseInstanceWithMem() {
-        H2DataSourceMetaData actual1 = new H2DataSourceMetaData("jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
-        H2DataSourceMetaData actual2 = new H2DataSourceMetaData("jdbc:h2:mem:ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
-        assertTrue(actual1.isInSameDatabaseInstance(actual2));
-    }
-    
-    @Test
-    void assertIsInSameDatabaseInstanceWithSymbol() {
-        H2DataSourceMetaData actual1 = new H2DataSourceMetaData("jdbc:h2:~:ds-0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
-        H2DataSourceMetaData actual2 = new H2DataSourceMetaData("jdbc:h2:~:ds-1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
-        assertTrue(actual1.isInSameDatabaseInstance(actual2));
-    }
-    
-    @Test
-    void assertIsInSameDatabaseInstance() {
-        H2DataSourceMetaData actual1 = new H2DataSourceMetaData("jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
-        H2DataSourceMetaData actual2 = new H2DataSourceMetaData("jdbc:h2:~:ds-1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
-        assertTrue(actual1.isInSameDatabaseInstance(actual2));
-    }
-    
-    @Test
-    void assertIsInSameDatabaseInstanceWithTcp() {
-        H2DataSourceMetaData actual1 = new H2DataSourceMetaData("jdbc:h2:tcp://localhost:8082/~/test1/test2;DB_CLOSE_DELAY=-1");
-        H2DataSourceMetaData actual2 = new H2DataSourceMetaData("jdbc:h2:tcp://localhost:8082/~/test3/test4;DB_CLOSE_DELAY=-1");
-        assertTrue(actual1.isInSameDatabaseInstance(actual2));
-    }
-    
-    @Test
-    void assertFalseIsInSameDatabaseInstanceWithTcp() {
-        H2DataSourceMetaData actual1 = new H2DataSourceMetaData("jdbc:h2:tcp://localhost:8082/~/test1/test2;DB_CLOSE_DELAY=-1");
-        H2DataSourceMetaData actual2 = new H2DataSourceMetaData("jdbc:h2:tcp://192.168.64.76:8082/~/test3/test4;DB_CLOSE_DELAY=-1");
-        assertFalse(actual1.isInSameDatabaseInstance(actual2));
+    @ParameterizedTest(name = "{0}")
+    @ArgumentsSource(NewConstructorTestCaseArgumentsProvider.class)
+    void assertNewConstructor(final String name, final String url, final String hostname, final int port, final String catalog, final String schema) {
+        H2DataSourceMetaData actual = new H2DataSourceMetaData(url);
+        assertThat(actual.getHostname(), is(hostname));
+        assertThat(actual.getPort(), is(port));
+        assertThat(actual.getCatalog(), is(catalog));
+        assertThat(actual.getSchema(), is(schema));
     }
     
-    @Test
-    void assertIsInSameDatabaseInstanceWithSsl() {
-        H2DataSourceMetaData actual1 = new H2DataSourceMetaData("jdbc:h2:ssl:180.76.76.76/home/test-one");
-        H2DataSourceMetaData actual2 = new H2DataSourceMetaData("jdbc:h2:ssl:180.76.76.76/home/test-two");
-        assertTrue(actual1.isInSameDatabaseInstance(actual2));
+    @ParameterizedTest(name = "{0}")
+    @ArgumentsSource(IsInSameDatabaseInstanceTestCaseArgumentsProvider.class)
+    void assertIsInSameDatabaseInstance(final String name, final String url1, final String url2, final boolean isSame) {
+        H2DataSourceMetaData actual1 = new H2DataSourceMetaData(url1);
+        H2DataSourceMetaData actual2 = new H2DataSourceMetaData(url2);
+        assertThat(actual1.isInSameDatabaseInstance(actual2), is(isSame));
     }
     
-    @Test
-    void assertFalseIsInSameDatabaseInstanceWithSsl() {
-        H2DataSourceMetaData actual1 = new H2DataSourceMetaData("jdbc:h2:ssl:180.76.76.76/home/test-one");
-        H2DataSourceMetaData actual2 = new H2DataSourceMetaData("jdbc:h2:ssl:181.76.76.76/home/test-two");
-        assertFalse(actual1.isInSameDatabaseInstance(actual2));
+    private static class NewConstructorTestCaseArgumentsProvider implements ArgumentsProvider {
+        
+        @Override
+        public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+            return Stream.of(
+                    Arguments.of("mem", "jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", "", -1, "ds_0", null),
+                    Arguments.of("symbol", "jdbc:h2:~:ds-0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", "", -1, "ds-0", null),
+                    Arguments.of("tcp", "jdbc:h2:tcp://localhost:8082/~/test1/test2;DB_CLOSE_DELAY=-1", "localhost", 8082, "test2", null),
+                    Arguments.of("ssl", "jdbc:h2:ssl:180.76.76.76/home/test", "180.76.76.76", -1, "test", null),
+                    Arguments.of("file", "jdbc:h2:file:/data/sample;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false", "", -1, "sample", null));
+        }
     }
     
-    @Test
-    void assertIsInSameDatabaseInstanceWithFile() {
-        H2DataSourceMetaData actual1 = new H2DataSourceMetaData("jdbc:h2:file:/data/sample-one;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false");
-        H2DataSourceMetaData actual2 = new H2DataSourceMetaData("jdbc:h2:file:/data/sample-two;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false");
-        assertTrue(actual1.isInSameDatabaseInstance(actual2));
+    private static class IsInSameDatabaseInstanceTestCaseArgumentsProvider implements ArgumentsProvider {
+        
+        @Override
+        public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+            return Stream.of(
+                    Arguments.of("mem", "jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", "jdbc:h2:mem:ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", true),
+                    Arguments.of("symbol", "jdbc:h2:~:ds-0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", "jdbc:h2:~:ds-1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", true),
+                    Arguments.of("memAndSymbol", "jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", "jdbc:h2:~:ds-1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", true),
+                    Arguments.of("tcp", "jdbc:h2:tcp://localhost:8082/~/test1/test2;DB_CLOSE_DELAY=-1", "jdbc:h2:tcp://localhost:8082/~/test3/test4;DB_CLOSE_DELAY=-1", true),
+                    Arguments.of("tcpNotSame", "jdbc:h2:tcp://localhost:8082/~/test1/test2;DB_CLOSE_DELAY=-1", "jdbc:h2:tcp://192.168.64.76:8082/~/test3/test4;DB_CLOSE_DELAY=-1", false),
+                    Arguments.of("ssl", "jdbc:h2:ssl:180.76.76.76/home/test-one", "jdbc:h2:ssl:180.76.76.76/home/test-two", true),
+                    Arguments.of("sslNotSame", "jdbc:h2:ssl:180.76.76.76/home/test-one", "jdbc:h2:ssl:181.76.76.76/home/test-two", false),
+                    Arguments.of("file", "jdbc:h2:file:/data/sample-one;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false", "jdbc:h2:file:/data/sample-two;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false", true));
+        }
     }
 }