Search in sources :

Example 1 with HugeGroup

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());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) HashMap(java.util.HashMap) HugeGroup(com.baidu.hugegraph.auth.HugeGroup) Id(com.baidu.hugegraph.backend.id.Id) Test(org.junit.Test)

Example 2 with HugeGroup

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());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) HugeGroup(com.baidu.hugegraph.auth.HugeGroup) Id(com.baidu.hugegraph.backend.id.Id) Test(org.junit.Test)

Example 3 with HugeGroup

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;
}
Also used : HugeGroup(com.baidu.hugegraph.auth.HugeGroup)

Example 4 with HugeGroup

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());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) HugeGroup(com.baidu.hugegraph.auth.HugeGroup) Test(org.junit.Test)

Example 5 with HugeGroup

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);
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) HugeGroup(com.baidu.hugegraph.auth.HugeGroup) Id(com.baidu.hugegraph.backend.id.Id) Test(org.junit.Test)

Aggregations

HugeGroup (com.baidu.hugegraph.auth.HugeGroup)12 HugeGraph (com.baidu.hugegraph.HugeGraph)11 AuthManager (com.baidu.hugegraph.auth.AuthManager)7 Test (org.junit.Test)6 Id (com.baidu.hugegraph.backend.id.Id)5 Timed (com.codahale.metrics.annotation.Timed)4 Produces (jakarta.ws.rs.Produces)4 Consumes (jakarta.ws.rs.Consumes)2 GET (jakarta.ws.rs.GET)2 Path (jakarta.ws.rs.Path)2 Status (com.baidu.hugegraph.api.filter.StatusFilter.Status)1 HugeProject (com.baidu.hugegraph.auth.HugeProject)1 HugeTarget (com.baidu.hugegraph.auth.HugeTarget)1 HugeUser (com.baidu.hugegraph.auth.HugeUser)1 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)1 POST (jakarta.ws.rs.POST)1 PUT (jakarta.ws.rs.PUT)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 After (org.junit.After)1