コード例 #1
0
  @Test
  public void testAddWorkspace() {
    int startingVertexCount = graph.getAllVertices().size();
    int startingEdgeCount = graph.getAllEdges().size();

    String workspaceId = "testWorkspaceId";
    idGenerator.push(workspaceId);
    idGenerator.push(workspaceId + "_to_" + user1.getUserId());

    Workspace workspace = workspaceRepository.add("workspace1", user1);
    assertTrue(
        authorizationRepository
            .getGraphAuthorizations()
            .contains(WorkspaceRepository.WORKSPACE_ID_PREFIX + workspaceId));

    assertEquals(
        startingVertexCount + 1, graph.getAllVertices().size()); // +1 = the workspace vertex
    assertEquals(
        startingEdgeCount + 1,
        graph.getAllEdges().size()); // +1 = the edge between workspace and user1

    assertNull(
        "Should not have access", graph.getVertex(workspace.getId(), new InMemoryAuthorizations()));
    InMemoryAuthorizations authorizations =
        new InMemoryAuthorizations(WorkspaceRepository.VISIBILITY_STRING, workspace.getId());
    assertNotNull("Should have access", graph.getVertex(workspace.getId(), authorizations));

    Workspace foundWorkspace = workspaceRepository.findById(workspace.getId(), user1);
    assertEquals(workspace.getId(), foundWorkspace.getId());
  }