You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/07/15 14:33:42 UTC
[shardingsphere] branch master updated: Revise AuthorityRuleTest (#19248)
This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng 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 5c2a7764340 Revise AuthorityRuleTest (#19248)
5c2a7764340 is described below
commit 5c2a7764340590d8f4b4631cb502dd64135b31bf
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Jul 15 22:33:37 2022 +0800
Revise AuthorityRuleTest (#19248)
---
.../authority/rule/AuthorityRuleTest.java | 51 +++++++++++-----------
1 file changed, 25 insertions(+), 26 deletions(-)
diff --git a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/rule/AuthorityRuleTest.java b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/rule/AuthorityRuleTest.java
index 5951e3c4375..aaa2daa4995 100644
--- a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/rule/AuthorityRuleTest.java
+++ b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-core/src/test/java/org/apache/shardingsphere/authority/rule/AuthorityRuleTest.java
@@ -17,43 +17,44 @@
package org.apache.shardingsphere.authority.rule;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.metadata.user.Grantee;
+import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Optional;
import java.util.Properties;
-import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
-import org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.junit.Test;
-public final class AuthorityRuleTest {
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+public final class AuthorityRuleTest {
+
@Test
public void assertFindUser() {
AuthorityRule rule = createAuthorityRule();
- Optional<ShardingSphereUser> adminUser = rule.findUser(new Grantee("admin", "localhost"));
- assertTrue(adminUser.isPresent());
- assertThat(adminUser.get().getGrantee().getUsername(), is("admin"));
- assertThat(adminUser.get().getGrantee().getHostname(), is("localhost"));
- Optional<ShardingSphereUser> notFindUser = rule.findUser(new Grantee("admin", "127.0.0.1"));
- assertFalse(notFindUser.isPresent());
+ Optional<ShardingSphereUser> actual = rule.findUser(new Grantee("admin", "localhost"));
+ assertTrue(actual.isPresent());
+ assertThat(actual.get().getGrantee().getUsername(), is("admin"));
+ assertThat(actual.get().getGrantee().getHostname(), is("localhost"));
}
-
+
+ @Test
+ public void assertNotFindUser() {
+ assertFalse(createAuthorityRule().findUser(new Grantee("admin", "127.0.0.1")).isPresent());
+ }
+
@Test
public void assertFindPrivileges() {
- AuthorityRule rule = createAuthorityRule();
- Optional<ShardingSpherePrivileges> privileges = rule.findPrivileges(new Grantee("admin", "localhost"));
- assertTrue(privileges.isPresent());
+ assertTrue(createAuthorityRule().findPrivileges(new Grantee("admin", "localhost")).isPresent());
}
-
+
@Test
public void assertRefresh() {
Collection<ShardingSphereUser> users = new LinkedList<>();
@@ -62,15 +63,13 @@ public final class AuthorityRuleTest {
users.add(new ShardingSphereUser("sharding-sphere", "123456", "127.0.0.1"));
AuthorityRule rule = createAuthorityRule();
rule.refresh(Collections.emptyMap(), users);
- Optional<ShardingSpherePrivileges> privileges = rule.findPrivileges(new Grantee("sharding-sphere", "localhost"));
- assertTrue(privileges.isPresent());
+ assertTrue(rule.findPrivileges(new Grantee("sharding-sphere", "localhost")).isPresent());
}
private AuthorityRule createAuthorityRule() {
Collection<ShardingSphereUser> users = new LinkedList<>();
users.add(new ShardingSphereUser("root", "root", "localhost"));
users.add(new ShardingSphereUser("admin", "123456", "localhost"));
- AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(users, new ShardingSphereAlgorithmConfiguration("ALL_PERMITTED", new Properties()));
- return new AuthorityRule(ruleConfig, Collections.emptyMap());
+ return new AuthorityRule(new AuthorityRuleConfiguration(users, new ShardingSphereAlgorithmConfiguration("ALL_PERMITTED", new Properties())), Collections.emptyMap());
}
}