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());
});
}
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());
}
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());
});
}
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());
}
}
Aggregations