コード例 #1
0
 public void testPropertyFilter2() {
   Graph graph = TinkerGraphFactory.createTinkerGraph();
   Vertex marko = graph.getVertex("1");
   Pipe<Vertex, Edge> pipe1 = new OutEdgesPipe();
   Pipe<Edge, Vertex> pipe2 = new InVertexPipe();
   Pipe pipe3 =
       new PropertyFilterPipe<Vertex, String>("lang", "java", FilterPipe.Filter.NOT_EQUAL);
   Pipeline<Vertex, Vertex> pipeline =
       new Pipeline<Vertex, Vertex>(Arrays.asList(pipe1, pipe2, pipe3));
   pipeline.setStarts(Arrays.asList(marko).iterator());
   assertTrue(pipeline.hasNext());
   int counter = 0;
   while (pipeline.hasNext()) {
     counter++;
     Vertex vertex = pipeline.next();
     assertTrue(vertex.getId().equals("2") || vertex.getId().equals("4"));
     assertTrue(
         vertex.getProperty("name").equals("josh") || vertex.getProperty("name").equals("vadas"));
     assertTrue(vertex.getProperty("age").equals(27) || vertex.getProperty("age").equals(32));
   }
   assertEquals(counter, 2);
   try {
     pipeline.next();
     assertTrue(false);
   } catch (NoSuchElementException e) {
     assertFalse(false);
   }
 }
コード例 #2
0
/** @author Marko A. Rodriguez (http://markorodriguez.com) */
public class FunctionStepTest extends com.tinkerpop.gremlin.test.FunctionStepTest {

  Graph g = TinkerGraphFactory.createTinkerGraph();

  public void testCompliance() {
    ComplianceTest.testCompliance(this.getClass());
  }

  public void test_g_v1_out_stepXnext_nameX() {
    super.test_g_v1_out_stepXnext_nameX(
        new GremlinPipeline(g.getVertex(1))
            .out()
            .step(
                new PipeFunction<Iterator<Vertex>, Vertex>() {
                  public Vertex compute(Iterator<Vertex> iterator) {
                    return iterator.next();
                  }
                })
            .property("name"));

    super.test_g_v1_out_stepXnext_nameX(
        new GremlinPipeline(g.getVertex(1))
            .optimize(false)
            .out()
            .step(
                new PipeFunction<Iterator<Vertex>, Vertex>() {
                  public Vertex compute(Iterator<Vertex> iterator) {
                    return iterator.next();
                  }
                })
            .property("name"));
  }
}
コード例 #3
0
ファイル: TestTraversals.java プロジェクト: wsalembi/totorom
public class TestTraversals {
  private FramedGraph graph = new FramedGraph(TinkerGraphFactory.createTinkerGraph());

  @Test
  public void testCopySplit() {
    List<TVertex> fair =
        graph.v(1).out("knows").copySplit(v -> v.traversal(), v -> v.out()).fairMerge().toList();

    List<TVertex> exhaust =
        graph.v(1).out("knows").copySplit(v -> v.traversal(), v -> v.out()).exhaustMerge().toList();

    Assert.assertEquals(exhaust.get(0), fair.get(0));
    Assert.assertNotEquals(exhaust.get(1), fair.get(1));
    Assert.assertEquals(exhaust.get(2), fair.get(1));
    Assert.assertEquals(exhaust.get(1), fair.get(2));
    Assert.assertTrue(exhaust.get(0) instanceof TVertex);
  }

  @Test
  public void testMarkBack() {

    Assert.assertEquals(
        29,
        graph.V().mark().outE("knows").inV().has("age", T.gt, 30).back().property("age").next());
  }

  @Test
  public void testMarkOptional() {
    List<TVertex> aggregate = new ArrayList<>();
    Assert.assertEquals(
        6,
        graph
            .V()
            .mark()
            .outE("knows")
            .inV()
            .has("age", T.gt, 30)
            .aggregate(aggregate)
            .optional()
            .property("age")
            .count());
    Assert.assertEquals(graph.v(4).next(), aggregate.get(0));
  }

  @Test
  public void testBoth() {
    Assert.assertEquals(3, graph.v(4).both().count());
    Assert.assertEquals(1, graph.v(4).both("knows").count());
    Assert.assertEquals(3, graph.v(4).both("knows", "created").count());
    Assert.assertEquals(1, graph.v(4).both(1, "knows", "created").count());
  }

  @Test
  public void testBothE() {
    Assert.assertEquals(3, graph.v(4).bothE().count());
    Assert.assertEquals(1, graph.v(4).bothE("knows").count());
    Assert.assertEquals(3, graph.v(4).bothE("knows", "created").count());
    Assert.assertEquals(1, graph.v(4).bothE(1, "knows", "created").count());
  }

  @Test
  public void testBothV() {

    Assert.assertEquals(2, graph.e(12).bothV().count());
  }

  @Test
  public void testCap() {

    Assert.assertEquals(3, graph.V().has("lang", "java").in("created").groupCount().cap().size());
  }

  @Test
  public void testId() {
    Assert.assertEquals("1", graph.V().has("name", "marko").id().next());
  }

  @Test
  public void testIn() {
    Assert.assertEquals(1, graph.v(4).in().count());
    Assert.assertEquals(3, graph.v(3).in("created").count());
    Assert.assertEquals(2, graph.v(3).in(2, "created").count());
  }

  @Test
  public void testInE() {
    Assert.assertEquals(1, graph.v(4).inE().count());
    Assert.assertEquals(3, graph.v(3).inE("created").count());
    Assert.assertEquals(2, graph.v(3).inE(2, "created").count());
  }

  @Test
  public void testInV() {

    Assert.assertEquals(graph.v(3).next(), graph.e(12).inV().next());
  }

  @Test
  public void testOutV() {
    Assert.assertEquals(graph.v(6).next(), graph.e(12).outV().next());
  }

  @Test
  public void testProperty() {
    Assert.assertEquals("marko", graph.v(1).property("name").next());
  }

  @Test
  public void testLabel() {
    Assert.assertEquals("created", graph.v(6).outE().label().next());
  }

  @Test
  public void testMap() {
    Assert.assertEquals(2, graph.v(1).map().next().size());
    Assert.assertEquals(6, graph.V().map("id", "age").count());
  }

  @Test
  public void testMemoize() {
    Assert.assertEquals(
        2, graph.V().out().as("here").out().memoize("here").property("name").count());
    Map<?, ?> map = new HashMap<>();
    Assert.assertEquals(
        2, graph.V().out().as("here").out().memoize("here", map).property("name").count());
    Assert.assertEquals(4, map.size());
  }

  @Test
  public void testOrder() {
    Assert.assertEquals("josh", graph.V().property("name").order().next());
    Assert.assertEquals("vadas", graph.V().property("name").order(Order.DECR).next());

    Assert.assertEquals(
        graph.v(2).next(), graph.V().order(Comparators.property("name")).out("knows").next());
  }

  @Test
  public void testOut() {

    Assert.assertEquals(3, graph.v(1).out().count());
    Assert.assertEquals(2, graph.v(1).out("knows").count());
    Assert.assertEquals(1, graph.v(1).out(1, "knows").count());
  }

  @Test
  public void testOutE() {

    Assert.assertEquals(3, graph.v(1).outE().count());
    Assert.assertEquals(2, graph.v(1).outE("knows").count());
    Assert.assertEquals(1, graph.v(1).outE(1, "knows").count());
  }

  @Test
  public void testPath() {

    List<?> path = graph.v(1).out().path().next();

    Assert.assertEquals(2, path.size());
    Assert.assertTrue(path.get(0) instanceof TVertex);
    Assert.assertTrue(path.get(1) instanceof TVertex);
  }

  @Test
  public void testGatherScatter() {

    Assert.assertEquals(6, graph.V().gatherScatter().out().count());

    Assert.assertEquals(3, graph.V().range(0, 2).gatherScatter().out().count());
  }

  @Test
  public void testSelect() {
    Row<?> row = graph.v(1).as("x").out("knows").as("y").select().next();
    Assert.assertEquals(graph.v(1).next(), row.get(0));
    Assert.assertEquals(graph.v(2).next(), row.get(1));
  }

  @Test
  public void testShuffle() {
    Assert.assertTrue(graph.v(1).out().shuffle().next() instanceof TVertex);
  }

  @Test
  public void testTransform() {
    Assert.assertEquals(new Integer(1), graph.v(1).transform(t -> 1).next());
  }

  @Test
  public void testRange() {
    Assert.assertEquals(graph.v(2).next(), graph.v(1).out().range(1, 1).next());
  }

  @Test
  public void testAnd() {
    Assert.assertEquals(2, graph.V().and(v -> v.both("knows"), v -> v.both("created")).count());
  }

  @Test
  public void testOr() {
    Assert.assertEquals(3, graph.V().or(v -> v.out().has("name")).count());
  }

  @Test
  public void testDedup() {
    Assert.assertEquals(3, graph.v(1).out().in().dedup().count());
  }

  @Test
  public void testExcept() {
    Assert.assertEquals(5, graph.V().except(graph.v(1)).count());
  }

  @Test
  public void testFilter() {
    Assert.assertEquals(
        2,
        graph
            .V()
            .filter(v -> v.getProperty("age") != null && v.getProperty("age", Integer.class) > 29)
            .count());
  }

  @Test
  public void testHas() {
    Assert.assertEquals(1, graph.V().has("name", "marko").count());
  }

  @Test
  public void testHasNot() {
    Assert.assertEquals(5, graph.V().hasNot("name", "marko").count());
  }

  @Test
  public void testInterval() {
    Assert.assertEquals(3, graph.E().interval("weight", 0.3f, 0.9f).count());
  }

  @Test
  public void testRandom() {
    // Assert.assertEquals(3, graph.V().random(0.5).count()); //Can't test
    // this :)
  }

  @Test
  public void testRetain() {
    Assert.assertEquals(1, graph.V().retain(graph.v(1)).count());
  }

  @Test
  public void testSimplePath() {
    Assert.assertEquals(2, graph.v(1).out().in().simplePath().count());
  }

  @Test
  public void testAggregate() {

    List<TVertex> x = new ArrayList<TVertex>();
    Assert.assertEquals(graph.v(3).next(), graph.v(1).out().aggregate(x).next());
    Assert.assertEquals(3, graph.v(1).out().aggregate().cap().size());
    Assert.assertEquals(3, x.size());
    Assert.assertTrue(x.get(0) instanceof TVertex);
  }

  @Test
  public void testGroupCount() {

    Map<TVertex, Long> cap = graph.V().out().groupCount().cap();
    Assert.assertEquals(4, cap.size());
    Assert.assertTrue(cap.keySet().iterator().next() instanceof TVertex);

    Assert.assertEquals(4, graph.V().out().groupCount(v -> v.getId()).cap().size());

    Assert.assertEquals(
        6, graph.V().out().groupCount().divert(gc -> Assert.assertEquals(4, gc.size())).count());
  }

  @Test
  public void testGroupBy() {

    Map<TVertex, List<TVertex>> cap = graph.V().groupBy(v -> v, v -> v.out()).cap();
    Assert.assertEquals(6, cap.size());
    Assert.assertEquals(3, cap.get(graph.v(1).next()).size());
    Assert.assertTrue(cap.get(graph.v(1).next()).iterator().next() instanceof TVertex);
  }

  @Test
  public void testOptional() {}

  @Test
  public void testSideEffect() {
    final List<TVertex> collected = new ArrayList<TVertex>();
    graph
        .v(1)
        .sideEffect(
            v -> {
              collected.add(v);
            })
        .iterate();
    Assert.assertEquals(1, collected.size());
  }

  @Test
  public void testStore() {
    Collection<TVertex> x = new ArrayList<>();
    graph.v(1).store(x).next();
    Assert.assertEquals(graph.v(1).next(), x.iterator().next());
    Assert.assertEquals(graph.v(1).next(), graph.v(1).store().cap().iterator().next());
  }

  @Test
  public void testTable() {

    Table table =
        graph
            .V()
            .as("vertex")
            .mark()
            .property("name")
            .as("name")
            .back()
            .property("age")
            .as("age")
            .table()
            .cap();
    Assert.assertEquals(6, table.size());
    Assert.assertTrue(table.get(0).get(0) instanceof TVertex);
  }

  @Test
  public void testTree() {

    Tree<TVertex> tree = graph.v(1).out().out().tree().cap();
    Assert.assertEquals(1, tree.get(graph.v(1).next()).size());
  }

  @Test
  public void testLoop() {

    List<TVertex> list = graph.v(1).loop(v -> v.out(), 3).toList();
    Assert.assertEquals(2, list.size());
  }
}