private void verifyProcessEntityEdges() {
    Vertex processVertex = getEntityVertex(PROCESS_ENTITY_NAME, RelationshipType.PROCESS_ENTITY);

    // verify edge to cluster vertex
    verifyVertexForEdge(
        processVertex,
        Direction.OUT,
        RelationshipLabel.FEED_CLUSTER_EDGE.getName(),
        CLUSTER_ENTITY_NAME,
        RelationshipType.CLUSTER_ENTITY.getName());
    // verify edge to user vertex
    verifyVertexForEdge(
        processVertex,
        Direction.OUT,
        RelationshipLabel.USER.getName(),
        FALCON_USER,
        RelationshipType.USER.getName());
    // verify edge to tags vertex
    verifyVertexForEdge(
        processVertex, Direction.OUT, "classified-as", "Critical", RelationshipType.TAGS.getName());

    // verify edges to inputs
    List<String> actual = new ArrayList<String>();
    for (Edge edge :
        processVertex.getEdges(Direction.IN, RelationshipLabel.FEED_PROCESS_EDGE.getName())) {
      Vertex outVertex = edge.getVertex(Direction.OUT);
      Assert.assertEquals(
          RelationshipType.FEED_ENTITY.getName(),
          outVertex.getProperty(RelationshipProperty.TYPE.getName()));
      actual.add(outVertex.<String>getProperty(RelationshipProperty.NAME.getName()));
    }

    Assert.assertTrue(
        actual.containsAll(Arrays.asList("impression-feed", "clicks-feed")),
        "Actual does not contain expected: " + actual);

    actual.clear();
    // verify edges to outputs
    for (Edge edge :
        processVertex.getEdges(Direction.OUT, RelationshipLabel.PROCESS_FEED_EDGE.getName())) {
      Vertex outVertex = edge.getVertex(Direction.IN);
      Assert.assertEquals(
          RelationshipType.FEED_ENTITY.getName(),
          outVertex.getProperty(RelationshipProperty.TYPE.getName()));
      actual.add(outVertex.<String>getProperty(RelationshipProperty.NAME.getName()));
    }
    Assert.assertTrue(
        actual.containsAll(Arrays.asList("imp-click-join1", "imp-click-join2")),
        "Actual does not contain expected: " + actual);
  }
  private void verifyLineageGraph(
      String feedType,
      List<String> expectedFeeds,
      List<String> secureFeeds,
      List<String> ownedAndSecureFeeds) {
    // feeds owned by a user
    List<String> feedNamesOwnedByUser = getFeedsOwnedByAUser(feedType);
    Assert.assertTrue(feedNamesOwnedByUser.containsAll(expectedFeeds));

    Graph graph = service.getGraph();

    Iterator<Vertex> vertices =
        graph.getVertices("name", "impression-feed/2014-01-01T00:00Z").iterator();
    Assert.assertTrue(vertices.hasNext());
    Vertex feedInstanceVertex = vertices.next();
    Assert.assertEquals(
        feedInstanceVertex.getProperty(RelationshipProperty.TYPE.getName()),
        RelationshipType.FEED_INSTANCE.getName());

    Object vertexId = feedInstanceVertex.getId();
    Vertex vertexById = graph.getVertex(vertexId);
    Assert.assertEquals(vertexById, feedInstanceVertex);

    // feeds classified as secure
    verifyFeedsClassifiedAsSecure(feedType, secureFeeds);

    // feeds owned by a user and classified as secure
    verifyFeedsOwnedByUserAndClassification(feedType, "Financial", ownedAndSecureFeeds);
  }
 private void verifyEntityProperties(
     Vertex entityVertex, String entityName, RelationshipType entityType) {
   Assert.assertEquals(entityName, entityVertex.getProperty(RelationshipProperty.NAME.getName()));
   Assert.assertEquals(
       entityType.getName(), entityVertex.getProperty(RelationshipProperty.TYPE.getName()));
   Assert.assertNotNull(entityVertex.getProperty(RelationshipProperty.TIMESTAMP.getName()));
 }
  private void verifyFeedsClassifiedAsSecure(String feedType, List<String> expected) {
    GraphQuery classQuery =
        getQuery()
            .has(RelationshipProperty.NAME.getName(), "Secure")
            .has(RelationshipProperty.TYPE.getName(), RelationshipType.TAGS.getName());

    List<String> actual = new ArrayList<String>();
    for (Vertex feedVertex : classQuery.vertices()) {
      for (Vertex feed : feedVertex.getVertices(Direction.BOTH, "classified-as")) {
        if (feed.getProperty(RelationshipProperty.TYPE.getName()).equals(feedType)) {
          System.out.println(" Secure classification -> " + GraphUtils.vertexString(feed));
          actual.add(feed.<String>getProperty(RelationshipProperty.NAME.getName()));
        }
      }
    }

    Assert.assertTrue(actual.containsAll(expected), "Actual does not contain expected: " + actual);
  }
  private List<String> getFeedsOwnedByAUser(String feedType) {
    GraphQuery userQuery =
        getQuery()
            .has(RelationshipProperty.NAME.getName(), FALCON_USER)
            .has(RelationshipProperty.TYPE.getName(), RelationshipType.USER.getName());

    List<String> feedNames = new ArrayList<String>();
    for (Vertex userVertex : userQuery.vertices()) {
      for (Vertex feed : userVertex.getVertices(Direction.IN, RelationshipLabel.USER.getName())) {
        if (feed.getProperty(RelationshipProperty.TYPE.getName()).equals(feedType)) {
          System.out.println(FALCON_USER + " owns -> " + GraphUtils.vertexString(feed));
          feedNames.add(feed.<String>getProperty(RelationshipProperty.NAME.getName()));
        }
      }
    }

    return feedNames;
  }
 private void verifyVertexForEdge(
     Vertex fromVertex,
     Direction direction,
     String label,
     String expectedName,
     String expectedType) {
   for (Edge edge : fromVertex.getEdges(direction, label)) {
     Vertex outVertex = edge.getVertex(Direction.IN);
     Assert.assertEquals(outVertex.getProperty(RelationshipProperty.NAME.getName()), expectedName);
     Assert.assertEquals(outVertex.getProperty(RelationshipProperty.TYPE.getName()), expectedType);
   }
 }
  private Vertex getEntityVertex(String entityName, RelationshipType entityType) {
    GraphQuery entityQuery =
        getQuery()
            .has(RelationshipProperty.NAME.getName(), entityName)
            .has(RelationshipProperty.TYPE.getName(), entityType.getName());
    Iterator<Vertex> iterator = entityQuery.vertices().iterator();
    Assert.assertTrue(iterator.hasNext());

    Vertex entityVertex = iterator.next();
    Assert.assertNotNull(entityVertex);

    return entityVertex;
  }
  /**
   * This unfortunately requires a handle to Titan implementation since
   * com.tinkerpop.blueprints.KeyIndexableGraph#createKeyIndex does not create an index.
   */
  protected void createIndicesForVertexKeys() {
    if (!((KeyIndexableGraph) graph).getIndexedKeys(Vertex.class).isEmpty()) {
      LOG.info("Indexes already exist for graph");
      return;
    }

    LOG.info("Indexes does not exist, Creating indexes for graph");
    // todo - externalize this
    makeNameKeyIndex();
    makeKeyIndex(RelationshipProperty.TYPE.getName());
    makeKeyIndex(RelationshipProperty.TIMESTAMP.getName());
    makeKeyIndex(RelationshipProperty.VERSION.getName());
    makeInstanceIndex();
  }
 private void verifyFeedsOwnedByUserAndClassification(
     String feedType, String classification, List<String> expected) {
   List<String> actual = new ArrayList<String>();
   Vertex userVertex = getEntityVertex(FALCON_USER, RelationshipType.USER);
   for (Vertex feed : userVertex.getVertices(Direction.IN, RelationshipLabel.USER.getName())) {
     if (feed.getProperty(RelationshipProperty.TYPE.getName()).equals(feedType)) {
       for (Vertex classVertex : feed.getVertices(Direction.OUT, "classified-as")) {
         if (classVertex.getProperty(RelationshipProperty.NAME.getName()).equals(classification)) {
           actual.add(feed.<String>getProperty(RelationshipProperty.NAME.getName()));
           System.out.println(
               classification + " feed owned by falcon-user -> " + GraphUtils.vertexString(feed));
         }
       }
     }
   }
   Assert.assertTrue(actual.containsAll(expected), "Actual does not contain expected: " + actual);
 }