コード例 #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());
  }
コード例 #2
0
  @Test
  public void testEntities() {
    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);
    assertEquals(
        startingVertexCount + 1, graph.getAllVertices().size()); // +1 = the workspace vertex
    assertEquals(
        startingEdgeCount + 1,
        graph.getAllEdges().size()); // +1 = the edges between workspaces and users

    try {
      workspaceRepository.updateEntityOnWorkspace(
          workspace, entity1Vertex.getId(), true, 100, 100, user2);
      fail("user2 should not have write access to workspace");
    } catch (LumifyAccessDeniedException ex) {
      assertEquals(user2, ex.getUser());
      assertEquals(workspace.getId(), ex.getResourceId());
    }

    idGenerator.push(workspaceId + "_to_" + entity1Vertex.getId());
    workspaceRepository.updateEntityOnWorkspace(
        workspace, entity1Vertex.getId(), true, 100, 200, user1);
    assertEquals(
        startingVertexCount + 1, graph.getAllVertices().size()); // +1 = the workspace vertex
    assertEquals(
        startingEdgeCount + 2,
        graph.getAllEdges().size()); // +2 = the edges between workspaces, users, and entities

    workspaceRepository.updateEntityOnWorkspace(
        workspace, entity1Vertex.getId(), true, 200, 300, user1);
    assertEquals(
        startingVertexCount + 1, graph.getAllVertices().size()); // +1 = the workspace vertex
    assertEquals(
        startingEdgeCount + 2,
        graph.getAllEdges().size()); // +2 = the edges between workspaces, users, and entities

    List<WorkspaceEntity> entities = workspaceRepository.findEntities(workspace, user1);
    assertEquals(1, entities.size());
    assertEquals(entity1Vertex.getId(), entities.get(0).getEntityVertexId());
    assertEquals(200, entities.get(0).getGraphPositionX().intValue());
    assertEquals(300, entities.get(0).getGraphPositionY().intValue());

    try {
      workspaceRepository.findEntities(workspace, user2);
      fail("user2 should not have read access to workspace");
    } catch (LumifyAccessDeniedException ex) {
      assertEquals(user2, ex.getUser());
      assertEquals(workspace.getId(), ex.getResourceId());
    }

    try {
      workspaceRepository.softDeleteEntityFromWorkspace(workspace, entity1Vertex.getId(), user2);
      fail("user2 should not have write access to workspace");
    } catch (LumifyAccessDeniedException ex) {
      assertEquals(user2, ex.getUser());
      assertEquals(workspace.getId(), ex.getResourceId());
    }

    workspaceRepository.softDeleteEntityFromWorkspace(workspace, entity1Vertex.getId(), user1);
    assertEquals(
        startingVertexCount + 1, graph.getAllVertices().size()); // +1 = the workspace vertex
    Map<String, InMemoryEdge> edgesAfterDelete = graph.getAllEdges();
    assertEquals(
        startingEdgeCount + 2, edgesAfterDelete.size()); // +1 = the edges between workspaces, users
    boolean foundRemovedEdge = false;
    for (InMemoryEdge edge : edgesAfterDelete.values()) {
      if (edge.getLabel().equals(workspaceToEntityRelationship.getIRI())) {
        assertEquals(
            false, WorkspaceLumifyProperties.WORKSPACE_TO_ENTITY_VISIBLE.getPropertyValue(edge));
        foundRemovedEdge = true;
      }
    }
    assertTrue(foundRemovedEdge);
  }