diff --git a/kernel/authority/distsql/handler/pom.xml b/kernel/authority/distsql/handler/pom.xml
index 7df40f894b716..c8c07844a7084 100644
--- a/kernel/authority/distsql/handler/pom.xml
+++ b/kernel/authority/distsql/handler/pom.xml
@@ -47,5 +47,12 @@
shardingsphere-authority-distsql-parser
${project.version}
+
+
+ org.apache.shardingsphere
+ shardingsphere-test-it-distsql
+ ${project.version}
+ test
+
diff --git a/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/query/ShowAuthorityRuleExecutor.java b/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/query/ShowAuthorityRuleExecutor.java
index f5a749f546dc2..7888bb802ac8b 100644
--- a/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/query/ShowAuthorityRuleExecutor.java
+++ b/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/query/ShowAuthorityRuleExecutor.java
@@ -49,7 +49,7 @@ public Collection getColumnNames(final ShowAuthorityRuleStatement sqlSta
public Collection getRows(final ShowAuthorityRuleStatement sqlStatement, final ContextManager contextManager) {
String grantees = rule.getGrantees().stream().map(Grantee::toString).collect(Collectors.joining("; "));
String provider = rule.getConfiguration().getPrivilegeProvider().getType();
- Properties props = rule.getConfiguration().getPrivilegeProvider().getProps().isEmpty() ? new Properties() : rule.getConfiguration().getPrivilegeProvider().getProps();
+ Properties props = rule.getConfiguration().getPrivilegeProvider().getProps();
return Collections.singleton(new LocalDataQueryResultRow(grantees, provider, props));
}
diff --git a/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/query/ShowAuthorityRuleExecutorTest.java b/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/query/ShowAuthorityRuleExecutorTest.java
index bd466fc816a0e..32989e38cd2f5 100644
--- a/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/query/ShowAuthorityRuleExecutorTest.java
+++ b/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/query/ShowAuthorityRuleExecutorTest.java
@@ -21,57 +21,58 @@
import org.apache.shardingsphere.authority.config.UserConfiguration;
import org.apache.shardingsphere.authority.distsql.statement.ShowAuthorityRuleStatement;
import org.apache.shardingsphere.authority.rule.AuthorityRule;
-import org.apache.shardingsphere.distsql.handler.engine.DistSQLConnectionContext;
-import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecuteEngine;
+import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
+import org.apache.shardingsphere.infra.metadata.user.Grantee;
+import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorTest;
+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.Collection;
import java.util.Collections;
-import java.util.Iterator;
-import java.util.Optional;
import java.util.Properties;
+import java.util.stream.Stream;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-class ShowAuthorityRuleExecutorTest {
+class ShowAuthorityRuleExecutorTest extends DistSQLGlobalRuleQueryExecutorTest {
- private DistSQLQueryExecuteEngine engine;
-
- @BeforeEach
- void setUp() {
- engine = new DistSQLQueryExecuteEngine(new ShowAuthorityRuleStatement(), null, mockContextManager(), mock(DistSQLConnectionContext.class));
+ ShowAuthorityRuleExecutorTest() {
+ super(mockRule());
}
- private ContextManager mockContextManager() {
- ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().findSingleRule(AuthorityRule.class)).thenReturn(Optional.of(new AuthorityRule(createRuleConfiguration())));
+ private static AuthorityRule mockRule() {
+ AuthorityRule result = mock(AuthorityRule.class);
+ when(result.getGrantees()).thenReturn(Collections.singleton(new Grantee("root", "localhost")));
return result;
}
- private AuthorityRuleConfiguration createRuleConfiguration() {
- UserConfiguration userConfig = new UserConfiguration("root", "", "localhost", null, false);
- AlgorithmConfiguration privilegeProvider = new AlgorithmConfiguration("ALL_PERMITTED", new Properties());
- return new AuthorityRuleConfiguration(Collections.singleton(userConfig), privilegeProvider, Collections.emptyMap(), null);
+ @ParameterizedTest(name = "{0}")
+ @ArgumentsSource(TestCaseArgumentsProvider.class)
+ void assertExecuteQuery(final String name, final GlobalRuleConfiguration ruleConfig, final DistSQLStatement sqlStatement, final Collection expected) throws SQLException {
+ assertQueryResultRows(ruleConfig, sqlStatement, expected);
}
- @Test
- void assertGetRows() throws SQLException {
- engine.executeQuery();
- Collection actual = engine.getRows();
- assertThat(actual.size(), is(1));
- Iterator iterator = actual.iterator();
- LocalDataQueryResultRow row = iterator.next();
- assertThat(row.getCell(1), is("root@localhost"));
- assertThat(row.getCell(2), is("ALL_PERMITTED"));
- assertThat(row.getCell(3), is(""));
+ private static class TestCaseArgumentsProvider implements ArgumentsProvider {
+
+ @Override
+ public Stream extends Arguments> provideArguments(final ExtensionContext extensionContext) {
+ return Stream.of(
+ Arguments.arguments("normal", createRuleConfiguration(), new ShowAuthorityRuleStatement(),
+ Collections.singleton(new LocalDataQueryResultRow("root@localhost", "ALL_PERMITTED", ""))));
+ }
+
+ private AuthorityRuleConfiguration createRuleConfiguration() {
+ UserConfiguration userConfig = new UserConfiguration("root", "", "localhost", null, false);
+ AlgorithmConfiguration privilegeProvider = new AlgorithmConfiguration("ALL_PERMITTED", new Properties());
+ return new AuthorityRuleConfiguration(Collections.singleton(userConfig), privilegeProvider, Collections.emptyMap(), null);
+ }
}
}