Search in sources :

Example 6 with Belong

use of com.baidu.hugegraph.structure.auth.Belong in project incubator-hugegraph-toolchain by apache.

the class BelongApiTest method testDelete.

@Test
public void testDelete() {
    Belong belong1 = createBelong(user1, group1, "user1 => group1");
    Belong belong2 = createBelong(user2, group2, "user2 => group2");
    Assert.assertEquals(2, api.list(null, null, -1).size());
    api.delete(belong1.id());
    Assert.assertEquals(1, api.list(null, null, -1).size());
    Assert.assertEquals(belong2, api.list(null, null, -1).get(0));
    api.delete(belong2.id());
    Assert.assertEquals(0, api.list(null, null, -1).size());
    Assert.assertThrows(ServerException.class, () -> {
        api.delete(belong2.id());
    }, e -> {
        Assert.assertContains("Invalid belong id:", e.getMessage());
    });
    Assert.assertThrows(ServerException.class, () -> {
        api.delete("fake-id");
    }, e -> {
        Assert.assertContains("Invalid belong id: fake-id", e.getMessage());
    });
}
Also used : Belong(com.baidu.hugegraph.structure.auth.Belong) Test(org.junit.Test)

Example 7 with Belong

use of com.baidu.hugegraph.structure.auth.Belong in project incubator-hugegraph-toolchain by apache.

the class BelongApiTest method testGet.

@Test
public void testGet() {
    Belong belong1 = createBelong(user1, group1, "user1 => group1");
    Belong belong2 = createBelong(user2, group2, "user2 => group2");
    Assert.assertEquals("user1 => group1", belong1.description());
    Assert.assertEquals("user2 => group2", belong2.description());
    belong1 = api.get(belong1.id());
    belong2 = api.get(belong2.id());
    Assert.assertEquals(user1.id(), belong1.user());
    Assert.assertEquals(group1.id(), belong1.group());
    Assert.assertEquals("user1 => group1", belong1.description());
    Assert.assertEquals(user2.id(), belong2.user());
    Assert.assertEquals(group2.id(), belong2.group());
    Assert.assertEquals("user2 => group2", belong2.description());
}
Also used : Belong(com.baidu.hugegraph.structure.auth.Belong) Test(org.junit.Test)

Example 8 with Belong

use of com.baidu.hugegraph.structure.auth.Belong in project incubator-hugegraph-toolchain by apache.

the class BelongApiTest method testUpdate.

@Test
public void testUpdate() {
    Belong belong1 = createBelong(user1, group1, "user1 => group1");
    Belong belong2 = createBelong(user2, group2, "user2 => group2");
    Assert.assertEquals("user1 => group1", belong1.description());
    Assert.assertEquals("user2 => group2", belong2.description());
    belong1.description("description updated");
    Belong updated = api.update(belong1);
    Assert.assertEquals("description updated", updated.description());
    Assert.assertNotEquals(belong1.updateTime(), updated.updateTime());
    Assert.assertThrows(ServerException.class, () -> {
        belong2.user(user1);
        api.update(belong2);
    }, e -> {
        Assert.assertContains("The user of belong can't be updated", e.getMessage());
    });
    Assert.assertThrows(ServerException.class, () -> {
        belong2.user(user2);
        belong2.group(group1);
        api.update(belong2);
    }, e -> {
        Assert.assertContains("The group of belong can't be updated", e.getMessage());
    });
    Assert.assertThrows(ServerException.class, () -> {
        Whitebox.setInternalState(belong2, "id", "fake-id");
        api.update(belong2);
    }, e -> {
        Assert.assertContains("Invalid belong id: fake-id", e.getMessage());
    });
}
Also used : Belong(com.baidu.hugegraph.structure.auth.Belong) Test(org.junit.Test)

Example 9 with Belong

use of com.baidu.hugegraph.structure.auth.Belong in project incubator-hugegraph-toolchain by apache.

the class AuthManager method deleteAll.

public void deleteAll() {
    for (Belong belong : this.listBelongs()) {
        this.deleteBelong(belong.id());
    }
    for (Access access : this.listAccesses()) {
        this.deleteAccess(access.id());
    }
    for (User user : this.listUsers()) {
        if (user.name().equals("admin")) {
            continue;
        }
        this.deleteUser(user.id());
    }
    for (Group group : this.listGroups()) {
        this.deleteGroup(group.id());
    }
    for (Target target : this.listTargets()) {
        this.deleteTarget(target.id());
    }
    for (Project project : this.listProjects()) {
        Set<String> graphs = project.graphs();
        if (CollectionUtils.isNotEmpty(graphs)) {
            this.projectRemoveGraphs(project.id(), graphs);
        }
        this.deleteProject(project.id());
    }
}
Also used : Group(com.baidu.hugegraph.structure.auth.Group) Project(com.baidu.hugegraph.structure.auth.Project) Target(com.baidu.hugegraph.structure.auth.Target) User(com.baidu.hugegraph.structure.auth.User) Access(com.baidu.hugegraph.structure.auth.Access) Belong(com.baidu.hugegraph.structure.auth.Belong)

Aggregations

Belong (com.baidu.hugegraph.structure.auth.Belong)9 Test (org.junit.Test)6 Access (com.baidu.hugegraph.structure.auth.Access)3 Group (com.baidu.hugegraph.structure.auth.Group)3 Target (com.baidu.hugegraph.structure.auth.Target)3 User (com.baidu.hugegraph.structure.auth.User)3 Project (com.baidu.hugegraph.structure.auth.Project)2 HugeClient (com.baidu.hugegraph.driver.HugeClient)1 HugeResource (com.baidu.hugegraph.structure.auth.HugeResource)1 Login (com.baidu.hugegraph.structure.auth.Login)1 LoginResult (com.baidu.hugegraph.structure.auth.LoginResult)1 TokenPayload (com.baidu.hugegraph.structure.auth.TokenPayload)1 UserRole (com.baidu.hugegraph.structure.auth.User.UserRole)1 AfterClass (org.junit.AfterClass)1