@Test
  public void testAccessControl() {
    int startingVertexCount = graph.getAllVertices().size();
    int startingEdgeCount = graph.getAllEdges().size();

    String workspace1Id = "testWorkspace1Id";
    String workspace1Title = "workspace1";
    idGenerator.push(workspace1Id);
    idGenerator.push(workspace1Id + "_to_" + user1.getUserId());
    workspaceRepository.add(workspace1Title, user1);

    String workspace2Id = "testWorkspace2Id";
    String workspace2Title = "workspace2";
    idGenerator.push(workspace2Id);
    idGenerator.push(workspace2Id + "_to_" + user1.getUserId());
    workspaceRepository.add(workspace2Title, user1);

    String workspace3Id = "testWorkspace3Id";
    String workspace3Title = "workspace3";
    idGenerator.push(workspace3Id);
    idGenerator.push(workspace3Id + "_to_" + user2.getUserId());
    workspaceRepository.add(workspace3Title, user2);

    assertEquals(
        startingVertexCount + 3, graph.getAllVertices().size()); // +3 = the workspace vertices
    assertEquals(
        startingEdgeCount + 3,
        graph.getAllEdges().size()); // +3 = the edges between workspaces and users

    List<Workspace> user1Workspaces = toList(workspaceRepository.findAll(user1));
    assertEquals(2, user1Workspaces.size());
    boolean foundWorkspace1 = false;
    boolean foundWorkspace2 = false;
    for (Workspace workspace : user1Workspaces) {
      if (workspace.getDisplayTitle().equals(workspace1Title)) {
        foundWorkspace1 = true;
      } else if (workspace.getDisplayTitle().equals(workspace2Title)) {
        foundWorkspace2 = true;
      }
    }
    assertTrue("foundWorkspace1", foundWorkspace1);
    assertTrue("foundWorkspace2", foundWorkspace2);

    List<Workspace> user2Workspaces = toList(workspaceRepository.findAll(user2));
    assertEquals(1, user2Workspaces.size());
    assertEquals(workspace3Title, user2Workspaces.get(0).getDisplayTitle());

    try {
      workspaceRepository.updateUserOnWorkspace(
          user2Workspaces.get(0), user1.getUserId(), WorkspaceAccess.READ, user1);
      fail("user1 should not have access to user2's workspace");
    } catch (LumifyAccessDeniedException ex) {
      assertEquals(user1, ex.getUser());
      assertEquals(user2Workspaces.get(0).getId(), ex.getResourceId());
    }

    idGenerator.push(workspace3Id + "to" + user2.getUserId());
    workspaceRepository.updateUserOnWorkspace(
        user2Workspaces.get(0), user1.getUserId(), WorkspaceAccess.READ, user2);
    assertEquals(
        startingVertexCount + 3, graph.getAllVertices().size()); // +3 = the workspace vertices
    assertEquals(
        startingEdgeCount + 4,
        graph.getAllEdges().size()); // +4 = the edges between workspaces and users
    List<WorkspaceUser> usersWithAccess =
        workspaceRepository.findUsersWithAccess(user2Workspaces.get(0).getId(), user2);
    boolean foundUser1 = false;
    boolean foundUser2 = false;
    for (WorkspaceUser userWithAccess : usersWithAccess) {
      if (userWithAccess.getUserId().equals(user1.getUserId())) {
        assertEquals(WorkspaceAccess.READ, userWithAccess.getWorkspaceAccess());
        foundUser1 = true;
      } else if (userWithAccess.getUserId().equals(user2.getUserId())) {
        assertEquals(WorkspaceAccess.WRITE, userWithAccess.getWorkspaceAccess());
        foundUser2 = true;
      } else {
        fail("Unexpected user " + userWithAccess.getUserId());
      }
    }
    assertTrue("could not find user1", foundUser1);
    assertTrue("could not find user2", foundUser2);

    try {
      workspaceRepository.deleteUserFromWorkspace(user2Workspaces.get(0), user1.getUserId(), user1);
      fail("user1 should not have write access to user2's workspace");
    } catch (LumifyAccessDeniedException ex) {
      assertEquals(user1, ex.getUser());
      assertEquals(user2Workspaces.get(0).getId(), ex.getResourceId());
    }

    try {
      workspaceRepository.delete(user2Workspaces.get(0), user1);
      fail("user1 should not have write access to user2's workspace");
    } catch (LumifyAccessDeniedException ex) {
      assertEquals(user1, ex.getUser());
      assertEquals(user2Workspaces.get(0).getId(), ex.getResourceId());
    }

    workspaceRepository.updateUserOnWorkspace(
        user2Workspaces.get(0), user1.getUserId(), WorkspaceAccess.WRITE, user2);
    assertEquals(
        startingVertexCount + 3, graph.getAllVertices().size()); // +3 = the workspace vertices
    assertEquals(
        startingEdgeCount + 4,
        graph.getAllEdges().size()); // +4 = the edges between workspaces and users

    workspaceRepository.deleteUserFromWorkspace(user2Workspaces.get(0), user1.getUserId(), user2);
    assertEquals(
        startingVertexCount + 3, graph.getAllVertices().size()); // +3 = the workspace vertices
    assertEquals(
        startingEdgeCount + 3,
        graph.getAllEdges().size()); // +3 = the edges between workspaces and users

    workspaceRepository.delete(user2Workspaces.get(0), user2);
    assertEquals(
        startingVertexCount + 2, graph.getAllVertices().size()); // +2 = the workspace vertices
    assertEquals(
        startingEdgeCount + 2,
        graph.getAllEdges().size()); // +2 = the edges between workspaces and users
  }