Esempio n. 1
0
 public void testBothEdges() {
   Graph graph = TinkerGraphFactory.createTinkerGraph();
   Vertex josh = graph.getVertex("4");
   BothEdgesPipe pipe = new BothEdgesPipe();
   pipe.setStarts(new SingleIterator<Vertex>(josh));
   int counter = 0;
   while (pipe.hasNext()) {
     counter++;
     Edge edge = pipe.next();
     assertTrue(
         edge.getId().equals("8") || edge.getId().equals("10") || edge.getId().equals("11"));
   }
   assertEquals(counter, 3);
 }
Esempio n. 2
0
 public void testPropertyMapPipe() {
   Graph graph = TinkerGraphFactory.createTinkerGraph();
   Pipe<Vertex, Map<String, Object>> pipe = new PropertyMapPipe<Vertex>();
   pipe.setStarts(new SingleIterator<Vertex>(graph.getVertex(1)));
   int counter = 0;
   while (pipe.hasNext()) {
     Map<String, Object> map = pipe.next();
     counter++;
     assertEquals(map.get("name"), "marko");
     assertEquals(map.get("age"), 29);
     assertNull(map.get("blah"));
   }
   assertEquals(counter, 1);
 }
Esempio n. 3
0
  public void testBothEdgesWithLabels() {

    Graph graph = TinkerGraphFactory.createTinkerGraph();
    Vertex marko = graph.getVertex("1");
    BothEdgesPipe pipe = new BothEdgesPipe("knows");
    pipe.setStarts(new SingleIterator<Vertex>(marko));
    int counter = 0;
    while (pipe.hasNext()) {
      counter++;
      Edge edge = pipe.next();
      assertTrue(
          edge.getInVertex().getProperty("name").equals("josh")
              || edge.getInVertex().getProperty("name").equals("vadas"));
    }
    assertEquals(counter, 2);
  }
Esempio n. 4
0
 public void testIncludeStatementPathOverTinkerGraph() {
   GremlinEvaluator ge = new GremlinEvaluator();
   Graph graph = TinkerGraphFactory.createTinkerGraph();
   ge.getVariables().declareVariable(Tokens.GRAPH_VARIABLE, graph);
   ge.getVariables().declareVariable(Tokens.AT_VARIABLE, graph.getVertex("1"));
   assertTrue(
       (Boolean) ge.evaluate("include 'com.tinkerpop.gremlin.statements.TestPathLibrary'").get(0));
   List results = ge.evaluate("./co-developer");
   assertEquals(results.size(), 2);
   for (Vertex vertex : (List<Vertex>) results) {
     if (vertex.getProperty("name").equals("peter") || vertex.getProperty("name").equals("josh")) {
       assertTrue(true);
     } else {
       assertTrue(false);
     }
   }
 }
  @Test
  public void inputGraphWithTypesFullCycle() throws IOException {
    TinkerGraph graph = TinkerGraphFactory.createTinkerGraph();

    ByteArrayOutputStream stream = new ByteArrayOutputStream();

    GraphSONWriter writer = new GraphSONWriter(graph);
    writer.outputGraph(stream, null, null, true);

    stream.flush();
    stream.close();

    String jsonString = new String(stream.toByteArray());

    byte[] bytes = jsonString.getBytes();
    InputStream inputStream = new ByteArrayInputStream(bytes);

    TinkerGraph emptyGraph = new TinkerGraph();
    GraphSONReader.inputGraph(emptyGraph, inputStream);

    Assert.assertEquals(6, getIterableCount(emptyGraph.getVertices()));
    Assert.assertEquals(6, getIterableCount(emptyGraph.getEdges()));

    for (Vertex v : graph.getVertices()) {
      Vertex found = emptyGraph.getVertex(v.getId());

      Assert.assertNotNull(v);

      for (String key : found.getPropertyKeys()) {
        Assert.assertEquals(v.getProperty(key), found.getProperty(key));
      }
    }

    for (Edge e : graph.getEdges()) {
      Edge found = emptyGraph.getEdge(e.getId());

      Assert.assertNotNull(e);

      for (String key : found.getPropertyKeys()) {
        Assert.assertEquals(e.getProperty(key), found.getProperty(key));
      }
    }
  }
Esempio n. 6
0
 public void testIdEdgePipeGraph() {
   Graph graph = TinkerGraphFactory.createTinkerGraph();
   List<String> ids = Arrays.asList("9", "11", "12");
   Pipe<String, Edge> pipe = new IdEdgePipe<String>(graph);
   pipe.setStarts(ids);
   int counter = 0;
   while (pipe.hasNext()) {
     Edge edge = pipe.next();
     if (counter == 0) {
       assertEquals(edge.getId(), "9");
       assertEquals(edge.getProperty("weight"), 0.4f);
     } else if (counter == 1) {
       assertEquals(edge.getId(), "11");
       assertEquals(edge.getInVertex(), graph.getVertex("3"));
     } else if (counter == 2) {
       assertEquals(edge.getId(), "12");
       assertEquals(edge.getLabel(), "created");
     } else {
       throw new RuntimeException("Illegal state.");
     }
     counter++;
   }
   assertEquals(counter, 3);
 }