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 1496b77  Add test case for ShowAuthorityRuleExecutor (#14915)
1496b77 is described below

commit 1496b77f2f34d4cb2cce978556187d1989e2c64b
Author: liguoping <[email protected]>
AuthorDate: Thu Jan 20 08:38:48 2022 +0800

    Add test case for ShowAuthorityRuleExecutor (#14915)
---
 .../common/show/ShowAuthorityRuleExecutorTest.java | 70 ++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/ShowAuthorityRuleExecutorTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/ShowAuthorityRuleExecutorTest.java
new file mode 100644
index 0000000..25a3eff
--- /dev/null
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/ShowAuthorityRuleExecutorTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.proxy.backend.text.distsql.ral.common.show;
+
+import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
+import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import 
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseRow;
+import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.show.executor.ShowAuthorityRuleExecutor;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class ShowAuthorityRuleExecutorTest {
+    
+    private final ShowAuthorityRuleExecutor executor = new 
ShowAuthorityRuleExecutor();
+    
+    @Test
+    public void assertAuthorityRule() throws SQLException {
+        ContextManager contextManager = mock(ContextManager.class, 
RETURNS_DEEP_STUBS);
+        
when(contextManager.getMetaDataContexts().getGlobalRuleMetaData()).thenReturn(getGlobalRuleMetaData());
+        ProxyContext.getInstance().init(contextManager);
+        executor.execute();
+        executor.next();
+        QueryResponseRow queryResponseRow = executor.getQueryResponseRow();
+        List<Object> data = new ArrayList<>(queryResponseRow.getData());
+        assertThat(data.size(), is(3));
+        assertThat(data.get(0), is("root@localhost"));
+        assertThat(data.get(1), is("ALL_PRIVILEGES_PERMITTED"));
+        assertThat(data.get(2), is(""));
+    }
+    
+    private ShardingSphereRuleMetaData getGlobalRuleMetaData() {
+        ShardingSphereUser root = new ShardingSphereUser("root", "", 
"localhost");
+        AuthorityRuleConfiguration authorityRuleConfiguration = new 
AuthorityRuleConfiguration(Collections.singletonList(root),
+                new 
ShardingSphereAlgorithmConfiguration("ALL_PRIVILEGES_PERMITTED", new 
Properties()));
+        return new 
ShardingSphereRuleMetaData(Collections.singleton(authorityRuleConfiguration), 
Collections.emptyList());
+    }
+}

Reply via email to