use of com.baidu.hugegraph.auth.HugeGroup in project incubator-hugegraph by apache.
the class AuthTest method testCreateGroup.
@Test
public void testCreateGroup() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
HugeGroup group = makeGroup("group1");
Id id = authManager.createGroup(group);
group = authManager.getGroup(id);
Assert.assertEquals("group1", group.name());
Assert.assertEquals(null, group.description());
Assert.assertEquals(group.create(), group.update());
Assert.assertEquals(ImmutableMap.of("group_name", "group1", "group_create", group.create(), "group_update", group.update(), "group_creator", "admin", "id", group.id()), group.asMap());
group = makeGroup("group2");
group.description("something");
id = authManager.createGroup(group);
group = authManager.getGroup(id);
Assert.assertEquals("group2", group.name());
Assert.assertEquals("something", group.description());
Assert.assertEquals(group.create(), group.update());
HashMap<String, Object> expected = new HashMap<>();
expected.putAll(ImmutableMap.of("group_name", "group2", "group_description", "something", "group_creator", "admin"));
expected.putAll(ImmutableMap.of("group_create", group.create(), "group_update", group.update(), "id", group.id()));
Assert.assertEquals(expected, group.asMap());
}
use of com.baidu.hugegraph.auth.HugeGroup in project incubator-hugegraph by apache.
the class AuthTest method testListGroups.
@Test
public void testListGroups() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id id1 = authManager.createGroup(makeGroup("group1"));
Id id2 = authManager.createGroup(makeGroup("group2"));
List<HugeGroup> groups = authManager.listGroups(ImmutableList.of(id1, id2));
Assert.assertEquals(2, groups.size());
Assert.assertEquals("group1", groups.get(0).name());
Assert.assertEquals("group2", groups.get(1).name());
groups = authManager.listGroups(ImmutableList.of(id1, id2, id2));
Assert.assertEquals(3, groups.size());
Assert.assertEquals("group1", groups.get(0).name());
Assert.assertEquals("group2", groups.get(1).name());
Assert.assertEquals("group2", groups.get(2).name());
groups = authManager.listGroups(ImmutableList.of(id1, id2, IdGenerator.of("fake")));
Assert.assertEquals(2, groups.size());
}
use of com.baidu.hugegraph.auth.HugeGroup in project incubator-hugegraph by apache.
the class AuthTest method makeGroup.
private static HugeGroup makeGroup(String name) {
HugeGroup group = new HugeGroup(name);
group.creator("admin");
return group;
}
use of com.baidu.hugegraph.auth.HugeGroup in project incubator-hugegraph by apache.
the class AuthTest method testListAllGroups.
@Test
public void testListAllGroups() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
authManager.createGroup(makeGroup("group1"));
authManager.createGroup(makeGroup("group2"));
List<HugeGroup> groups = authManager.listAllGroups(-1);
Assert.assertEquals(2, groups.size());
Assert.assertEquals(ImmutableSet.of("group1", "group2"), ImmutableSet.of(groups.get(0).name(), groups.get(1).name()));
Assert.assertEquals(0, authManager.listAllGroups(0).size());
Assert.assertEquals(1, authManager.listAllGroups(1).size());
Assert.assertEquals(2, authManager.listAllGroups(2).size());
Assert.assertEquals(2, authManager.listAllGroups(3).size());
}
use of com.baidu.hugegraph.auth.HugeGroup in project incubator-hugegraph by apache.
the class AuthTest method testGetGroup.
@Test
public void testGetGroup() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id id = authManager.createGroup(makeGroup("group-test"));
HugeGroup group = authManager.getGroup(id);
Assert.assertEquals("group-test", group.name());
Assert.assertThrows(NotFoundException.class, () -> {
authManager.getGroup(IdGenerator.of("fake"));
});
Assert.assertThrows(NotFoundException.class, () -> {
authManager.getGroup(null);
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
Id user = authManager.createUser(makeUser("tom", "pass1"));
authManager.getGroup(user);
});
}
Aggregations