From f0340f4ac5f3dad73993318a6f254b75ce3bf96b Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com> Date: Sat, 1 Nov 2014 08:14:02 -0400 Subject: [PATCH] Added filter pipe example. --- .../titangraph/example/GremlinTest.java | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/syncleus/titangraph/example/GremlinTest.java b/src/test/java/com/syncleus/titangraph/example/GremlinTest.java index 02023f0..2923121 100644 --- a/src/test/java/com/syncleus/titangraph/example/GremlinTest.java +++ b/src/test/java/com/syncleus/titangraph/example/GremlinTest.java @@ -38,7 +38,7 @@ public class GremlinTest { } @Test - public void testGremlinFindBrothersFirstLetterP() { + public void testGremlinFindBrothersFilterLetter() { final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB"); final GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>(); final Vertex jupiterVertex = godGraph.getVertices("name", "jupiter").iterator().next(); @@ -56,6 +56,49 @@ public class GremlinTest { Assert.assertEquals( "pluto", brotherNames.get(0).toString() ); } + @Test + public void testGremlinFindBrothersRemoveLetter() { + final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB"); + final GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>(); + final Vertex jupiterVertex = godGraph.getVertices("name", "jupiter").iterator().next(); + final GremlinPipeline brotherNamesPipe = new GremlinPipeline(jupiterVertex).out("brother").property("name").transform(new PipeFunction<String, String>() { + public String compute(String argument) { + return argument.replaceAll("o", ""); + } + }); + final List brotherNames = brotherNamesPipe.next(100); + + //we know jupiter only has two brothers + Assert.assertEquals(brotherNames.size(), 2); + + //check each brothers name to make sure both of them matchone of the known brothers names + Assert.assertTrue(("plut".equals(brotherNames.get(0).toString())) || ("neptune".equals(brotherNames.get(0).toString()))); + Assert.assertTrue( ("plut".equals(brotherNames.get(1).toString())) || ("neptune".equals(brotherNames.get(1).toString())) ); + } + + @Test + public void testGremlinFindBrothersRemoveAndFilterLetter() { + final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB"); + final GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>(); + final Vertex jupiterVertex = godGraph.getVertices("name", "jupiter").iterator().next(); + final GremlinPipeline brotherNamesPipe = new GremlinPipeline(jupiterVertex).out("brother").property("name").transform(new PipeFunction<String, String>() { + public String compute(String argument) { + return argument.replaceAll("o", ""); + } + }).filter(new PipeFunction<String, Boolean>() { + public Boolean compute(String argument) { + return argument.startsWith("p"); + } + }); + final List brotherNames = brotherNamesPipe.next(100); + + //we know jupiter only has two brothers + Assert.assertEquals(brotherNames.size(), 1); + + //check each brothers name to make sure both of them matchone of the known brothers names + Assert.assertEquals( "plut", brotherNames.get(0).toString() ); + } + @Test public void testGremlinCompiled() { final TitanGraph godGraph = TitanGods.create("./target/TitanTestDB"); -- GitLab