├── .gitignore ├── .travis.yml ├── CHANGELOG.textile ├── LICENSE.txt ├── README.textile ├── bin ├── gremlin.bat └── gremlin.sh ├── data ├── graph-example-1.json ├── graph-example-1.ntriple ├── graph-example-1.xml └── graph-example-2.xml ├── doc ├── Acknowledgments.textile ├── Backtrack-Pattern.textile ├── Basic-Graph-Traversals.textile ├── Defining-a-More-Complex-Property-Graph.textile ├── Defining-a-Property-Graph.textile ├── Depth-First-vs.-Breadth-First.textile ├── Downloads.textile ├── Except-Retain-Pattern.textile ├── Flow-Rank-Pattern.textile ├── Getting-Started.textile ├── Gremlin-Groovy-Path-Optimizations.textile ├── Gremlin-Methods.textile ├── Gremlin-Steps.textile ├── Home.textile ├── JVM-Language-Implementations.textile ├── Learning-Dependencies.textile ├── LinkedData-Sail.textile ├── Loop-Pattern.textile ├── MapReduce-Pattern.textile ├── Path-Pattern.textile ├── Pattern-Match-Pattern.textile ├── Release-Notes.textile ├── SPARQL-vs.-Gremlin.textile ├── Split-Merge-Pattern.textile ├── Step-Closures.textile ├── The-Benefits-of-Gremlin.textile ├── Traversal-Optimization.textile ├── Tree-Pattern.textile ├── Troubleshooting.textile ├── Updating-a-Graph.textile ├── User-Defined-Steps.textile ├── Using-Gremlin-through-Groovy.textile ├── Using-Gremlin-through-Java.textile ├── Using-JUNG.textile ├── Writing-Gremlin-REPL-Plugins.textile └── images │ ├── co-followed_by-example.jpg │ ├── co-followed_by.graffle │ ├── dbpedia-logo.png │ ├── depth-vs-breadth.gif │ ├── favicon.ico │ ├── grammar-example-1.graffle │ ├── grammar-example-1.jpg │ ├── grammar-map-example-1.jpg │ ├── grammar-map-rewrite.graffle │ ├── grammar-map-rewrite.jpg │ ├── graph-example-1-codeveloper.graffle │ ├── graph-example-1-rdf.graffle │ ├── graph-example-1-rdf.jpg │ ├── graph-example-1.graffle │ ├── graph-example-1.jpg │ ├── graph-example-2.jpg │ ├── graph-model.graffle │ ├── graph-model.jpg │ ├── grateful-dead-concert.jpg │ ├── grateful-dead-concert2.jpg │ ├── gremlin-2.png │ ├── gremlin-character-2.png │ ├── gremlin-character-3.png │ ├── gremlin-characters.pdf │ ├── gremlin-chickenwing.png │ ├── gremlin-clownin-around.png │ ├── gremlin-grad.png │ ├── gremlin-gremalicious.png │ ├── gremlin-gremicide.png │ ├── gremlin-gremlin-the-grouch.png │ ├── gremlin-gremlin.png │ ├── gremlin-gremlivich.png │ ├── gremlin-gremopoly.png │ ├── gremlin-gremreaper.png │ ├── gremlin-gremstefani.png │ ├── gremlin-hardhat.png │ ├── gremlin-inthewild.png │ ├── gremlin-kilt.png │ ├── gremlin-lab-coat.pdf │ ├── gremlin-lab-coat.png │ ├── gremlin-logo.graffle │ ├── gremlin-logo.png │ ├── gremlin-logo_inv.png │ ├── gremlin-new-sheriff-in-town.png │ ├── gremlin-no-more-mr-nice-guy.png │ ├── gremlin-on-the-case.png │ ├── gremlin-painting.png │ ├── gremlin-pipe.png │ ├── gremlin-running.png │ ├── gremlin-standing-small.png │ ├── gremlin-standing.png │ ├── gremlin-without-a-cause.pdf │ ├── gremlin-without-a-cause.png │ ├── gremlin-xmas-alpha.png │ ├── gremlindocs-logo.graffle │ ├── gremlindocs-logo.png │ ├── gremlindocs.pdf │ ├── gremlindocs.png │ ├── jerry-followed_by-example.graffle │ ├── jerry-followed_by-example.jpg │ ├── jerry-garcia.jpg │ ├── ldsail-arch.graffle │ ├── ldsail-arch.jpg │ ├── lod-cloud.png │ ├── rdf-graph-model.graffle │ ├── rdf-graph-model.jpg │ ├── rdf-logo.gif │ ├── sql2gremlin-logo.pdf │ ├── sql2gremlin-logo.png │ ├── structures-processes.graffle │ ├── structures-processes.jpg │ └── tinkerpop-logo-small.jpg ├── gremlin-groovy ├── bin │ ├── gremlin.bat │ └── gremlin.sh ├── pom.xml └── src │ ├── assembly │ ├── distribution.xml │ └── standalone.xml │ ├── main │ ├── bin │ │ ├── README.txt │ │ ├── gremlin.bat │ │ └── gremlin.sh │ ├── groovy │ │ └── com │ │ │ └── tinkerpop │ │ │ └── gremlin │ │ │ └── groovy │ │ │ ├── Gremlin.groovy │ │ │ └── loaders │ │ │ ├── ElementLoader.groovy │ │ │ ├── GraphLoader.groovy │ │ │ ├── IndexLoader.groovy │ │ │ ├── ObjectLoader.groovy │ │ │ ├── PipeLoader.groovy │ │ │ └── SailGraphLoader.groovy │ ├── java │ │ └── com │ │ │ └── tinkerpop │ │ │ └── gremlin │ │ │ └── groovy │ │ │ ├── GremlinGroovyPipeline.java │ │ │ ├── GroovyPipeFunction.java │ │ │ ├── console │ │ │ ├── Console.java │ │ │ ├── ConsoleGroovy.java │ │ │ ├── ConsoleIO.java │ │ │ ├── ConsolePlugin.java │ │ │ ├── ErrorHookClosure.java │ │ │ ├── NullResultHookClosure.java │ │ │ ├── PromptClosure.java │ │ │ └── ResultHookClosure.java │ │ │ └── jsr223 │ │ │ ├── AbstractImportCustomizerProvider.java │ │ │ ├── DefaultImportCustomizerProvider.java │ │ │ ├── GremlinGroovyScriptEngine.java │ │ │ ├── GremlinGroovyScriptEngineFactory.java │ │ │ ├── ImportCustomizerProvider.java │ │ │ └── ScriptExecutor.java │ └── resources │ │ ├── META-INF │ │ └── services │ │ │ └── javax.script.ScriptEngineFactory │ │ └── log4j.properties │ └── test │ ├── groovy │ └── com │ │ └── tinkerpop │ │ └── gremlin │ │ └── groovy │ │ ├── FunctionStepTest.groovy │ │ ├── GremlinTest.groovy │ │ ├── UtilitiesTest.groovy │ │ ├── basescript │ │ ├── GremlinGroovyPipelineInterceptor.groovy │ │ └── GremlinGroovyScriptBaseClassForTest.groovy │ │ ├── branch │ │ ├── IfThenElseStepTest.groovy │ │ ├── LoopStepTest.groovy │ │ └── SplitMergeStepsTest.groovy │ │ ├── filter │ │ ├── BackStepTest.groovy │ │ ├── DedupStepTest.groovy │ │ ├── ExceptStepTest.groovy │ │ ├── FilterStepTest.groovy │ │ ├── HasNotStepTest.groovy │ │ ├── HasStepTest.groovy │ │ ├── IntervalStepTest.groovy │ │ ├── RangeStepTest.groovy │ │ └── RetainStepTest.groovy │ │ ├── loaders │ │ ├── ElementLoaderTest.groovy │ │ ├── GraphLoaderTest.groovy │ │ ├── IndexLoaderTest.groovy │ │ ├── ObjectLoaderTest.groovy │ │ ├── PipeLoaderTest.groovy │ │ └── SailGraphLoaderTest.groovy │ │ ├── sideeffect │ │ ├── AggregateStepTest.groovy │ │ ├── GroupByStepTest.groovy │ │ ├── GroupCountStepTest.groovy │ │ ├── LinkedStepTest.groovy │ │ ├── SideEffectStepTest.groovy │ │ ├── StoreStepTest.groovy │ │ ├── TableStepTest.groovy │ │ └── TreeStepTest.groovy │ │ └── transform │ │ ├── GatherStepTest.groovy │ │ ├── MapStepTest.groovy │ │ ├── OrderStepTest.groovy │ │ ├── PathStepTest.groovy │ │ ├── SelectStepTest.groovy │ │ ├── TransformStepTest.groovy │ │ └── TraversalStepsTest.groovy │ ├── java │ └── com │ │ └── tinkerpop │ │ └── gremlin │ │ ├── BaseTest.java │ │ └── groovy │ │ └── jsr223 │ │ ├── GremlinGroovyScriptEngineTest.java │ │ └── ScriptExecutorTest.java │ └── resources │ └── com │ └── tinkerpop │ └── gremlin │ └── groovy │ └── jsr223 │ └── GremlinScript.groovy ├── gremlin-java ├── pom.xml └── src │ ├── assembly │ └── distribution.xml │ ├── main │ └── java │ │ └── com │ │ └── tinkerpop │ │ └── gremlin │ │ ├── Imports.java │ │ ├── Tokens.java │ │ ├── Version.java │ │ └── java │ │ ├── GremlinFluentPipeline.java │ │ ├── GremlinFluentUtility.java │ │ ├── GremlinPipeline.java │ │ └── GremlinStartPipe.java │ └── test │ └── java │ └── com │ └── tinkerpop │ └── gremlin │ └── java │ ├── FunctionStepTest.java │ ├── GremlinFluentUtilityTest.java │ ├── GremlinPipelineTest.java │ ├── GremlinStartPipeTest.java │ ├── UtilitiesTest.java │ ├── branch │ ├── IfThenElseStepTest.java │ ├── LoopStepTest.java │ └── SplitMergeStepsTest.java │ ├── filter │ ├── BackStepTest.java │ ├── DedupStepTest.java │ ├── ExceptStepTest.java │ ├── FilterStepTest.java │ ├── HasNotStepTest.java │ ├── HasStepTest.java │ ├── IntervalStepTest.java │ ├── RangeStepTest.java │ └── RetainStepTest.java │ ├── sideeffect │ ├── AggregateStepTest.java │ ├── GroupByStepTest.java │ ├── GroupCountStepTest.java │ ├── LinkedStepTest.java │ ├── SideEffectStepTest.java │ ├── StoreStepTest.java │ ├── TableStepTest.java │ └── TreeStepTest.java │ └── transform │ ├── GatherStepTest.java │ ├── MapStepTest.java │ ├── OrderStepTest.java │ ├── PathStepTest.java │ ├── SelectStepTest.java │ ├── TransformStepTest.java │ └── TraversalStepsTest.java ├── gremlin-test ├── pom.xml └── src │ ├── assembly │ └── distribution.xml │ └── main │ └── java │ └── com │ └── tinkerpop │ └── gremlin │ └── test │ ├── ComplianceTest.java │ ├── FunctionStepTest.java │ ├── UtilitiesTest.java │ ├── branch │ ├── IfThenElseStepTest.java │ ├── LoopStepTest.java │ └── SplitMergeStepsTest.java │ ├── filter │ ├── BackStepTest.java │ ├── DedupStepTest.java │ ├── ExceptStepTest.java │ ├── FilterStepTest.java │ ├── HasNotStepTest.java │ ├── HasStepTest.java │ ├── IntervalStepTest.java │ ├── RangeStepTest.java │ └── RetainStepTest.java │ ├── sideeffect │ ├── AggregateStepTest.java │ ├── GroupByStepTest.java │ ├── GroupCountStepTest.java │ ├── LinkStepTest.java │ ├── SideEffectStepTest.java │ ├── StoreStepTest.java │ ├── TableStepTest.java │ └── TreeStepTest.java │ └── transform │ ├── GatherStepTest.java │ ├── MapStepTest.java │ ├── OrderStepTest.java │ ├── PathStepTest.java │ ├── SelectStepTest.java │ ├── TransformStepTest.java │ └── TraversalStepsTest.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .gremlin_history 3 | target/ 4 | .idea/ 5 | *.iml -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk7 4 | - openjdk7 5 | - openjdk6 6 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-Infinity, TinkerPop [http://tinkerpop.com] 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the TinkerPop nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL TINKERPOP BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | !https://github.com/tinkerpop/gremlin/raw/master/doc/images/gremlin-logo.png! 2 | 3 | 4 | 5 | *IMPORTANT* - TinkerPop is now a part of the Apache Software Foundation and "TinkerPop 3.x":http://tinkerpop.apache.org/ is the latest incarnation of The TinkerPop. This project is TinkerPop 2.x and is no longer active. 6 | 7 | Gremlin is a domain specific language for traversing property "graphs":http://en.wikipedia.org/wiki/Graph_%28mathematics%29. Gremlin makes use of "Pipes":http://pipes.tinkerpop.com to perform complex graph traversals. This language has application in the areas of graph query, analysis, and manipulation. Connectors, provided by "Blueprints":http://blueprints.tinkerpop.com, exist for the following graph management systems: 8 | 9 | * Graph database connectivity: 10 | ** "TinkerGraph":https://github.com/tinkerpop/blueprints/wiki/TinkerGraph in-memory graph 11 | ** "Neo4j":http://neo4j.org/ graph database 12 | ** "OrientDB":http://www.orientechnologies.com/ graph database 13 | ** "Sparksee":http://www.sparsity-technologies.com/#sparksee graph database 14 | ** "Titan":http://thinkaurelius.github.com/titan/ graph database 15 | ** "Faunus":http://thinkaurelius.github.com/faunus/ graph analytics engine 16 | ** "InfiniteGraph":http://www.objectivity.com/products/infinitegraph/ graph database 17 | ** "Rexster":http://rexster.tinkerpop.com graph server 18 | ** "Sesame 2.x":http://www.openrdf.org compliant RDF stores 19 | ** Many "third-party":https://github.com/tinkerpop/blueprints/wiki Blueprints implementations 20 | 21 | * JVM language connectivity: 22 | ** "Java":http://java.com/: Gremlin in the Java Language 23 | ** "Groovy":http://groovy.codehaus.org/: Gremlin in the Groovy Language 24 | ** Easy to connect to other "JVM languages":http://en.wikipedia.org/wiki/List_of_JVM_languages 25 | 26 | The documentation for Gremlin can be found at this "location":http://gremlin.tinkerpop.com. Finally, please visit "TinkerPop":http://tinkerpop.com for other software products. 27 | -------------------------------------------------------------------------------- /bin/gremlin.bat: -------------------------------------------------------------------------------- 1 | :: Windows launcher script for Gremlin 2 | @echo off 3 | 4 | cd %CD%\..\gremlin-groovy\target\ 5 | 6 | set TARGET= 7 | 8 | for /f "tokens=*" %%a in ('dir /b /ad') do ( 9 | if exist "%%a\bin\gremlin.bat" set TARGET=%%a 10 | ) 11 | 12 | cd %TARGET%\bin\ 13 | call gremlin.bat %* -------------------------------------------------------------------------------- /bin/gremlin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | `dirname $0`/../gremlin-groovy/bin/gremlin.sh $@ 4 | -------------------------------------------------------------------------------- /data/graph-example-1.json: -------------------------------------------------------------------------------- 1 | { 2 | "vertices":[ 3 | {"name":"marko","age":29,"_id":1,"_type":"vertex"}, 4 | {"name":"vadas","age":27,"_id":2,"_type":"vertex"}, 5 | {"name":"lop","lang":"java","_id":3,"_type":"vertex"}, 6 | {"name":"josh","age":32,"_id":4,"_type":"vertex"}, 7 | {"name":"ripple","lang":"java","_id":5,"_type":"vertex"}, 8 | {"name":"peter","age":35,"_id":6,"_type":"vertex"} 9 | ], 10 | "edges":[ 11 | {"weight":0.5,"_id":7,"_type":"edge","_outV":1,"_inV":2,"_label":"knows"}, 12 | {"weight":1.0,"_id":8,"_type":"edge","_outV":1,"_inV":4,"_label":"knows"}, 13 | {"weight":0.4,"_id":9,"_type":"edge","_outV":1,"_inV":3,"_label":"created"}, 14 | {"weight":1.0,"_id":10,"_type":"edge","_outV":4,"_inV":5,"_label":"created"}, 15 | {"weight":0.4,"_id":11,"_type":"edge","_outV":4,"_inV":3,"_label":"created"}, 16 | {"weight":0.2,"_id":12,"_type":"edge","_outV":6,"_inV":3,"_label":"created"} 17 | ] 18 | } -------------------------------------------------------------------------------- /data/graph-example-1.ntriple: -------------------------------------------------------------------------------- 1 | . 2 | . 3 | . 4 | 5 | . 6 | . 7 | 8 | . 9 | 10 | "marko"^^ . 11 | "29"^^ . 12 | 13 | "vadas"^^ . 14 | "27"^^ . 15 | 16 | "lop"^^ . 17 | "java"^^ . 18 | 19 | "josh"^^ . 20 | "32"^^ . 21 | 22 | "ripple"^^ . 23 | "java"^^ . 24 | 25 | "peter"^^ . 26 | "35"^^ . -------------------------------------------------------------------------------- /data/graph-example-1.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | marko 13 | 29 14 | 15 | 16 | vadas 17 | 27 18 | 19 | 20 | lop 21 | java 22 | 23 | 24 | josh 25 | 32 26 | 27 | 28 | ripple 29 | java 30 | 31 | 32 | peter 33 | 35 34 | 35 | 36 | 0.5 37 | 38 | 39 | 1.0 40 | 41 | 42 | 0.4 43 | 44 | 45 | 1.0 46 | 47 | 48 | 0.4 49 | 50 | 51 | 0.2 52 | 53 | 54 | -------------------------------------------------------------------------------- /doc/Acknowledgments.textile: -------------------------------------------------------------------------------- 1 | [[https://github.com/tinkerpop/gremlin/raw/master/doc/images/gremlin-standing-small.png]] 2 | 3 | This section provides a list of the people that have contributed in some way to the creation of Gremlin. 4 | 5 | # "Marko A. Rodriguez":http://markorodriguez.com -- designed, developed, tested, and documented Gremlin. 6 | # "Pavel Yaskevich":http://github.com/xedin -- designed and developed Gremlin 0.5 compiler and virtual machine. 7 | # "Darrick Wiebe":http://ofallpossibleworlds.wordpress.com/ -- inspired many of Gremlin 0.7+ developments. 8 | # "Peter Neubauer":http://www.linkedin.com/in/neubauer -- aided in the design and the evangelizing of Gremlin. 9 | # "Joshua Shinavier":http://fortytwo.net -- inspired early design choices. 10 | # "Ketrina Yim":http://www.ketrinayim.com/ -- designed the Gremlin logo. 11 | # "Pierre De Wilde":http://www.linkedin.com/in/pierredewilde -- designs and tests new features. 12 | 13 | Please review Gremlin's "pom.xml":http://github.com/tinkerpop/gremlin/blob/master/pom.xml. Gremlin would not be possible without the work done by others to create these useful packages. 14 | 15 | Join the Gremlin users group at "http://groups.google.com/group/gremlin-users":http://groups.google.com/group/gremlin-users. -------------------------------------------------------------------------------- /doc/Defining-a-More-Complex-Property-Graph.textile: -------------------------------------------------------------------------------- 1 | The documentation up to this point has been using examples from a simple toy graph of 6 vertices and 6 edges. For this section, a more complicated graph structure is used in the examples. A clipped representation (i.e. low weighted edges removed) of this graph is diagrammed below. This graph is a representation of the American band, the "Grateful Dead":http://en.wikipedia.org/wiki/Grateful_Dead. 2 | 3 | !https://github.com/tinkerpop/gremlin/raw/master/doc/images/graph-example-2.jpg! 4 | 5 | More information about this data set can be found in the following article. 6 | 7 | Rodriguez, M.A., Gintautas, V., Pepe, A., "A Grateful Dead Analysis: The Relationship Between Concert and Listening Behavior":http://arxiv.org/abs/0807.2466, First Monday, volume 14, number 1, University of Illinois at Chicago Library, January 2009. 8 | 9 | ```text 10 | g = new TinkerGraph() 11 | g.loadGraphML('data/graph-example-2.xml') 12 | ``` 13 | 14 | In the above Grateful Dead graph, there are vertices and there are edges. The vertices are broken into two sets: songs (e.g. "Dark Star":http://en.wikipedia.org/wiki/Dark_Star_%28song%29, "China Cat Sunflower":http://en.wikipedia.org/wiki/China_Cat_Sunflower) and artists (e.g. "Jerry Garcia":http://en.wikipedia.org/wiki/Jerry_Garcia, "Robert Hunter":http://en.wikipedia.org/wiki/Robert_Hunter_%28lyricist%29). The following itemization describes the properties associated with vertices and edges. 15 | 16 | # vertices 17 | ** song vertices 18 | **** type (string): always 'song' for song vertices. 19 | **** name (string): the name of the song. 20 | **** performances (integer): the number of times the song was played in concert. 21 | **** song_type (string): whether the song is a 'cover' song or an 'original'. 22 | ** artist vertices 23 | **** type (string): always 'artist' for artist vertices. 24 | **** name (string): the name of the artist. 25 | # edges 26 | ** followed_by (song -> song): if the tail song was followed by the head song in concert. 27 | **** weight (integer): the number of times these two songs were paired in concert. 28 | ** sung_by (song -> artist): if the tail song was primarily sung by the head artist. 29 | ** written_by (song -> artist): if the tail song was written by the head artist. 30 | -------------------------------------------------------------------------------- /doc/Defining-a-Property-Graph.textile: -------------------------------------------------------------------------------- 1 | Gremlin was designed specifically for the analysis and manipulation of key/value-based, directed, multi-relational graphs. This long term refers to a type of graph data structure that has certain features. These features are described as follows. The first term, key/value, refers to the fact that both vertices and edges can have any number of properties associated with them. The second term, directed, refers to the fact that the edges in the graph have a directionality -- that is, there is a tail and head to each edge. Finally, the third term, multi-relational, refers to the fact that there can many types of edges and thus, many types of relationships can exist between the vertices. For the remainder of this documentation, and for the sake of brevity, these types of graphs will be called *property graphs*. A property graph is demonstrated in the following example. This diagrammed property graph comes with the Gremlin distribution in "GraphML":http://graphml.graphdrawing.org/ format at @data/graph-example-1.xml@ (see "graph-example-1.xml":https://github.com/tinkerpop/gremlin/blob/master/data/graph-example-1.xml) or GraphSON at @data/graph-example-1.json@ (see "graph-example-1.json":https://github.com/tinkerpop/gremlin/blob/master/data/graph-example-1.json) 2 | 3 | !https://github.com/tinkerpop/gremlin/raw/master/doc/images/graph-example-1.jpg! 4 | 5 | A property graph has these elements: 6 | # a set of vertices 7 | ** each vertex has a unique identifier. 8 | ** each vertex has a set of outgoing edges. 9 | ** each vertex has a set of incoming edges. 10 | ** each vertex has a collection of properties defined by a map from key to value. 11 | # a set of edges 12 | ** each edge has a unique identifier. 13 | ** each edge has an outgoing tail vertex. 14 | ** each edge has an incoming head vertex. 15 | ** each edge has a label that denotes the type of relationship between its two vertices. 16 | ** each edge has a collection of properties defined by a map from key to value. 17 | 18 | Learn more about the property graph data model from "Blueprints":http://blueprints.tinkerpop.com. 19 | 20 | !https://github.com/tinkerpop/blueprints/raw/master/doc/images/blueprints-logo.png!:http://blueprints.tinkerpop.com -------------------------------------------------------------------------------- /doc/Downloads.textile: -------------------------------------------------------------------------------- 1 | !https://github.com/tinkerpop/gremlin/raw/master/doc/images/gremlin-logo.png! 2 | [[Release Notes]] for all versions 3 | ==
== 4 | * *Gremlin 2.x* 5 | ** "Gremlin 2.4.0":http://tinkerpop.com/downloads/gremlin/gremlin-groovy-2.4.0.zip 6 | ** "Gremlin 2.3.0":http://tinkerpop.com/downloads/gremlin/gremlin-groovy-2.3.0.zip 7 | ** "Gremlin 2.2.0":http://tinkerpop.com/downloads/gremlin/gremlin-groovy-2.2.0.zip 8 | ** "Gremlin 2.1.0":http://tinkerpop.com/downloads/gremlin/gremlin-groovy-2.1.0.zip 9 | ** "Gremlin 2.0.0":http://tinkerpop.com/downloads/gremlin/gremlin-groovy-2.0.0.zip 10 | 11 | * *Gremlin 1.x* 12 | ** "Gremlin 1.5":http://tinkerpop.com/downloads/gremlin/gremlin-groovy-1.5.zip 13 | ** "Gremlin 1.4":http://tinkerpop.com/downloads/gremlin/gremlin-groovy-1.4.zip 14 | ** "Gremlin 1.3":http://tinkerpop.com/downloads/gremlin/gremlin-1.3.zip 15 | ** "Gremlin 1.2":http://tinkerpop.com/downloads/gremlin/gremlin-1.2.zip 16 | ** "Gremlin 1.1":http://tinkerpop.com/downloads/gremlin/gremlin-1.1.zip 17 | ** "Gremlin 1.0":http://tinkerpop.com/downloads/gremlin/gremlin-1.0.zip 18 | 19 | * *Gremlin 0.x* 20 | ** "Gremlin 0.9":http://tinkerpop.com/downloads/gremlin/gremlin-0.9.zip 21 | ** "Gremlin 0.8":http://tinkerpop.com/downloads/gremlin/gremlin-0.8.zip 22 | ** "Gremlin 0.7":http://tinkerpop.com/downloads/gremlin/gremlin-0.7.zip 23 | ** "Gremlin 0.6":http://tinkerpop.com/downloads/gremlin/gremlin-0.6.zip 24 | ** "Gremlin 0.5.5":http://tinkerpop.com/downloads/gremlin/gremlin-0.5.5.zip 25 | ** "Gremlin 0.5":http://tinkerpop.com/downloads/gremlin/gremlin-0.5.zip 26 | ** "Gremlin 0.2.2":http://tinkerpop.com/downloads/gremlin/gremlin-0.2.2.zip 27 | ** "Gremlin 0.2.1":http://tinkerpop.com/downloads/gremlin/gremlin-0.2.1.zip 28 | ** "Gremlin 0.2":http://tinkerpop.com/downloads/gremlin/gremlin-0.2.zip 29 | ** "Gremlin 0.1":http://tinkerpop.com/downloads/gremlin/gremlin-0.1.zip -------------------------------------------------------------------------------- /doc/Except-Retain-Pattern.textile: -------------------------------------------------------------------------------- 1 | [[https://github.com/tinkerpop/gremlin/raw/master/doc/images/gremlin-kilt.png]] 2 | 3 | In many instances its desirable to traverse to only those elements that have not been seen in a previous step. Specific use cases are: 4 | 5 | * "Who are my friends friends that are not already my friends?" 6 | * "What is liked by the people that like the same things as me that I don't already like?" 7 | 8 | The solution to these types of problems is provided by the except pattern. Its opposite is the retain pattern--only traverse to those vertices that have been seen in a previous step. 9 | 10 | ```text 11 | gremlin> g = TinkerGraphFactory.createTinkerGraph() 12 | ==>tinkergraph[vertices:6 edges:6] 13 | gremlin> g.v(1).out 14 | ==>v[2] 15 | ==>v[3] 16 | ==>v[4] 17 | gremlin> g.v(1).out.out 18 | ==>v[5] 19 | ==>v[3] 20 | ``` 21 | 22 | Both the first and the second emit @v[3]@. To ensure that @v[3]@ is not traversed to on the second step, its necessary to save the results seen after the first @out@. There are three high-level pipes called @aggregate@, @except@, and @retain@. In the examples below, @x@ stores all the values seen up to the @aggregate@ step. Note that, everything in @out@ is "drained" into @x@ before going to the next @out@. 23 | 24 | ```text 25 | gremlin> x = [] 26 | gremlin> g.v(1).out.aggregate(x).out.except(x) 27 | ==>v[5] 28 | ``` 29 | 30 | ```text 31 | gremlin> x = [] 32 | gremlin> g.v(1).out.aggregate(x).out.retain(x) 33 | ==>v[3] 34 | ``` 35 | 36 | With named steps it is possible to @except@ and @retain@ previously (and actually forward) objects in the pipeline. 37 | 38 | ```text 39 | gremlin> g.v(1).as('x').out('created').in('created').except('x') 40 | ==>v[4] 41 | ==>v[6] 42 | ``` -------------------------------------------------------------------------------- /doc/Split-Merge-Pattern.textile: -------------------------------------------------------------------------------- 1 | !https://github.com/tinkerpop/gremlin/raw/master/doc/images/gremlin-kilt.png! 2 | 3 | Most Gremlin pipelines are serial in that one step feeds to the next, so on and so forth. There are situations where it is desirable to split a pipeline and thus, have @n@-parallel steps that are later merged back into a serial flow. To support this type of traversal, there are split and merge steps. 4 | 5 | * Split 6 | ** @copySplit@: copy the incoming object to each pipeline 7 | * Merge 8 | ** @fairMerge@: merge the parallel traversals in a round-robin fashion 9 | ** @exhaustMerge@: merge the parallel traversals by exhaustively getting the objects of the first, then the second, etc. 10 | 11 | ```text 12 | gremlin> g.v(1).out('knows').copySplit(_().out('created').name, _().age).fairMerge 13 | ==>ripple 14 | ==>27 15 | ==>lop 16 | ==>32 17 | gremlin> g.v(1).out('knows').copySplit(_().out('created').name, _().age).exhaustMerge 18 | ==>ripple 19 | ==>lop 20 | ==>27 21 | ==>32 22 | ``` 23 | 24 | A useful representation of the the split/merge pattern is as follows. 25 | 26 | ```text 27 | g.v(1).out('knows').copySplit( 28 | _().out('created').name, 29 | _().age 30 | ).fairMerge 31 | ``` -------------------------------------------------------------------------------- /doc/Step-Closures.textile: -------------------------------------------------------------------------------- 1 | !http://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/Lambda_uc_lc.svg/150px-Lambda_uc_lc.svg.png! 2 | 3 | Many Gremlin steps take a user-defined function (or functions). These steps have the form: 4 | 5 | ``` 6 | step{ // some function } 7 | ``` 8 | 9 | A Gremlin closure/function can take either one or two arguments. If passed one argument, then the argument references the current object passing through the step. For instance: 10 | 11 | ``` 12 | gremlin> g.v(1).out.transform{it.name} 13 | ==>vadas 14 | ==>josh 15 | ==>lop 16 | ``` 17 | 18 | The variable @it@ is a shorthand for naming the argument as follows: 19 | 20 | ``` 21 | gremlin> g.v(1).out.transform{v -> v.name} 22 | ==>vadas 23 | ==>josh 24 | ==>lop 25 | ``` 26 | 27 | If two arguments are passed to the closure, then the second argument represents the variable map of the Gremlin pipeline. When a step is named using @as@, then the last object that has passed through that named step can be accessed in the step closure. For instance: 28 | 29 | ``` 30 | gremlin> g.v(1).out.as('x').out.transform{v,m -> m.x.name + ' ' + v.name} 31 | ==>josh ripple 32 | ==>josh lop 33 | ``` 34 | 35 | The variable @m@ has a @get(String name)@ method which allows getting the value last seen at the particular named step. -------------------------------------------------------------------------------- /doc/Troubleshooting.textile: -------------------------------------------------------------------------------- 1 | When working with Gremlin, there may be issues that arise. This section hopes to articulate common problems users have an how to resolve them. 2 | 3 | h2. Nearly everything is an iterator 4 | 5 | The expression @g.V[0]@ seems like it is returning the first vertex in the graph. However, this statement is in fact creating an iterator/iterable (i.e. a "Pipe":http://pipes.tinkerpop.com) that will return the first vertex in the graph when @next()@ is called on it. Thus, use @g.V[0].next()@ to return the first vertex in the graph. Better yet, just use @g.V.next()@. 6 | 7 | In general, when using the "Gremlin console":https://github.com/tinkerpop/gremlin/wiki/Using-Gremlin-from-the-Command-Line, it is not necessary to call @next()@ as the console will automatically iterate it and @==>@ print the objects of the iterator. However, when using Gremlin in, for example, "Java":https://github.com/tinkerpop/gremlin/wiki/Using-Gremlin-through-Java or "Groovy":https://github.com/tinkerpop/gremlin/wiki/Using-Gremlin-through-Groovy, be sure to iterate the pipe. Note that the [[Gremlin methods]] provide various shorthand mechanisms for this. For example, @iterate()@ will "@while(hasNext())@" and tends to be use consistently. 8 | 9 | h2. When the Gremlin Groovy console is stuck, use clear 10 | 11 | Many times you will misplace a @(@ or a @{@ and your console terminal will be "stuck." To get out of this situation, just type @clear@ to reset the parser. 12 | 13 | ```text 14 | gremlin> if(true) { 15 | gremlin> 1+2 16 | gremlin> { 17 | gremlin> } 18 | gremlin> 1 19 | groovysh_parse: 24: Ambiguous expression could be a parameterless ... 20 | 1 error 21 | gremlin> 1 22 | groovysh_parse: 24: Ambiguous expression could be a parameterless ... 23 | 1 error 24 | gremlin> clear 25 | gremlin> 1 26 | ==>1 27 | ``` -------------------------------------------------------------------------------- /doc/Writing-Gremlin-REPL-Plugins.textile: -------------------------------------------------------------------------------- 1 | Developers who wish to extend the features of the Gremlin REPL can do so by writing a plugin. Common use cases for plugin development include: 2 | 3 | * Not all Blueprints implementations are distributed via the Gremlin distribution. A plugin provides a common way for any Blueprints implementations to be accessible in the REPL. 4 | * Third-party developers who implement Blueprints, may wish to extend the Gremlin language with new features specific to their database. 5 | * Extend the Gremlin language to include a convenient overload to an existing step or include entirely new functions to the language itself. 6 | 7 | Users can load plugins with the @Gremlin.use()@ function which is described in greater detail "here":Using-Gremlin-through-Groovy#use-of-external-jars. 8 | 9 | h2. Writing a Plugin 10 | 11 | To write a plugin, first implement the @com.tinkerpop.gremlin.groovy.console.ConsolePlugin@ interface. It has two methods to implement: @getName@ and @pluginTo@. The @getName@ method simply returns the "name" of the plugin. This name must be unique within the list of plugins loaded to the REPL at any given point. If a naming conflict occurs, the second plugin to be loaded with that name will be ignored. 12 | 13 | The @pluginTo@ method has the following signature: 14 | 15 | ```java 16 | void pluginTo(final ConsoleGroovy groovy, final ConsoleIO io, final Map args); 17 | ``` 18 | 19 | This method gets called when the @Gremlin.use()@ function is called and after all dependencies have been loaded by "Grape":http://groovy.codehaus.org/Grape. The reference to @ConsoleGroovy@ allows the execution of arbitrary Groovy within the context of the REPL. For example, a common function of a plugin would be to auto-import classes for users that are relevant to the plugin: 20 | 21 | ```java 22 | groovy.execute("import org.apache.commons.math3.util.FastMath"); 23 | ``` 24 | 25 | The @ConsoleIO@ argument allows the plugin to write something to the console for the caller to see and the @Map@ argument contains any arguments that were passed to @Gremlin.use()@. 26 | 27 | Once the implementation of the @ConsolePlugin@ has been written, it must be made available such that the @Gremlin.use()@ function can find it at runtime. Gremlin uses "ServiceLoader":http://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html to lookup plugin implementations at runtime. Therefore, to make the implementation known, add a @com.tinkerpop.gremlin.groovy.console.ConsolePlugin@ file to the @META-INF/services@ of the package plugin. The file should list the fully qualified name of the @ConsolePlugin@ class. -------------------------------------------------------------------------------- /doc/images/co-followed_by-example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/co-followed_by-example.jpg -------------------------------------------------------------------------------- /doc/images/co-followed_by.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/co-followed_by.graffle -------------------------------------------------------------------------------- /doc/images/dbpedia-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/dbpedia-logo.png -------------------------------------------------------------------------------- /doc/images/depth-vs-breadth.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/depth-vs-breadth.gif -------------------------------------------------------------------------------- /doc/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/favicon.ico -------------------------------------------------------------------------------- /doc/images/grammar-example-1.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/grammar-example-1.graffle -------------------------------------------------------------------------------- /doc/images/grammar-example-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/grammar-example-1.jpg -------------------------------------------------------------------------------- /doc/images/grammar-map-example-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/grammar-map-example-1.jpg -------------------------------------------------------------------------------- /doc/images/grammar-map-rewrite.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/grammar-map-rewrite.graffle -------------------------------------------------------------------------------- /doc/images/grammar-map-rewrite.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/grammar-map-rewrite.jpg -------------------------------------------------------------------------------- /doc/images/graph-example-1-codeveloper.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/graph-example-1-codeveloper.graffle -------------------------------------------------------------------------------- /doc/images/graph-example-1-rdf.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/graph-example-1-rdf.graffle -------------------------------------------------------------------------------- /doc/images/graph-example-1-rdf.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/graph-example-1-rdf.jpg -------------------------------------------------------------------------------- /doc/images/graph-example-1.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/graph-example-1.graffle -------------------------------------------------------------------------------- /doc/images/graph-example-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/graph-example-1.jpg -------------------------------------------------------------------------------- /doc/images/graph-example-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/graph-example-2.jpg -------------------------------------------------------------------------------- /doc/images/graph-model.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/graph-model.graffle -------------------------------------------------------------------------------- /doc/images/graph-model.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/graph-model.jpg -------------------------------------------------------------------------------- /doc/images/grateful-dead-concert.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/grateful-dead-concert.jpg -------------------------------------------------------------------------------- /doc/images/grateful-dead-concert2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/grateful-dead-concert2.jpg -------------------------------------------------------------------------------- /doc/images/gremlin-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-2.png -------------------------------------------------------------------------------- /doc/images/gremlin-character-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-character-2.png -------------------------------------------------------------------------------- /doc/images/gremlin-character-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-character-3.png -------------------------------------------------------------------------------- /doc/images/gremlin-characters.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-characters.pdf -------------------------------------------------------------------------------- /doc/images/gremlin-chickenwing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-chickenwing.png -------------------------------------------------------------------------------- /doc/images/gremlin-clownin-around.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-clownin-around.png -------------------------------------------------------------------------------- /doc/images/gremlin-grad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-grad.png -------------------------------------------------------------------------------- /doc/images/gremlin-gremalicious.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-gremalicious.png -------------------------------------------------------------------------------- /doc/images/gremlin-gremicide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-gremicide.png -------------------------------------------------------------------------------- /doc/images/gremlin-gremlin-the-grouch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-gremlin-the-grouch.png -------------------------------------------------------------------------------- /doc/images/gremlin-gremlin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-gremlin.png -------------------------------------------------------------------------------- /doc/images/gremlin-gremlivich.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-gremlivich.png -------------------------------------------------------------------------------- /doc/images/gremlin-gremopoly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-gremopoly.png -------------------------------------------------------------------------------- /doc/images/gremlin-gremreaper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-gremreaper.png -------------------------------------------------------------------------------- /doc/images/gremlin-gremstefani.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-gremstefani.png -------------------------------------------------------------------------------- /doc/images/gremlin-hardhat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-hardhat.png -------------------------------------------------------------------------------- /doc/images/gremlin-inthewild.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-inthewild.png -------------------------------------------------------------------------------- /doc/images/gremlin-kilt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-kilt.png -------------------------------------------------------------------------------- /doc/images/gremlin-lab-coat.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-lab-coat.pdf -------------------------------------------------------------------------------- /doc/images/gremlin-lab-coat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-lab-coat.png -------------------------------------------------------------------------------- /doc/images/gremlin-logo.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-logo.graffle -------------------------------------------------------------------------------- /doc/images/gremlin-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-logo.png -------------------------------------------------------------------------------- /doc/images/gremlin-logo_inv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-logo_inv.png -------------------------------------------------------------------------------- /doc/images/gremlin-new-sheriff-in-town.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-new-sheriff-in-town.png -------------------------------------------------------------------------------- /doc/images/gremlin-no-more-mr-nice-guy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-no-more-mr-nice-guy.png -------------------------------------------------------------------------------- /doc/images/gremlin-on-the-case.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-on-the-case.png -------------------------------------------------------------------------------- /doc/images/gremlin-painting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-painting.png -------------------------------------------------------------------------------- /doc/images/gremlin-pipe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-pipe.png -------------------------------------------------------------------------------- /doc/images/gremlin-running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-running.png -------------------------------------------------------------------------------- /doc/images/gremlin-standing-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-standing-small.png -------------------------------------------------------------------------------- /doc/images/gremlin-standing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-standing.png -------------------------------------------------------------------------------- /doc/images/gremlin-without-a-cause.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-without-a-cause.pdf -------------------------------------------------------------------------------- /doc/images/gremlin-without-a-cause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-without-a-cause.png -------------------------------------------------------------------------------- /doc/images/gremlin-xmas-alpha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlin-xmas-alpha.png -------------------------------------------------------------------------------- /doc/images/gremlindocs-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlindocs-logo.png -------------------------------------------------------------------------------- /doc/images/gremlindocs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlindocs.pdf -------------------------------------------------------------------------------- /doc/images/gremlindocs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/gremlindocs.png -------------------------------------------------------------------------------- /doc/images/jerry-followed_by-example.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/jerry-followed_by-example.graffle -------------------------------------------------------------------------------- /doc/images/jerry-followed_by-example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/jerry-followed_by-example.jpg -------------------------------------------------------------------------------- /doc/images/jerry-garcia.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/jerry-garcia.jpg -------------------------------------------------------------------------------- /doc/images/ldsail-arch.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/ldsail-arch.graffle -------------------------------------------------------------------------------- /doc/images/ldsail-arch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/ldsail-arch.jpg -------------------------------------------------------------------------------- /doc/images/lod-cloud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/lod-cloud.png -------------------------------------------------------------------------------- /doc/images/rdf-graph-model.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/rdf-graph-model.graffle -------------------------------------------------------------------------------- /doc/images/rdf-graph-model.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/rdf-graph-model.jpg -------------------------------------------------------------------------------- /doc/images/rdf-logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/rdf-logo.gif -------------------------------------------------------------------------------- /doc/images/sql2gremlin-logo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/sql2gremlin-logo.pdf -------------------------------------------------------------------------------- /doc/images/sql2gremlin-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/sql2gremlin-logo.png -------------------------------------------------------------------------------- /doc/images/structures-processes.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/structures-processes.graffle -------------------------------------------------------------------------------- /doc/images/structures-processes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/structures-processes.jpg -------------------------------------------------------------------------------- /doc/images/tinkerpop-logo-small.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinkerpop/gremlin/b0eb5575c4ecb241a87805e2dc51d5142510018f/doc/images/tinkerpop-logo-small.jpg -------------------------------------------------------------------------------- /gremlin-groovy/bin/gremlin.bat: -------------------------------------------------------------------------------- 1 | :: Windows launcher script for Gremlin 2 | @echo off 3 | 4 | cd %CD%\..\target\ 5 | 6 | set TARGET= 7 | 8 | for /f "tokens=*" %%a in ('dir /b /ad') do ( 9 | if exist "%%a\bin\gremlin.bat" set TARGET=%%a 10 | ) 11 | 12 | cd %TARGET%\bin\ 13 | call gremlin.bat %* 14 | -------------------------------------------------------------------------------- /gremlin-groovy/bin/gremlin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | `dirname $0`/../target/gremlin-*-standalone/bin/gremlin.sh $@ -------------------------------------------------------------------------------- /gremlin-groovy/src/assembly/distribution.xml: -------------------------------------------------------------------------------- 1 | 2 | distribution 3 | 4 | zip 5 | 6 | 7 | 8 | 0775 9 | target/${project.artifactId}-${project.version}-standalone/bin 10 | bin 11 | 12 | *.sh 13 | *.bat 14 | 15 | 16 | 17 | src 18 | 19 | 20 | ../doc 21 | 22 | 26 | 27 | target/${project.artifactId}-${project.version}-standalone/lib 28 | lib 29 | 30 | 31 | 32 | 33 | pom.xml 34 | src 35 | 36 | 37 | ../data/graph-example-1.json 38 | data 39 | 40 | 41 | ../data/graph-example-1.ntriple 42 | data 43 | 44 | 45 | ../data/graph-example-1.xml 46 | data 47 | 48 | 49 | ../data/graph-example-2.xml 50 | data 51 | 52 | 53 | ../LICENSE.txt 54 | / 55 | 56 | 57 | ../CHANGELOG.textile 58 | / 59 | 60 | 61 | src/main/bin/README.txt 62 | / 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /gremlin-groovy/src/assembly/standalone.xml: -------------------------------------------------------------------------------- 1 | 2 | standalone 3 | 4 | dir 5 | 6 | false 7 | 8 | 9 | 10 | src/main/bin 11 | /bin 12 | 0755 13 | 14 | 15 | target/*.jar 16 | /lib 17 | 18 | 19 | 20 | 21 | 22 | /lib 23 | false 24 | compile 25 | 26 | 27 | /lib 28 | false 29 | provided 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/bin/README.txt: -------------------------------------------------------------------------------- 1 | -= Gremlin: A Graph Traversal Language =- 2 | 3 | Gremlin is a domain specific language for traversing property graphs. 4 | Gremlin makes use of a path-based syntax to support complex graph traversals. 5 | Gremlin has application in the areas of graph query, analysis, and manipulation. 6 | 7 | Gremlin connects to various graph databases including: 8 | * TinkerGraph 9 | * Neo4j 10 | * OrientDB 11 | * DEX 12 | * InfiniteGraph 13 | * Titan 14 | * Rexster 15 | * Sail RDF Stores 16 | 17 | Gremlin documentation can be found online at: 18 | http://gremlin.tinkerpop.com 19 | 20 | --------------- RUNNING GREMLIN --------------- 21 | 22 | gremlin$ bin/gremlin.sh 23 | 24 | \,,,/ 25 | (o o) 26 | -----oOOo-(_)-oOOo----- 27 | gremlin> g = TinkerGraphFactory.createTinkerGraph() 28 | ==>tinkergraph[vertices:6 edges:6] 29 | gremlin> g.v(1) 30 | ==>v[1] 31 | gremlin> g.v(1).name 32 | ==>marko 33 | gremlin> g.v(1).out('knows').name 34 | ==>vadas 35 | ==>josh 36 | 37 | NOTE: TinkerGraphFactory.createTinkerGraph() returns a hardcoded toy graph for the purposes of demonstration. 38 | 39 | ----------------------------------------------- 40 | 41 | Gremlin is provided by TinkerPop [http://tinkerpop.com] 42 | "Open Source Software Products in the Graph Space" -------------------------------------------------------------------------------- /gremlin-groovy/src/main/bin/gremlin.bat: -------------------------------------------------------------------------------- 1 | :: Windows launcher script for Gremlin Groovy 2 | 3 | @echo off 4 | 5 | ::cd ..\lib 6 | 7 | ::set LIBDIR=%CD% 8 | 9 | set LIBDIR=..\lib 10 | 11 | set OLD_CLASSPATH=%CLASSPATH% 12 | set CP= 13 | 14 | for %%i in (%LIBDIR%\*.jar) do call :concatsep %%i 15 | 16 | :: cd ..\..\..\ 17 | 18 | set JAVA_OPTIONS=-Xms32m -Xmx512m 19 | 20 | :: Launch the application 21 | 22 | if "%1" == "" goto console 23 | if "%1" == "-e" goto script 24 | if "%1" == "-v" goto version 25 | 26 | :console 27 | 28 | set CLASSPATH=%CP%;%OLD_CLASSPATH% 29 | java %JAVA_OPTIONS% %JAVA_ARGS% com.tinkerpop.gremlin.groovy.console.Console %* 30 | 31 | set CLASSPATH=%OLD_CLASSPATH% 32 | goto :eof 33 | 34 | :script 35 | 36 | set strg= 37 | 38 | FOR %%X IN (%*) DO ( 39 | CALL :concat %%X %1 %2 40 | ) 41 | 42 | set CLASSPATH=%CP%;%OLD_CLASSPATH% 43 | java %JAVA_OPTIONS% %JAVA_ARGS% com.tinkerpop.gremlin.groovy.jsr223.ScriptExecutor %strg% 44 | set CLASSPATH=%OLD_CLASSPATH% 45 | goto :eof 46 | 47 | :version 48 | 49 | set CLASSPATH=%CP%;%OLD_CLASSPATH% 50 | java %JAVA_OPTIONS% %JAVA_ARGS% com.tinkerpop.gremlin.Version 51 | 52 | set CLASSPATH=%OLD_CLASSPATH% 53 | goto :eof 54 | 55 | :concat 56 | 57 | if %1 == %2 goto skip 58 | 59 | SET strg=%strg% %1 60 | 61 | :concatsep 62 | 63 | if "%CP%" == "" ( 64 | set CP=%LIBDIR%\%1 65 | )else ( 66 | set CP=%CP%;%LIBDIR%\%1 67 | ) 68 | 69 | :skip 70 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/bin/gremlin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | case `uname` in 4 | CYGWIN*) 5 | CP=$( echo `dirname $0`/../lib/*.jar . | sed 's/ /;/g') 6 | ;; 7 | *) 8 | CP=$( echo `dirname $0`/../lib/*.jar . | sed 's/ /:/g') 9 | esac 10 | #echo $CP 11 | 12 | # Find Java 13 | if [ "$JAVA_HOME" = "" ] ; then 14 | JAVA="java -server" 15 | else 16 | JAVA="$JAVA_HOME/bin/java -server" 17 | fi 18 | 19 | # Set Java options 20 | if [ "$JAVA_OPTIONS" = "" ] ; then 21 | JAVA_OPTIONS="-Xms32m -Xmx512m" 22 | fi 23 | 24 | # Launch the application 25 | if [ "$1" = "-e" ]; then 26 | k=$2 27 | if [ $# -gt 2 ]; then 28 | for (( i=3 ; i < $# + 1 ; i++ )) 29 | do 30 | eval a=\${${i}} 31 | k="$k \"$a\"" 32 | done 33 | fi 34 | 35 | eval $JAVA $JAVA_OPTIONS -cp $CP:$CLASSPATH com.tinkerpop.gremlin.groovy.jsr223.ScriptExecutor $k 36 | else 37 | if [ "$1" = "-v" ]; then 38 | exec $JAVA $JAVA_OPTIONS -cp $CP:$CLASSPATH com.tinkerpop.gremlin.Version 39 | else 40 | exec $JAVA $JAVA_OPTIONS -cp $CP:$CLASSPATH com.tinkerpop.gremlin.groovy.console.Console $@ 41 | fi 42 | fi 43 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/groovy/com/tinkerpop/gremlin/groovy/loaders/ElementLoader.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.loaders 2 | 3 | import com.tinkerpop.blueprints.Edge 4 | import com.tinkerpop.blueprints.Element 5 | import com.tinkerpop.blueprints.Vertex 6 | import com.tinkerpop.gremlin.groovy.Gremlin 7 | import com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | class ElementLoader { 13 | 14 | public static void load() { 15 | 16 | Element.metaClass.propertyMissing = { final String name, final def value -> 17 | ((Element) delegate).setProperty(name, value) 18 | } 19 | 20 | Element.metaClass.methodMissing = { final String name, final def args -> 21 | if (Gremlin.isStep(name)) { 22 | return new GremlinGroovyPipeline(delegate)."$name"(* args) 23 | } else { 24 | throw new MissingMethodException(name, delegate.getClass()); 25 | } 26 | } 27 | 28 | Element.metaClass.propertyMissing = { final String name -> 29 | if (Gremlin.isStep(name)) { 30 | return new GremlinGroovyPipeline(delegate)."$name"() 31 | } else { 32 | return ((Element) delegate).getProperty(name) 33 | } 34 | } 35 | 36 | Element.metaClass.map = { 37 | final Map map = new HashMap(); 38 | for (final String key : ((Element) delegate).getPropertyKeys()) { 39 | map.put(key, ((Element) delegate).getProperty(key)) 40 | } 41 | return map; 42 | } 43 | 44 | Element.metaClass.keys = { 45 | return ((Element) delegate).getPropertyKeys() 46 | } 47 | 48 | Element.metaClass.values = { 49 | final List values = new ArrayList(); 50 | for (final String key : ((Element) delegate).getPropertyKeys()) { 51 | values.add(((Element) delegate).getProperty(key)) 52 | } 53 | return values; 54 | } 55 | 56 | // for Vertex only 57 | 58 | Vertex.metaClass.addEdge = { final String label, final Vertex inVertex, final Map properties -> 59 | final Edge edge = ((Vertex) delegate).addEdge(label, inVertex); 60 | for (final Map.Entry entry : properties.entrySet()) { 61 | edge.setProperty(entry.getKey(), entry.getValue()); 62 | } 63 | return edge; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/groovy/com/tinkerpop/gremlin/groovy/loaders/IndexLoader.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.loaders 2 | 3 | import com.tinkerpop.blueprints.Index 4 | import com.tinkerpop.blueprints.IndexableGraph 5 | import com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline 6 | 7 | /** 8 | * @author Marko A. Rodriguez (http://markorodriguez.com) 9 | */ 10 | class IndexLoader { 11 | 12 | public static void load() { 13 | 14 | IndexableGraph.metaClass.idx = { final Object indexName -> 15 | return ((IndexableGraph) delegate).getIndices().find { it.getIndexName().equals(indexName) } 16 | } 17 | 18 | Index.metaClass.getAt = { final Map query -> 19 | final Map.Entry entry = (Map.Entry) query.iterator().next(); 20 | return new GremlinGroovyPipeline().start((((Index) delegate).get((String) entry.getKey(), entry.getValue()))); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/groovy/com/tinkerpop/gremlin/groovy/loaders/ObjectLoader.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.loaders 2 | 3 | import com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline 4 | import com.tinkerpop.gremlin.groovy.GroovyPipeFunction 5 | import com.tinkerpop.pipes.util.structures.Row 6 | import com.tinkerpop.pipes.util.structures.Table 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class ObjectLoader { 12 | 13 | public static void load() { 14 | 15 | Object.metaClass._ = { final Closure closure -> 16 | return new GremlinGroovyPipeline(delegate.iterator()); 17 | } 18 | 19 | Map.metaClass.getAt = { final IntRange range -> 20 | final int size = delegate.size(); 21 | int high = Math.min(size - 1, range.max()); 22 | int low = Math.max(0, range.min()); 23 | 24 | final Map tempMap = new LinkedHashMap(); 25 | int c = 0; 26 | for (final Map.Entry entry : delegate.entrySet()) { 27 | if (c >= low && c <= high) { 28 | tempMap.put(entry.getKey(), entry.getValue()); 29 | } 30 | if (c > high) { 31 | break; 32 | } 33 | c++; 34 | 35 | } 36 | return tempMap; 37 | 38 | 39 | } 40 | 41 | Table.metaClass.apply = { final Closure... closures -> 42 | return ((Table) delegate).apply(GroovyPipeFunction.generate(closures)); 43 | 44 | } 45 | 46 | Table.metaClass.unique = { final Closure closure -> 47 | final Table temp = Table.cloneTableStructure((Table) delegate); 48 | for (final Row row : delegate.iterator().unique(closure)) { 49 | temp.addRow(row); 50 | } 51 | return temp; 52 | } 53 | 54 | Table.metaClass.sort = { final Closure closure -> 55 | final Table temp = Table.cloneTableStructure((Table) delegate); 56 | for (final Row row : delegate.iterator().sort(closure)) { 57 | temp.addRow(row); 58 | } 59 | return temp; 60 | } 61 | 62 | List.metaClass.isSimple = { 63 | return new HashSet(((List) delegate)).size() == ((List) delegate).size() 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/main/groovy/com/tinkerpop/gremlin/groovy/loaders/PipeLoader.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.loaders 2 | 3 | import com.tinkerpop.gremlin.groovy.Gremlin 4 | import com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline 5 | import com.tinkerpop.pipes.util.PipeHelper 6 | 7 | /** 8 | * @author Marko A. Rodriguez (http://markorodriguez.com) 9 | */ 10 | class PipeLoader { 11 | 12 | public static void load() { 13 | 14 | GremlinGroovyPipeline.metaClass.propertyMissing = { final String name -> 15 | if (Gremlin.isStep(name)) { 16 | return delegate."$name"(); 17 | } else { 18 | return ((GremlinGroovyPipeline) delegate).property(name); 19 | } 20 | } 21 | 22 | [Iterable, Iterator].each { 23 | it.metaClass.count = { 24 | return PipeHelper.counter(delegate.iterator()); 25 | } 26 | } 27 | 28 | [Iterable, Iterator].each { 29 | it.metaClass.mean = { 30 | double counter = 0; 31 | double sum = 0; 32 | delegate.each { counter++; sum += it; } 33 | return sum / counter; 34 | } 35 | } 36 | 37 | GremlinGroovyPipeline.metaClass.getAt = { final Integer index -> 38 | return ((GremlinGroovyPipeline) delegate).range(index, index); 39 | } 40 | 41 | 42 | GremlinGroovyPipeline.metaClass.getAt = { final Range range -> 43 | return ((GremlinGroovyPipeline) delegate).range(range.getFrom() as Integer, range.getTo() as Integer); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/groovy/com/tinkerpop/gremlin/groovy/loaders/SailGraphLoader.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.loaders 2 | 3 | import com.tinkerpop.blueprints.impls.sail.SailGraph 4 | 5 | /** 6 | * @author Marko A. Rodriguez (http://markorodriguez.com) 7 | */ 8 | class SailGraphLoader { 9 | 10 | public static void load() { 11 | 12 | SailGraph.metaClass.uri { final String prefix -> 13 | return ((SailGraph) delegate).expandPrefix(prefix) 14 | } 15 | 16 | SailGraph.metaClass.qn { final String uri -> 17 | return ((SailGraph) delegate).prefixNamespace(uri) 18 | } 19 | 20 | SailGraph.metaClass.loadRDF = { final def fileObject, final String format -> 21 | try { 22 | ((SailGraph) delegate).loadRDF(new URL(fileObject).openStream(), "", format, null); 23 | } catch (MalformedURLException e) { 24 | ((SailGraph) delegate).loadRDF(new FileInputStream(fileObject), "", format, null); 25 | } 26 | } 27 | 28 | SailGraph.metaClass.saveRDF = { final def fileObject, final String format -> 29 | if (fileObject instanceof String) { 30 | ((SailGraph) delegate).saveRDF(new FileOutputStream(new File(fileObject)), format); 31 | } else if (fileObject instanceof File) { 32 | ((SailGraph) delegate).saveRDF(new FileOutputStream(fileObject), format); 33 | } else if (fileObject instanceof OutputStream) { 34 | ((SailGraph) delegate).saveRDF(fileObject, format); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/java/com/tinkerpop/gremlin/groovy/GroovyPipeFunction.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy; 2 | 3 | import com.tinkerpop.pipes.PipeFunction; 4 | import com.tinkerpop.pipes.util.PipesFunction; 5 | import com.tinkerpop.pipes.util.structures.AsMap; 6 | import groovy.lang.Closure; 7 | 8 | /** 9 | * GroovyPipeFunction wraps a Groovy Closure in a PipeFunction. 10 | * If used within the context of a GremlinGroovyPipeline, the AsMap is the second argument of the function. 11 | * 12 | * @author Marko A. Rodriguez (http://markorodriguez.com) 13 | */ 14 | public class GroovyPipeFunction extends PipesFunction { 15 | 16 | private final Closure closure; 17 | private final boolean doAsMap; 18 | 19 | public GroovyPipeFunction(final AsMap asMap, final Closure closure) { 20 | this.closure = closure; 21 | this.setAsMap(asMap); 22 | this.doAsMap = null != this.asMap && this.closure.getParameterTypes().length > 1; 23 | } 24 | 25 | public GroovyPipeFunction(final Closure closure) { 26 | this(null, closure); 27 | } 28 | 29 | public B compute(final A argument) { 30 | return this.doAsMap ? (B) this.closure.call(argument, this.asMap) : (B) this.closure.call(argument); 31 | } 32 | 33 | public static PipeFunction[] generate(final AsMap asMap, final Closure... closures) { 34 | final PipeFunction[] pipeFunctions = new PipeFunction[closures.length]; 35 | for (int i = 0; i < closures.length; i++) { 36 | pipeFunctions[i] = new GroovyPipeFunction(asMap, closures[i]); 37 | } 38 | return pipeFunctions; 39 | } 40 | 41 | public static PipeFunction[] generate(final Closure... closures) { 42 | final PipeFunction[] pipeFunctions = new PipeFunction[closures.length]; 43 | for (int i = 0; i < closures.length; i++) { 44 | pipeFunctions[i] = new GroovyPipeFunction(null, closures[i]); 45 | } 46 | return pipeFunctions; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/java/com/tinkerpop/gremlin/groovy/console/ConsoleGroovy.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.console; 2 | 3 | import org.codehaus.groovy.tools.shell.Groovysh; 4 | 5 | /** 6 | * Wrapper for the Groovysh class that gets passed to a plugin. 7 | * 8 | * @author Stephen Mallette (http://stephen.genoprime.com) 9 | */ 10 | public class ConsoleGroovy { 11 | private final Groovysh groovysh; 12 | 13 | public ConsoleGroovy(final Groovysh groovysh) { 14 | this.groovysh = groovysh; 15 | } 16 | 17 | /** 18 | * Execute some groovy in the REPL. For plugin developers, this is typically use to execute import statements 19 | * for classes that should be available in the REPL so that the user does not need to type the entire 20 | * package name. 21 | */ 22 | public Object execute(final String line) { 23 | return this.groovysh.execute(line); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/java/com/tinkerpop/gremlin/groovy/console/ConsolePlugin.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.console; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * Those wanting to extend the Gremlin Console can extend this class to provide custom imports and extension 7 | * methods to the language itself. Gremlin Console uses ServiceLoader to install plugins. It is necessary for 8 | * projects wishing to extend the Console to include a com.tinkerpop.gremlin.groovy.console.ConsolePlugin file in 9 | * META-INF/services of their packaged project which includes the full class names of the implementations of this 10 | * interface to install. 11 | * 12 | * @author Stephen Mallette (http://stephen.genoprime.com) 13 | */ 14 | public interface ConsolePlugin { 15 | 16 | /** 17 | * The name of the plugin. This name should be unique as naming clashes will prevent proper plugin operations. 18 | */ 19 | String getName(); 20 | 21 | /** 22 | * Implementors will typically execute imports of classes within their project that they want available in the 23 | * console. They may use groovy meta programming to introduce new extensions to the Gremlin. 24 | * 25 | * @param args Arbitrary arguments passed from the caller of Gremlin.use() to be used as the plugin sees fit. 26 | */ 27 | void pluginTo(final ConsoleGroovy groovy, final ConsoleIO io, final Map args); 28 | } 29 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/java/com/tinkerpop/gremlin/groovy/console/ErrorHookClosure.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.console; 2 | 3 | import groovy.lang.Closure; 4 | import org.codehaus.groovy.tools.shell.IO; 5 | 6 | import java.io.BufferedReader; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class ErrorHookClosure extends Closure { 12 | 13 | private final IO io; 14 | 15 | public ErrorHookClosure(final Object owner, final IO io) { 16 | super(owner); 17 | this.io = io; 18 | } 19 | 20 | public Object call(final Object[] args) { 21 | if (args.length > 0) { 22 | try { 23 | final Throwable e = (Throwable) args[0]; 24 | String message = e.getMessage(); 25 | if (null != message) { 26 | message = message.replace("startup failed:", ""); 27 | io.err.println(message.trim()); 28 | } else { 29 | io.err.println(e); 30 | } 31 | 32 | io.err.print("Display stack trace? [yN] "); 33 | io.err.flush(); 34 | String line = new BufferedReader(io.in).readLine(); 35 | if (null == line) 36 | line = ""; 37 | io.err.print(line.trim()); 38 | io.err.println(); 39 | if (line.trim().equals("y") || line.trim().equals("Y")) { 40 | e.printStackTrace(io.err); 41 | } 42 | 43 | return null; 44 | } catch (Exception e) { 45 | io.err.println("An undefined error has occurred: " + args[0]); 46 | return null; 47 | } 48 | } else { 49 | io.err.println("An undefined error has occurred"); 50 | return null; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/java/com/tinkerpop/gremlin/groovy/console/NullResultHookClosure.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.console; 2 | 3 | import groovy.lang.Closure; 4 | 5 | /** 6 | * @author Marko A. Rodriguez (http://markorodriguez.com) 7 | */ 8 | public class NullResultHookClosure extends Closure { 9 | public NullResultHookClosure(final Object owner) { 10 | super(owner); 11 | } 12 | 13 | public Object call(final Object[] args) { 14 | return null; 15 | } 16 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/main/java/com/tinkerpop/gremlin/groovy/console/PromptClosure.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.console; 2 | 3 | import groovy.lang.Closure; 4 | 5 | /** 6 | * @author Marko A. Rodriguez (http://markorodriguez.com) 7 | */ 8 | public class PromptClosure extends Closure { 9 | 10 | private final String inputPrompt; 11 | 12 | public PromptClosure(final Object owner, final String inputPrompt) { 13 | super(owner); 14 | this.inputPrompt = inputPrompt; 15 | } 16 | 17 | public Object call() { 18 | return this.inputPrompt; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/java/com/tinkerpop/gremlin/groovy/console/ResultHookClosure.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.console; 2 | 3 | import com.tinkerpop.pipes.transform.ToStringPipe; 4 | import com.tinkerpop.pipes.util.iterators.SingleIterator; 5 | import groovy.lang.Closure; 6 | import org.codehaus.groovy.tools.shell.IO; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class ResultHookClosure extends Closure { 12 | private final String resultPrompt; 13 | private final IO io; 14 | 15 | public ResultHookClosure(final Object owner, final IO io, final String resultPrompt) { 16 | super(owner); 17 | this.io = io; 18 | this.resultPrompt = resultPrompt; 19 | } 20 | 21 | public Object call(final Object[] args) { 22 | final Object result = args[0]; 23 | ToStringPipe toStringPipe = new ToStringPipe(); 24 | toStringPipe.setStarts(new SingleIterator(result)); 25 | while (toStringPipe.hasNext()) { 26 | this.io.out.println(this.resultPrompt + toStringPipe.next()); 27 | } 28 | 29 | return null; 30 | } 31 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/main/java/com/tinkerpop/gremlin/groovy/jsr223/AbstractImportCustomizerProvider.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.jsr223; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import com.tinkerpop.blueprints.TransactionalGraph; 5 | import com.tinkerpop.gremlin.Imports; 6 | import org.codehaus.groovy.control.customizers.ImportCustomizer; 7 | 8 | import java.util.HashSet; 9 | import java.util.Set; 10 | 11 | /** 12 | * @author Stephen Mallette (http://stephen.genoprime.com) 13 | */ 14 | public abstract class AbstractImportCustomizerProvider implements ImportCustomizerProvider { 15 | protected static final String DOT_STAR = ".*"; 16 | protected static final String EMPTY_STRING = ""; 17 | protected static final String PERIOD = "."; 18 | 19 | protected final Set extraImports = new HashSet(); 20 | protected final Set extraStaticImports = new HashSet(); 21 | 22 | @Override 23 | public ImportCustomizer getImportCustomizer() { 24 | final ImportCustomizer ic = new ImportCustomizer(); 25 | for (final String imp : Imports.getImports()) { 26 | ic.addStarImports(imp.replace(DOT_STAR, EMPTY_STRING)); 27 | } 28 | 29 | ic.addImports("com.tinkerpop.gremlin.Tokens.T"); 30 | ic.addStarImports("com.tinkerpop.gremlin.groovy"); 31 | ic.addStaticImport(Direction.class.getName(), Direction.OUT.toString()); 32 | ic.addStaticImport(Direction.class.getName(), Direction.IN.toString()); 33 | ic.addStaticImport(Direction.class.getName(), Direction.BOTH.toString()); 34 | ic.addStaticImport(TransactionalGraph.Conclusion.class.getName(), TransactionalGraph.Conclusion.SUCCESS.toString()); 35 | ic.addStaticImport(TransactionalGraph.Conclusion.class.getName(), TransactionalGraph.Conclusion.FAILURE.toString()); 36 | 37 | importExtras(ic); 38 | importExtraStatics(ic); 39 | 40 | return ic; 41 | } 42 | 43 | private void importExtraStatics(final ImportCustomizer ic) { 44 | for (final String extraStaticImport : extraStaticImports) { 45 | if (extraStaticImport.endsWith(DOT_STAR)) { 46 | ic.addStaticStars(extraStaticImport.replace(DOT_STAR, EMPTY_STRING)); 47 | } else { 48 | final int place = extraStaticImport.lastIndexOf(PERIOD); 49 | ic.addStaticImport(extraStaticImport.substring(0, place), extraStaticImport.substring(place + 1)); 50 | } 51 | } 52 | } 53 | 54 | private void importExtras(final ImportCustomizer ic) { 55 | for (final String extraImport : extraImports) { 56 | if (extraImport.endsWith(DOT_STAR)) { 57 | ic.addStarImports(extraImport.replace(DOT_STAR, EMPTY_STRING)); 58 | } else { 59 | ic.addImports(extraImport); 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/java/com/tinkerpop/gremlin/groovy/jsr223/DefaultImportCustomizerProvider.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.jsr223; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | /** 7 | * Grabs the standard Gremlin/Blueprints classes and allows additional imports to be added. 8 | * 9 | * @author Stephen Mallette (http://stephen.genoprime.com) 10 | */ 11 | public class DefaultImportCustomizerProvider extends AbstractImportCustomizerProvider { 12 | private static Set staticExtraImports = new HashSet(); 13 | private static Set staticExtraStaticImports = new HashSet(); 14 | 15 | /** 16 | * Utilizes imports defined statically by initializeStatically(). 17 | */ 18 | public DefaultImportCustomizerProvider() { 19 | this.extraImports.addAll(staticExtraImports); 20 | this.extraStaticImports.addAll(staticExtraStaticImports); 21 | } 22 | 23 | /** 24 | * Utilizes imports defined by the supplied arguments. Those imports defined statically through 25 | * initializeStatically() are ignored. 26 | */ 27 | public DefaultImportCustomizerProvider(final Set extraImports, final Set extraStaticImports) { 28 | this.extraStaticImports.addAll(extraStaticImports); 29 | this.extraImports.addAll(extraImports); 30 | } 31 | 32 | /** 33 | * Allows imports to defined globally and statically. 34 | * 35 | * This method must be called prior to initialization of a ScriptEngine instance through the ScriptEngineFactory. 36 | */ 37 | public static void initializeStatically(final Set extraImports, final Set extraStaticImports) { 38 | if (extraImports != null) { 39 | staticExtraImports = extraImports; 40 | } 41 | 42 | if (extraStaticImports != null) { 43 | staticExtraStaticImports = extraStaticImports; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/java/com/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineFactory.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.jsr223; 2 | 3 | import com.tinkerpop.gremlin.Tokens; 4 | 5 | import javax.script.ScriptEngine; 6 | import javax.script.ScriptEngineFactory; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | /** 11 | * @author Marko A. Rodriguez (http://markorodriguez.com) 12 | */ 13 | public class GremlinGroovyScriptEngineFactory implements ScriptEngineFactory { 14 | 15 | private static final String ENGINE_NAME = "gremlin-groovy"; 16 | private static final String LANGUAGE_NAME = "gremlin-groovy"; 17 | private static final String VERSION_NUMBER = Tokens.VERSION; 18 | private static final String PLAIN = "plain"; 19 | private static final List EXTENSIONS = Arrays.asList("groovy"); 20 | 21 | public String getEngineName() { 22 | return ENGINE_NAME; 23 | } 24 | 25 | public String getEngineVersion() { 26 | return VERSION_NUMBER; 27 | } 28 | 29 | public List getExtensions() { 30 | return EXTENSIONS; 31 | } 32 | 33 | public String getLanguageName() { 34 | return LANGUAGE_NAME; 35 | } 36 | 37 | public String getLanguageVersion() { 38 | return VERSION_NUMBER; 39 | } 40 | 41 | public String getMethodCallSyntax(final String obj, final String m, final String... args) { 42 | return null; 43 | } 44 | 45 | public List getMimeTypes() { 46 | return Arrays.asList(PLAIN); 47 | } 48 | 49 | public List getNames() { 50 | return Arrays.asList(LANGUAGE_NAME); 51 | } 52 | 53 | public String getOutputStatement(final String toDisplay) { 54 | return "println " + toDisplay; 55 | } 56 | 57 | public Object getParameter(final String key) { 58 | if (key.equals(ScriptEngine.ENGINE)) { 59 | return this.getEngineName(); 60 | } else if (key.equals(ScriptEngine.ENGINE_VERSION)) { 61 | return this.getEngineVersion(); 62 | } else if (key.equals(ScriptEngine.NAME)) { 63 | return ENGINE_NAME; 64 | } else if (key.equals(ScriptEngine.LANGUAGE)) { 65 | return this.getLanguageName(); 66 | } else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) { 67 | return this.getLanguageVersion(); 68 | } else 69 | return null; 70 | } 71 | 72 | public String getProgram(final String... statements) { 73 | String program = ""; 74 | 75 | for (String statement : statements) { 76 | program = program + statement + "\n"; 77 | } 78 | 79 | return program; 80 | } 81 | 82 | public ScriptEngine getScriptEngine() { 83 | return new GremlinGroovyScriptEngine(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/java/com/tinkerpop/gremlin/groovy/jsr223/ImportCustomizerProvider.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.jsr223; 2 | 3 | import org.codehaus.groovy.control.customizers.ImportCustomizer; 4 | 5 | /** 6 | * Allows customization of the imports used by the GremlinGroovyScriptEngine implementation. 7 | * 8 | * @author Stephen Mallette (http://stephen.genoprime.com) 9 | */ 10 | public interface ImportCustomizerProvider { 11 | ImportCustomizer getImportCustomizer(); 12 | } 13 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/java/com/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.jsr223; 2 | 3 | import javax.script.Bindings; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | import java.io.Reader; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | /** 11 | * @author Pavel A. Yaskevich 12 | * @author Marko A. Rodriguez (http://markorodriguez.com) 13 | */ 14 | public class ScriptExecutor { 15 | 16 | public static void main(final String[] arguments) throws IOException { 17 | if (arguments.length == 0) { 18 | System.out.println("Usage: ..."); 19 | } else { 20 | evaluate(new FileReader(arguments[0]), Arrays.asList(arguments).subList(1, arguments.length)); 21 | } 22 | } 23 | 24 | protected static void evaluate(final Reader reader, final List arguments) { 25 | final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(); 26 | 27 | final Bindings bindings = engine.createBindings(); 28 | bindings.put("args", arguments.toArray()); 29 | // TODO: Deprecate this 30 | if (arguments.size() > 0) { 31 | for (int i = 0; i < arguments.size(); i++) { 32 | bindings.put("a" + (i + 1), arguments.get(i)); 33 | } 34 | } 35 | try { 36 | engine.eval(reader, bindings); 37 | } catch (Exception e) { 38 | System.err.println(e.getMessage()); 39 | } 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /gremlin-groovy/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory: -------------------------------------------------------------------------------- 1 | com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngineFactory -------------------------------------------------------------------------------- /gremlin-groovy/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # A1 is set to be a ConsoleAppender. 2 | log4j.appender.A1=org.apache.log4j.ConsoleAppender 3 | 4 | # A1 uses PatternLayout. 5 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n 7 | 8 | # Set root logger level to the designated level and its only appender to A1. 9 | log4j.rootLogger=ERROR, A1 -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/FunctionStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.test.ComplianceTest 6 | 7 | /** 8 | * @author Marko A. Rodriguez (http://markorodriguez.com) 9 | */ 10 | class FunctionStepTest extends com.tinkerpop.gremlin.test.FunctionStepTest { 11 | 12 | Graph g = TinkerGraphFactory.createTinkerGraph(); 13 | static { 14 | Gremlin.load(); 15 | } 16 | 17 | public void testCompliance() { 18 | ComplianceTest.testCompliance(this.getClass()); 19 | } 20 | 21 | public void test_g_v1_out_stepXnext_nameX() { 22 | super.test_g_v1_out_stepXnext_nameX(g.v(1).out.step { it.next().name }); 23 | } 24 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/UtilitiesTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.test.ComplianceTest 6 | 7 | /** 8 | * @author Marko A. Rodriguez (http://markorodriguez.com) 9 | */ 10 | class UtilitiesTest extends com.tinkerpop.gremlin.test.UtilitiesTest { 11 | Graph g = TinkerGraphFactory.createTinkerGraph(); 12 | static { 13 | Gremlin.load(); 14 | } 15 | 16 | public void testCompliance() { 17 | ComplianceTest.testCompliance(this.getClass()); 18 | } 19 | 20 | public void test_g_v1_out_toList() { 21 | super.test_g_v1_out_toList(g.v(1).out.toList()); 22 | } 23 | 24 | public void test_g_v1_out_nextX1X() { 25 | super.test_g_v1_out_nextX1X(g.v(1).out.next(1)); 26 | } 27 | 28 | public void test_g_v1_out_fillXlistX() { 29 | super.test_g_v1_out_fillXlistX(g.v(1).out().fill([])); 30 | } 31 | 32 | public void test_g_V_countXX() { 33 | super.test_g_V_countXX(g.V.count()); 34 | } 35 | 36 | public void test_g_E_remove() { 37 | def temp = TinkerGraphFactory.createTinkerGraph(); 38 | temp.E.remove(); 39 | super.test_g_E_remove(temp); 40 | } 41 | 42 | public void test_g_V_hasXidX1X_name_equals_g_v1_name() { 43 | super.test_g_V_hasXidX1X_name_equals_g_v1_name(g.V.has('id', '1').name, g.v(1)._().name); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/basescript/GremlinGroovyPipelineInterceptor.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.basescript 2 | 3 | /** 4 | * Created by pieter on 2014/04/21. 5 | */ 6 | class GremlinGroovyPipelineInterceptor implements Interceptor { 7 | 8 | @Override 9 | Object beforeInvoke(Object object, String methodName, Object[] arguments) { 10 | null 11 | } 12 | 13 | @Override 14 | Object afterInvoke(Object object, String methodName, Object[] arguments, Object result) { 15 | if (methodName == 'V') { 16 | return result.hasNot('deleted'); 17 | } else { 18 | return result 19 | } 20 | } 21 | 22 | @Override 23 | boolean doInvoke() { 24 | return true 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/basescript/GremlinGroovyScriptBaseClassForTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.basescript 2 | 3 | /** 4 | * @author Pieter Martin 5 | */ 6 | abstract class GremlinGroovyScriptBaseClassForTest extends Script { 7 | 8 | def useInterceptor= { Class theClass, Class theInterceptor, Closure theCode-> 9 | def proxy= ProxyMetaClass.getInstance( theClass ) 10 | def interceptor= theInterceptor.newInstance() 11 | proxy.interceptor= interceptor 12 | proxy.use( theCode ) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/branch/IfThenElseStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.branch 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class IfThenElseStepTest extends com.tinkerpop.gremlin.test.branch.IfThenElseStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_out_ifThenElseXlang_eq_java__it__outX_name() { 23 | super.test_g_v1_out_ifThenElseXlang_eq_java__it__outX_name(g.v(1).out.ifThenElse { it.lang == 'java' } { it } { it.out }.name); 24 | } 25 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/branch/LoopStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.branch 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class LoopStepTest extends com.tinkerpop.gremlin.test.branch.LoopStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_out_loopX1_loops_lt_3X_propertyXnameX() { 23 | super.test_g_v1_out_loopX1_loops_lt_3X_propertyXnameX(g.v(1).out.loop(1) { it.loops < 3 }.name); 24 | } 25 | 26 | public void test_g_v1_asXhereX_out_loopXhere_loops_lt_3X_propertyXnameX() { 27 | super.test_g_v1_asXhereX_out_loopXhere_loops_lt_3X_propertyXnameX(g.v(1).as('here').out.loop('here') { it.loops < 3 }.property('name')); 28 | } 29 | 30 | public void test_g_V_out_loopX1_loops_lt_3X_propertyXnameX() { 31 | super.test_g_V_out_loopX1_loops_lt_3X_propertyXnameX(g.V.out.loop(1) { it.loops < 3 }.property('name')); 32 | } 33 | 34 | public void test_g_V_asXhereX_out_loopXhere_loops_lt_3X_propertyXnameX() { 35 | super.test_g_V_asXhereX_out_loopXhere_loops_lt_3X_propertyXnameX(g.V.as('here').out.loop('here') { it.loops < 3 }.name); 36 | } 37 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/branch/SplitMergeStepsTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.branch 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class SplitMergeStepsTest extends com.tinkerpop.gremlin.test.branch.SplitMergeStepsTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_out_copySplitXpropertyXnameX__propertyXageXX_fairMerge() { 23 | super.test_g_v1_out_copySplitXpropertyXnameX__propertyXageXX_fairMerge(g.v(1).out.copySplit(_().name, _().age).fairMerge); 24 | } 25 | 26 | public void test_g_v1_outXknowsX_copySplitXpropertyXnameX__propertyXageXX_exhaustMerge() { 27 | super.test_g_v1_outXknowsX_copySplitXpropertyXnameX__propertyXageXX_exhaustMerge(g.v(1).out('knows').copySplit(_().name, _().age).exhaustMerge); 28 | } 29 | 30 | public void test_g_v1_outXknowsX_copySplitXpropertyXnameX__propertyXageXX_exhaustMerge_path() { 31 | super.test_g_v1_outXknowsX_copySplitXpropertyXnameX__propertyXageXX_exhaustMerge_path(g.v(1).out('knows').copySplit(_().name, _().age).exhaustMerge.path); 32 | } 33 | 34 | /*public void testPlay() { 35 | System.out.println(g.v(1).out('knows','created').loop(1){println(it.object.toString() + "!!" + it.loops);it.loops < 3}.toList()); 36 | System.out.println("\n") 37 | System.out.println(g.v(1).copySplit(_().out('knows'), _().out('created')).fairMerge.loop(2){println(it.object.toString() + "!!" + it.loops); it.loops < 3}.toList()); 38 | }*/ 39 | } 40 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/filter/BackStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.filter 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class BackStepTest extends com.tinkerpop.gremlin.test.filter.BackStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_out_backX1X() { 23 | super.test_g_v1_out_backX1X(g.v(1).out.back(1)); 24 | } 25 | 26 | public void test_g_v1_asXhereX_out_backXhereX() { 27 | super.test_g_v1_asXhereX_out_backXhereX(g.v(1).as('here').out.back('here')); 28 | } 29 | 30 | public void test_g_v4_out_filterXlang_eq_javaX_backX1X() { 31 | super.test_g_v4_out_filterXlang_eq_javaX_backX1X(g.v(4).out.filter { it.lang == 'java' }.back(1)); 32 | } 33 | 34 | public void test_g_v4_out_asXhereX_filterXlang_eq_javaX_backXhereX() { 35 | super.test_g_v4_out_asXhereX_filterXlang_eq_javaX_backXhereX(g.v(4).out.as('here').filter { it.lang == 'java' }.back('here')); 36 | } 37 | 38 | public void test_g_v4_out_asXhereX_filterXlang_eq_javaX_backXhereX_propertyXnameX() { 39 | super.test_g_v4_out_asXhereX_filterXlang_eq_javaX_backXhereX_propertyXnameX(g.v(4).out.as('here').filter { it.lang == 'java' }.back('here').name); 40 | } 41 | 42 | public void test_g_v1_outE_inV_hasXname_vadasX_backX2X() { 43 | super.test_g_v1_outE_inV_hasXname_vadasX_backX2X(g.v(1).outE().inV.has("name", "vadas").back(2)); 44 | } 45 | 46 | public void test_g_v1_outE_asXhereX_inV_hasXname_vadasX_backXhereX() { 47 | super.test_g_v1_outE_asXhereX_inV_hasXname_vadasX_backXhereX(g.v(1).outE.as("here").inV.has("name", "vadas").back("here")); 48 | } 49 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/filter/DedupStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.filter 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class DedupStepTest extends com.tinkerpop.gremlin.test.filter.DedupStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_V_both_dedup_name() { 23 | super.test_g_V_both_dedup_name(g.V.both.dedup.name); 24 | } 25 | 26 | public void test_g_V_both_dedupXlangX_name() { 27 | super.test_g_V_both_dedupXlangX_name(g.V.both.dedup { it.lang }.name); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/filter/ExceptStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.filter 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class ExceptStepTest extends com.tinkerpop.gremlin.test.filter.ExceptStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_out_exceptXg_v2X() { 23 | super.test_g_v1_out_exceptXg_v2X(g.v(1).out.except([g.v(2)])); 24 | } 25 | 26 | public void test_g_v1_out_aggregateXxX_out_exceptXxX() { 27 | def x = [] as Set; 28 | super.test_g_v1_out_aggregateXxX_out_exceptXxX(g.v(1).out.aggregate(x).out.except(x)); 29 | } 30 | 31 | public void test_g_v1_outXcreatedX_inXcreatedX_exceptXg_v1X_propertyXnameX() { 32 | super.test_g_v1_outXcreatedX_inXcreatedX_exceptXg_v1X_propertyXnameX(g.v(1).out("created").in("created").except([g.v(1)]).property("name")); 33 | } 34 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/filter/FilterStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.filter 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class FilterStepTest extends com.tinkerpop.gremlin.test.filter.FilterStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_V_filterXfalseX() { 23 | super.test_g_V_filterXfalseX(g.V.filter { false }); 24 | } 25 | 26 | public void test_g_V_filterXtrueX() { 27 | super.test_g_V_filterXtrueX(g.V.filter { true }); 28 | } 29 | 30 | public void test_g_V_filterXlang_eq_javaX() { 31 | super.test_g_V_filterXlang_eq_javaX(g.V.filter { it.lang == 'java' }); 32 | } 33 | 34 | public void test_g_v1_out_filterXage_gt_30X() { 35 | super.test_g_v1_out_filterXage_gt_30X(g.v(1).out.filter { it.age > 30 }); 36 | } 37 | 38 | public void test_g_V_filterXname_startsWith_m_OR_name_startsWith_pX() { 39 | super.test_g_V_filterXname_startsWith_m_OR_name_startsWith_pX(g.V.filter { it.name.startsWith('m') | it.name.startsWith('p') }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/filter/HasNotStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.filter 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class HasNotStepTest extends com.tinkerpop.gremlin.test.filter.HasNotStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_V_hasNotXname_markoX() { 23 | super.test_g_V_hasNotXname_markoX(g.V.hasNot('name', 'marko')); 24 | } 25 | 26 | public void test_g_V_hasNotXname_blahX() { 27 | super.test_g_V_hasNotXname_blahX(g.V.hasNot('name', 'blah')); 28 | } 29 | 30 | public void test_g_V_hasNotXblahX() { 31 | super.test_g_V_hasNotXblahX(g.V.hasNot('blah')); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/filter/HasStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.filter 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.Tokens 6 | import com.tinkerpop.gremlin.groovy.Gremlin 7 | import com.tinkerpop.gremlin.test.ComplianceTest 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | class HasStepTest extends com.tinkerpop.gremlin.test.filter.HasStepTest { 13 | 14 | Graph g = TinkerGraphFactory.createTinkerGraph(); 15 | static { 16 | Gremlin.load(); 17 | } 18 | 19 | public void testCompliance() { 20 | ComplianceTest.testCompliance(this.getClass()); 21 | } 22 | 23 | public void test_g_V_hasXname_markoX() { 24 | super.test_g_V_hasXname_markoX(g.V.has('name', 'marko')); 25 | } 26 | 27 | public void test_g_V_hasXname_blahX() { 28 | super.test_g_V_hasXname_blahX(g.V.has('name', 'blah')); 29 | } 30 | 31 | public void test_g_V_hasXblahX() { 32 | super.test_g_V_hasXblahX(g.V.has('blah')); 33 | } 34 | 35 | public void test_g_v1_out_hasXid_2X() { 36 | super.test_g_v1_out_hasXid_2X(g.v(1).out.has('id', '2')); 37 | } 38 | 39 | public void test_g_V_hasXage_gt_30X() { 40 | super.test_g_V_hasXage_gt_30X(g.V.has('age', Tokens.T.gt, 30)); 41 | } 42 | 43 | public void test_g_E_hasXlabelXknowsX() { 44 | super.test_g_E_hasXlabelXknowsX(g.E.has("label", "knows")); 45 | } 46 | 47 | public void test_g_E_hasXlabelXknows_createdX() { 48 | super.test_g_E_hasXlabelXknows_createdX(g.E.has("label", Tokens.T.in, ["knows", "created"])); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/filter/IntervalStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.filter 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class IntervalStepTest extends com.tinkerpop.gremlin.test.filter.IntervalStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_outE_intervalXweight_0_06X_inV() { 23 | super.test_g_v1_outE_intervalXweight_0_06X_inV(g.v(1).outE.interval('weight', 0.0f, 0.6f).inV); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/filter/RangeStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.filter 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class RangeStepTest extends com.tinkerpop.gremlin.test.filter.RangeStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_out_rangeX0_1X() { 23 | super.test_g_v1_out_rangeX0_1X(g.v(1).out[0..1]); 24 | } 25 | 26 | public void test_g_v1_outXknowsX_outEXcreatedX_rangeX0_0X_inV() { 27 | super.test_g_v1_outXknowsX_outEXcreatedX_rangeX0_0X_inV(g.v(1).out('knows').outE('created')[0..0].inV); 28 | } 29 | 30 | public void test_g_v1_outXknowsX_outXcreatedX_rangeX0_0X() { 31 | super.test_g_v1_outXknowsX_outXcreatedX_rangeX0_0X(g.v(1).out('knows').out('created')[0..0]); 32 | } 33 | 34 | public void test_g_v1_outXcreatedX_inXcreatedX_rangeX1_2X() { 35 | super.test_g_v1_outXcreatedX_inXcreatedX_rangeX1_2X(g.v(1).out('created').in('created')[1..2]); 36 | } 37 | 38 | public void test_g_v1_outXcreatedX_inEXcreatedX_rangeX1_2X_outV() { 39 | super.test_g_v1_outXcreatedX_inXcreatedX_rangeX1_2X(g.v(1).out('created').inE('created')[1..2].outV); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/filter/RetainStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.filter 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class RetainStepTest extends com.tinkerpop.gremlin.test.filter.RetainStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_out_retainXg_v2X() { 23 | super.test_g_v1_out_retainXg_v2X(g.v(1).out.retain([g.v(2)])); 24 | } 25 | 26 | public void test_g_v1_out_aggregateXxX_out_retainXxX() { 27 | def x = [] as Set; 28 | super.test_g_v1_out_aggregateXxX_out_retainXxX(g.v(1).out.aggregate(x).out.retain(x)); 29 | } 30 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/loaders/IndexLoaderTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.loaders 2 | 3 | import com.tinkerpop.blueprints.Edge 4 | import com.tinkerpop.blueprints.Graph 5 | import com.tinkerpop.blueprints.Vertex 6 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 7 | import com.tinkerpop.gremlin.groovy.Gremlin 8 | import junit.framework.TestCase 9 | 10 | /** 11 | * @author Marko A. Rodriguez (http://markorodriguez.com) 12 | */ 13 | class IndexLoaderTest extends TestCase { 14 | 15 | public void testIndexShortcuts() throws Exception { 16 | Gremlin.load(); 17 | Graph g = TinkerGraphFactory.createTinkerGraph(); 18 | g.createKeyIndex('name', Vertex.class); 19 | g.createKeyIndex('weight', Edge.class); 20 | assertEquals(g.v(1), g.V('name', 'marko').next()); 21 | assertEquals(2, g.E('weight', 0.4f).count()); 22 | } 23 | 24 | public void testIndexHitIntoTraversal() throws Exception { 25 | Gremlin.load(); 26 | Graph g = TinkerGraphFactory.createTinkerGraph(); 27 | g.createKeyIndex('lang', Vertex.class); 28 | 29 | def results = []; 30 | g.V('lang', 'java').inE.outV.fill(results); 31 | assertEquals(results.size(), 4); 32 | assertTrue(results.contains(g.v(1))); 33 | assertTrue(results.contains(g.v(6))); 34 | assertTrue(results.contains(g.v(4))); 35 | } 36 | 37 | public void testIndexLookupError() throws Exception { 38 | Gremlin.load(); 39 | Graph g = TinkerGraphFactory.createTinkerGraph(); 40 | assertNull(g.idx('blah')) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/loaders/ObjectLoaderTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.loaders 2 | 3 | import com.tinkerpop.gremlin.groovy.Gremlin 4 | import junit.framework.TestCase 5 | 6 | /** 7 | * @author Marko A. Rodriguez (http://markorodriguez.com) 8 | */ 9 | class ObjectLoaderTest extends TestCase { 10 | 11 | public void testMapRange() { 12 | Gremlin.load(); 13 | def m = ["a": 2, "b": 3, "c": 4, "d": 5, "e": 6]; 14 | def x = m[0..1].keySet(); 15 | assertTrue(x.contains("a")) 16 | assertTrue(x.contains("b")) 17 | assertEquals(x.size(), 2); 18 | 19 | x = m[1..3].keySet(); 20 | assertTrue(x.contains("b")) 21 | assertTrue(x.contains("c")) 22 | assertTrue(x.contains("d")) 23 | assertEquals(x.size(), 3); 24 | 25 | x = m[1..<3].keySet(); 26 | assertTrue(x.contains("b")) 27 | assertTrue(x.contains("c")) 28 | assertEquals(x.size(), 2); 29 | 30 | x = m[0..20]; 31 | assertEquals(x.size(), m.size()); 32 | assertEquals(x, m); 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/loaders/PipeLoaderTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.loaders 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import junit.framework.TestCase 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class PipeLoaderTest extends TestCase { 12 | 13 | public void testCount() { 14 | Gremlin.load(); 15 | Graph g = TinkerGraphFactory.createTinkerGraph(); 16 | assertEquals(g.V.count(), 6l); 17 | assertEquals(g.E.count(), 6l); 18 | assertEquals(g.v(1).outE().count(), 3l); 19 | assertEquals(g.v(1).outE('blah').count(), 0l); 20 | } 21 | 22 | public void testMean() { 23 | Gremlin.load() 24 | def numbers = [1, 2, 3, 4, 5]; 25 | assertEquals(numbers.mean(), 3.0d) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/loaders/SailGraphLoaderTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.loaders 2 | 3 | import com.tinkerpop.blueprints.impls.sail.impls.MemoryStoreSailGraph 4 | import junit.framework.TestCase 5 | 6 | /** 7 | * @author Marko A. Rodriguez (http://markorodriguez.com) 8 | */ 9 | class SailGraphLoaderTest extends TestCase { 10 | 11 | public void testNamespacePrefix() { 12 | SailGraphLoader.load(); 13 | 14 | def g = new MemoryStoreSailGraph(); 15 | g.addNamespace('tg', 'http://tinkerpop.com#'); 16 | assertEquals(g.uri('tg:1'), 'http://tinkerpop.com#1'); 17 | assertEquals(g.qn('http://tinkerpop.com#1'), 'tg:1'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/sideeffect/AggregateStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.sideeffect 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class AggregateStepTest extends com.tinkerpop.gremlin.test.sideeffect.AggregateStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_aggregateXxX_outXcreatedX_inXcreatedX_exceptXxX() { 23 | def x = []; 24 | super.test_g_v1_aggregateXxX_outXcreatedX_inXcreatedX_exceptXxX(g.v(1).aggregate(x).out('created').in('created').except(x)) 25 | } 26 | 27 | public void test_g_V_propertyXnameX_aggregate_cap() { 28 | super.test_g_V_propertyXnameX_aggregate_cap(g.V.name.aggregate.cap); 29 | } 30 | 31 | public void test_g_V_aggregateXnameX_cap() { 32 | super.test_g_V_aggregateXnameX_cap(g.V.aggregate { it.name }.cap); 33 | } 34 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/sideeffect/GroupByStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.sideeffect 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class GroupByStepTest extends com.tinkerpop.gremlin.test.sideeffect.GroupByStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | 19 | public void testCompliance() { 20 | ComplianceTest.testCompliance(this.getClass()); 21 | } 22 | 23 | public void test_g_V_groupByXlang_nameX() { 24 | def m = [:]; 25 | super.test_g_V_groupByXlang_nameX(g.V.groupBy(m) { it.lang } { it.name }, m); 26 | } 27 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/sideeffect/GroupCountStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.sideeffect 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class GroupCountStepTest extends com.tinkerpop.gremlin.test.sideeffect.GroupCountStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_V_outXcreatedX_groupCountXm__nameX() { 23 | def m = [:] 24 | super.test_g_V_outXcreatedX_groupCountXm__nameX(g.V.out('created').groupCount(m) { it.name }, m); 25 | } 26 | 27 | public void test_g_V_outXcreatedX_groupCountXm__name__plus_2X() { 28 | def m = [:] 29 | super.test_g_V_outXcreatedX_groupCountXm__name__plus_2X(g.V.out('created').groupCount(m) { it.name } { it.b + 2l }, m); 30 | } 31 | 32 | public void test_g_V_outXcreatedX_groupCountXnameX_cap() { 33 | super.test_g_V_outXcreatedX_groupCountXnameX_cap(g.V.out('created').groupCount { it.name }.cap); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/sideeffect/LinkedStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.sideeffect 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | 7 | /** 8 | * @author Marko A. Rodriguez (http://markorodriguez.com) 9 | */ 10 | class LinkedStepTest extends com.tinkerpop.gremlin.test.sideeffect.LinkStepTest { 11 | 12 | Graph g = TinkerGraphFactory.createTinkerGraph(); 13 | static { 14 | Gremlin.load(); 15 | } 16 | 17 | public void test_g_v1_asXaX_outXcreatedX_inXcreatedX_linkBothXcocreator_aX() { 18 | super.test_g_v1_asXaX_outXcreatedX_inXcreatedX_linkBothXcocreator_aX(g.v(1).as('a').out('created').in('created').linkBoth('cocreator', 'a')); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/sideeffect/SideEffectStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.sideeffect 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class SideEffectStepTest extends com.tinkerpop.gremlin.test.sideeffect.SideEffectStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_sideEffectXstore_aX_propertyXnameX() { 23 | def a; 24 | super.test_g_v1_sideEffectXstore_aX_propertyXnameX(g.v(1).sideEffect { a = it }.name); 25 | assertEquals(a, g.v(1)) 26 | } 27 | 28 | public void test_g_v1_out_sideEffectXincr_cX_propertyXnameX() { 29 | def c = 0; 30 | super.test_g_v1_out_sideEffectXincr_cX_propertyXnameX(g.v(1).out.sideEffect { c++ }.name); 31 | assertEquals(c, 3); 32 | } 33 | 34 | public void test_g_v1_out_sideEffectXfalseX_propertyXnameX() { 35 | super.test_g_v1_out_sideEffectXfalseX_propertyXnameX(g.v(1).out.sideEffect { false }.name); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/sideeffect/StoreStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.sideeffect 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class StoreStepTest extends com.tinkerpop.gremlin.test.sideeffect.StoreStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_V_propertyXnameX_store_cap() { 23 | super.test_g_V_propertyXnameX_store_cap(g.V.name.store.cap); 24 | } 25 | 26 | public void test_g_V_storeXnameX_cap() { 27 | super.test_g_V_storeXnameX_cap(g.V.store { it.name }.cap); 28 | } 29 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/sideeffect/TableStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.sideeffect 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | import com.tinkerpop.pipes.util.structures.Table 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | class TableStepTest extends com.tinkerpop.gremlin.test.sideeffect.TableStepTest { 13 | 14 | Graph g = TinkerGraphFactory.createTinkerGraph(); 15 | static { 16 | Gremlin.load(); 17 | } 18 | 19 | public void testCompliance() { 20 | ComplianceTest.testCompliance(this.getClass()); 21 | } 22 | 23 | public void test_g_v1_asXaX_out_properyXnameX_asXbX_table_cap() { 24 | super.test_g_v1_asXaX_out_properyXnameX_asXbX_table_cap(g.v(1).as('a').out.name.as('b').table.cap); 25 | } 26 | 27 | public void test_g_v1_asXaX_out_asXbX_tableXnameX_cap() { 28 | super.test_g_v1_asXaX_out_asXbX_tableXnameX_cap(g.v(1).as('a').out.as('b').table { it.name }.cap); 29 | } 30 | 31 | public void test_g_v1_asXaX_out_propertyXnameX_asXbX_tableXname_lengthX_cap() { 32 | super.test_g_v1_asXaX_out_propertyXnameX_asXbX_tableXname_lengthX_cap(g.v(1).as('a').out.name.as('b').table { it.name } { it.length() }.cap); 33 | } 34 | 35 | public void testTableMethods() { 36 | Table table = new Table(); 37 | table.addRow("marko", 3); 38 | table.addRow("josh", 2); 39 | table.addRow("stephen", 1); 40 | Table temp = table.sort { a, b -> a.get(1) <=> b.get(1) }; 41 | assertEquals(temp.get(0, 0), "stephen") 42 | assertEquals(temp.get(1, 0), "josh") 43 | assertEquals(temp.get(2, 0), "marko") 44 | 45 | temp = table.apply { it.length() } { it + 1 }; 46 | assertEquals(temp.get(0, 0), 5) 47 | assertEquals(temp.get(0, 1), 4) 48 | assertEquals(temp.get(1, 0), 4) 49 | assertEquals(temp.get(1, 1), 3) 50 | assertEquals(temp.get(2, 0), 7) 51 | assertEquals(temp.get(2, 1), 2) 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/sideeffect/TreeStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.sideeffect 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class TreeStepTest extends com.tinkerpop.gremlin.test.sideeffect.TreeStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_out_out_treeXnameX_cap() { 23 | super.test_g_v1_out_out_treeXnameX_cap(g.v(1).out.out.tree { it.name }.cap); 24 | } 25 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/transform/GatherStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.transform 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.Vertex 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 6 | import com.tinkerpop.gremlin.java.GremlinPipeline 7 | import com.tinkerpop.gremlin.test.ComplianceTest 8 | import com.tinkerpop.pipes.Pipe 9 | 10 | /** 11 | * @author Marko A. Rodriguez (http://markorodriguez.com) 12 | */ 13 | class GatherStepTest extends com.tinkerpop.gremlin.test.transform.GatherStepTest { 14 | 15 | Graph g = TinkerGraphFactory.createTinkerGraph(); 16 | 17 | public void testCompliance() { 18 | ComplianceTest.testCompliance(this.getClass()); 19 | } 20 | 21 | public void test_g_v1_out_gather(final Pipe> pipe) { 22 | super.test_g_v1_out_gather(new GremlinPipeline(g.v(1).out.gather)); 23 | } 24 | 25 | public void test_g_v1_out_gatherXget0X(final Pipe pipe) { 26 | super.test_g_v1_out_gatherXget0X(g.v(1).out.gather { it[0] }); 27 | } 28 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/transform/MapStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.transform 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class MapStepTest extends com.tinkerpop.gremlin.test.transform.MapStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_map() { 23 | super.test_g_v1_map(g.v(1).map) 24 | } 25 | 26 | public void test_g_v1_mapXname_idX() { 27 | super.test_g_v1_mapXname_idX(g.v(1).map('name', 'id')); 28 | } 29 | 30 | public void test_g_v1_outXknowsX_map() { 31 | super.test_g_v1_outXknowsX_map(g.v(1).out('knows').map); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/transform/OrderStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.transform 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.Tokens 6 | import com.tinkerpop.gremlin.groovy.Gremlin 7 | import com.tinkerpop.gremlin.test.ComplianceTest 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | class OrderStepTest extends com.tinkerpop.gremlin.test.transform.OrderStepTest { 13 | 14 | Graph g = TinkerGraphFactory.createTinkerGraph(); 15 | static { 16 | Gremlin.load(); 17 | } 18 | 19 | public void testCompliance() { 20 | ComplianceTest.testCompliance(this.getClass()); 21 | } 22 | 23 | public void test_g_V_name_order() { 24 | super.test_g_V_name_order(g.V.name.order); 25 | } 26 | 27 | public void test_g_V_name_orderXabX() { 28 | super.test_g_V_name_orderXabX(g.V.name.order { it.b <=> it.a }); 29 | } 30 | 31 | public void test_g_V_orderXa_nameXb_nameX_name() { 32 | super.test_g_V_orderXa_nameXb_nameX_name(g.V.order { it.b.name <=> it.a.name }.name); 33 | } 34 | 35 | public void test_g_V_name_orderXdecrX() { 36 | super.test_g_V_name_orderXdecrX(g.V.name.order(Tokens.T.decr)); 37 | } 38 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/transform/PathStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.transform 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class PathStepTest extends com.tinkerpop.gremlin.test.transform.PathStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_propertyXnameX_path() { 23 | super.test_g_v1_propertyXnameX_path(g.v(1)._.name.path); 24 | } 25 | 26 | public void test_g_v1_out_pathXage__nameX() { 27 | super.test_g_v1_out_pathXage__nameX(g.v(1).out.path { it.age } { it.name }); 28 | } 29 | 30 | public void test_g_V_out_loopX1__loops_lt_3X_pathXit__name__langX() { 31 | super.test_g_V_out_loopX1__loops_lt_3X_pathXit__name__langX(g.V.out.loop(1) { it.loops < 3 }.path { it } { it.name } { it.lang }); 32 | } 33 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/transform/SelectStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.transform 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class SelectStepTest extends com.tinkerpop.gremlin.test.transform.SelectStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_asXaX_outXknowsX_asXbX_select() { 23 | super.test_g_v1_asXaX_outXknowsX_asXbX_select(g.v(1).as('a').out('knows').as('b').select) 24 | } 25 | 26 | public void test_g_v1_asXaX_outXknowsX_asXbX_selectXnameX() { 27 | super.test_g_v1_asXaX_outXknowsX_asXbX_selectXnameX(g.v(1).as('a').out('knows').as('b').select { it.name }); 28 | } 29 | 30 | public void test_g_v1_asXaX_outXknowsX_asXbX_selectXaX() { 31 | super.test_g_v1_asXaX_outXknowsX_asXbX_selectXaX(g.v(1).as('a').out('knows').as('b').select(['a'])); 32 | } 33 | 34 | public void test_g_v1_asXaX_outXknowsX_asXbX_selectXa_nameX() { 35 | super.test_g_v1_asXaX_outXknowsX_asXbX_selectXa_nameX(g.v(1).as('a').out('knows').as('b').select(['a']) { it.name }); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/groovy/com/tinkerpop/gremlin/groovy/transform/TransformStepTest.groovy: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.transform 2 | 3 | import com.tinkerpop.blueprints.Graph 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory 5 | import com.tinkerpop.gremlin.groovy.Gremlin 6 | import com.tinkerpop.gremlin.test.ComplianceTest 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | class TransformStepTest extends com.tinkerpop.gremlin.test.transform.TransformStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | static { 15 | Gremlin.load(); 16 | } 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_transformXnameX() { 23 | super.test_g_v1_transformXnameX(g.v(1).transform { it.name }); 24 | } 25 | 26 | public void test_g_v1_outE_label_transformXlengthX() { 27 | super.test_g_v1_outE_label_transformXlengthX(g.v(1).outE.label.transform { it.length() }); 28 | } 29 | 30 | public void test_g_v1_out_transformXnameX_transformXlengthX() { 31 | super.test_g_v1_out_transformXnameX_transformXlengthX(g.v(1).out.transform { it.name }.transform { it.length() }); 32 | } 33 | 34 | public void test_g_V_asXaX_out_transformXa_nameX() { 35 | super.test_g_V_asXaX_out_transformXa_nameX(g.V.as('a').out.transform { x, y -> y.a.name }); 36 | } 37 | } -------------------------------------------------------------------------------- /gremlin-groovy/src/test/java/com/tinkerpop/gremlin/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Iterator; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public abstract class BaseTest extends TestCase { 13 | 14 | double timer = -1.0d; 15 | 16 | public static int count(final Iterator iterator) { 17 | int counter = 0; 18 | while (iterator.hasNext()) { 19 | iterator.next(); 20 | counter++; 21 | } 22 | return counter; 23 | } 24 | 25 | public static List asList(final Iterable iterable) { 26 | return asList(iterable.iterator()); 27 | } 28 | 29 | public static List asList(final Iterator iterator) { 30 | List list = new ArrayList(); 31 | while (iterator.hasNext()) { 32 | 33 | list.add(iterator.next()); 34 | } 35 | return list; 36 | } 37 | 38 | public double stopWatch() { 39 | if (this.timer == -1.0d) { 40 | this.timer = System.nanoTime() / 1000000.0d; 41 | return -1.0d; 42 | } else { 43 | double temp = (System.nanoTime() / 1000000.0d) - this.timer; 44 | this.timer = -1.0d; 45 | return temp; 46 | } 47 | } 48 | 49 | public static void printPerformance(String name, Integer events, String eventName, double timeInMilliseconds) { 50 | if (null != events) 51 | System.out.println("\t" + name + ": " + events + " " + eventName + " in " + timeInMilliseconds + "ms"); 52 | else 53 | System.out.println("\t" + name + ": " + eventName + " in " + timeInMilliseconds + "ms"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/java/com/tinkerpop/gremlin/groovy/jsr223/ScriptExecutorTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.groovy.jsr223; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import java.io.InputStreamReader; 6 | import java.util.Arrays; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class ScriptExecutorTest extends TestCase { 12 | 13 | public void testArguments() { 14 | ScriptExecutor.evaluate(new InputStreamReader(ScriptExecutorTest.class.getResourceAsStream("GremlinScript.groovy")), Arrays.asList("1", "2", "3")); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /gremlin-groovy/src/test/resources/com/tinkerpop/gremlin/groovy/jsr223/GremlinScript.groovy: -------------------------------------------------------------------------------- 1 | println 'Using aX arguments' 2 | println a1 + a2 3 | assert (a1 + a2) == "12" 4 | println a3 5 | g = TinkerGraphFactory.createTinkerGraph(); 6 | println g.V.out.out.count() 7 | 8 | println 'Using args[x] arguments' 9 | println args[0] + args[1] 10 | assert (args[0] + args[1]) == "12" 11 | println args[2] 12 | g = TinkerGraphFactory.createTinkerGraph(); 13 | println g.V.out.out.count() -------------------------------------------------------------------------------- /gremlin-java/src/assembly/distribution.xml: -------------------------------------------------------------------------------- 1 | 2 | distribution 3 | 4 | zip 5 | 6 | 7 | 8 | 9 | pom.xml 10 | 11 | 12 | 13 | src 14 | 15 | 16 | target/apidocs 17 | 18 | 19 | target/site 20 | 21 | 22 | target 23 | 24 | gremlin-java-*.jar 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /gremlin-java/src/main/java/com/tinkerpop/gremlin/Tokens.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin; 2 | 3 | import com.tinkerpop.blueprints.Compare; 4 | import com.tinkerpop.blueprints.Contains; 5 | import com.tinkerpop.blueprints.Predicate; 6 | import com.tinkerpop.pipes.transform.TransformPipe; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class Tokens { 12 | 13 | public static final String VERSION = "2.7.0-SNAPSHOT"; 14 | public static final String LABEL = "label"; 15 | public static final String ID = "id"; 16 | 17 | public static enum T { 18 | /** 19 | * Greater than 20 | */ 21 | gt, 22 | /** 23 | * Less than 24 | */ 25 | lt, 26 | /** 27 | * Equal to 28 | */ 29 | eq, 30 | /** 31 | * Greater than or equal to 32 | */ 33 | gte, 34 | /** 35 | * Less than or equal to 36 | */ 37 | lte, 38 | /** 39 | * Not equal to 40 | */ 41 | neq, 42 | /** 43 | * Decrement 44 | */ 45 | decr, 46 | /** 47 | * Increment 48 | */ 49 | incr, 50 | /** 51 | * In collection 52 | */ 53 | in, 54 | /** 55 | * Not in collection 56 | */ 57 | notin 58 | } 59 | 60 | public static TransformPipe.Order mapOrder(final T t) { 61 | if (t.equals(T.decr)) 62 | return TransformPipe.Order.DECR; 63 | else if (t.equals(T.incr)) 64 | return TransformPipe.Order.INCR; 65 | else 66 | throw new IllegalArgumentException(t.toString() + " is an unknown order type"); 67 | } 68 | 69 | public static Predicate mapPredicate(final T t) { 70 | if (t.equals(T.eq)) 71 | return Compare.EQUAL; 72 | else if (t.equals(T.neq)) 73 | return Compare.NOT_EQUAL; 74 | else if (t.equals(T.lt)) 75 | return Compare.LESS_THAN; 76 | else if (t.equals(T.lte)) 77 | return Compare.LESS_THAN_EQUAL; 78 | else if (t.equals(T.gt)) 79 | return Compare.GREATER_THAN; 80 | else if (t.equals(T.gte)) 81 | return Compare.GREATER_THAN_EQUAL; 82 | else if (t.equals(T.in)) 83 | return Contains.IN; 84 | else if (t.equals(T.notin)) 85 | return Contains.NOT_IN; 86 | else 87 | throw new IllegalArgumentException(t.toString() + " is an unknown filter type"); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /gremlin-java/src/main/java/com/tinkerpop/gremlin/Version.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * @author Marko A. Rodriguez (http://markorodriguez.com) 7 | */ 8 | public class Version { 9 | 10 | public static void main(final String[] arguments) throws IOException { 11 | System.out.println("gremlin " + Tokens.VERSION); 12 | } 13 | } 14 | 15 | 16 | -------------------------------------------------------------------------------- /gremlin-java/src/main/java/com/tinkerpop/gremlin/java/GremlinStartPipe.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.pipes.IdentityPipe; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public class GremlinStartPipe extends IdentityPipe { 13 | 14 | private final boolean startIsGraph; 15 | 16 | public GremlinStartPipe(final Object start) { 17 | this.startIsGraph = start instanceof Graph; 18 | } 19 | 20 | public List getCurrentPath() { 21 | return this.startIsGraph ? new ArrayList() : super.getCurrentPath(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/FunctionStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 6 | import com.tinkerpop.gremlin.test.ComplianceTest; 7 | import com.tinkerpop.pipes.PipeFunction; 8 | 9 | import java.util.Iterator; 10 | 11 | /** 12 | * @author Marko A. Rodriguez (http://markorodriguez.com) 13 | */ 14 | public class FunctionStepTest extends com.tinkerpop.gremlin.test.FunctionStepTest { 15 | 16 | Graph g = TinkerGraphFactory.createTinkerGraph(); 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_out_stepXnext_nameX() { 23 | super.test_g_v1_out_stepXnext_nameX(new GremlinPipeline(g.getVertex(1)).out().step(new PipeFunction, Vertex>() { 24 | public Vertex compute(Iterator iterator) { 25 | return iterator.next(); 26 | } 27 | }).property("name")); 28 | 29 | super.test_g_v1_out_stepXnext_nameX(new GremlinPipeline(g.getVertex(1)).optimize(false).out().step(new PipeFunction, Vertex>() { 30 | public Vertex compute(Iterator iterator) { 31 | return iterator.next(); 32 | } 33 | }).property("name")); 34 | } 35 | } -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/GremlinPipelineTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 6 | import com.tinkerpop.pipes.PipeFunction; 7 | import junit.framework.TestCase; 8 | 9 | public class GremlinPipelineTest extends TestCase { 10 | public void testCasting() { 11 | 12 | Graph graph = TinkerGraphFactory.createTinkerGraph(); 13 | GremlinPipeline pipeline = new GremlinPipeline(graph.getVertices()); 14 | assertTrue(pipeline == pipeline.cast(Vertex.class)); 15 | 16 | //This should compile without warnings 17 | pipeline.as("person").out("knows").has("name", "josh").back("person").cast(Vertex.class) 18 | .filter(new PipeFunction() { 19 | 20 | @Override 21 | public Boolean compute(Vertex argument) { 22 | return true; 23 | } 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/GremlinStartPipeTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 5 | import com.tinkerpop.pipes.Pipe; 6 | import com.tinkerpop.pipes.util.StartPipe; 7 | import junit.framework.TestCase; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public class GremlinStartPipeTest extends TestCase { 13 | 14 | public void testNoGraphInPath() { 15 | Graph graph = TinkerGraphFactory.createTinkerGraph(); 16 | 17 | Pipe pipe = new GremlinStartPipe(graph); 18 | pipe.enablePath(true); 19 | assertEquals(pipe.getCurrentPath().size(), 0); 20 | 21 | pipe = new StartPipe(graph); 22 | pipe.enablePath(true); 23 | assertEquals(pipe.getCurrentPath().size(), 1); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/UtilitiesTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 6 | import com.tinkerpop.gremlin.test.ComplianceTest; 7 | 8 | import java.util.ArrayList; 9 | 10 | /** 11 | * @author Marko A. Rodriguez (http://markorodriguez.com) 12 | */ 13 | public class UtilitiesTest extends com.tinkerpop.gremlin.test.UtilitiesTest { 14 | 15 | Graph g = TinkerGraphFactory.createTinkerGraph(); 16 | 17 | public void testCompliance() { 18 | ComplianceTest.testCompliance(this.getClass()); 19 | } 20 | 21 | public void test_g_v1_out_toList() { 22 | super.test_g_v1_out_toList(new GremlinPipeline(g.getVertex(1)).out().toList()); 23 | } 24 | 25 | public void test_g_v1_out_nextX1X() { 26 | super.test_g_v1_out_nextX1X(new GremlinPipeline(g.getVertex(1)).out().next(1)); 27 | } 28 | 29 | public void test_g_v1_out_fillXlistX() { 30 | super.test_g_v1_out_fillXlistX(new GremlinPipeline(g.getVertex(1)).out().fill(new ArrayList())); 31 | } 32 | 33 | public void test_g_V_countXX() { 34 | super.test_g_V_countXX(new GremlinPipeline(g.getVertices()).count()); 35 | } 36 | 37 | public void test_g_E_remove() { 38 | Graph temp = TinkerGraphFactory.createTinkerGraph(); 39 | new GremlinPipeline(temp.getEdges()).remove(); 40 | super.test_g_E_remove(temp); 41 | } 42 | 43 | public void test_g_V_hasXidX1X_name_equals_g_v1_name() { 44 | super.test_g_V_hasXidX1X_name_equals_g_v1_name(new GremlinPipeline(g.getVertices()).has("id", "1").property("name"), 45 | new GremlinPipeline(g.getVertex(1)).property("name")); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/branch/SplitMergeStepsTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.branch; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 5 | import com.tinkerpop.gremlin.java.GremlinPipeline; 6 | import com.tinkerpop.gremlin.test.ComplianceTest; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class SplitMergeStepsTest extends com.tinkerpop.gremlin.test.branch.SplitMergeStepsTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | 15 | public void testCompliance() { 16 | ComplianceTest.testCompliance(this.getClass()); 17 | } 18 | 19 | public void test_g_v1_out_copySplitXpropertyXnameX__propertyXageXX_fairMerge() { 20 | super.test_g_v1_out_copySplitXpropertyXnameX__propertyXageXX_fairMerge(new GremlinPipeline(g.getVertex(1)).out().copySplit(new GremlinPipeline().property("name"), new GremlinPipeline().property("age")).fairMerge()); 21 | super.test_g_v1_out_copySplitXpropertyXnameX__propertyXageXX_fairMerge(new GremlinPipeline(g.getVertex(1)).optimize(false).out().copySplit(new GremlinPipeline().optimize(false).property("name"), new GremlinPipeline().property("age")).fairMerge()); 22 | } 23 | 24 | public void test_g_v1_outXknowsX_copySplitXpropertyXnameX__propertyXageXX_exhaustMerge() { 25 | super.test_g_v1_outXknowsX_copySplitXpropertyXnameX__propertyXageXX_exhaustMerge(new GremlinPipeline(g.getVertex(1)).out("knows").copySplit(new GremlinPipeline().property("name"), new GremlinPipeline().property("age")).exhaustMerge()); 26 | super.test_g_v1_outXknowsX_copySplitXpropertyXnameX__propertyXageXX_exhaustMerge(new GremlinPipeline(g.getVertex(1)).optimize(false).out("knows").copySplit(new GremlinPipeline().optimize(false).property("name"), new GremlinPipeline().property("age")).exhaustMerge()); 27 | } 28 | 29 | public void test_g_v1_outXknowsX_copySplitXpropertyXnameX__propertyXageXX_exhaustMerge_path() { 30 | super.test_g_v1_outXknowsX_copySplitXpropertyXnameX__propertyXageXX_exhaustMerge_path(new GremlinPipeline(g.getVertex(1)).out("knows").copySplit(new GremlinPipeline().property("name"), new GremlinPipeline().property("age")).exhaustMerge().path()); 31 | super.test_g_v1_outXknowsX_copySplitXpropertyXnameX__propertyXageXX_exhaustMerge_path(new GremlinPipeline(g.getVertex(1)).optimize(false).out("knows").copySplit(new GremlinPipeline().property("name"), new GremlinPipeline().property("age")).exhaustMerge().path()); 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/filter/DedupStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.filter; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 6 | import com.tinkerpop.gremlin.java.GremlinPipeline; 7 | import com.tinkerpop.gremlin.test.ComplianceTest; 8 | import com.tinkerpop.pipes.PipeFunction; 9 | 10 | /** 11 | * @author Marko A. Rodriguez (http://markorodriguez.com) 12 | */ 13 | public class DedupStepTest extends com.tinkerpop.gremlin.test.filter.DedupStepTest { 14 | 15 | Graph g = TinkerGraphFactory.createTinkerGraph(); 16 | 17 | public void testCompliance() { 18 | ComplianceTest.testCompliance(this.getClass()); 19 | } 20 | 21 | public void test_g_V_both_dedup_name() { 22 | super.test_g_V_both_dedup_name(new GremlinPipeline(g.getVertices()).both().dedup().property("name")); 23 | super.test_g_V_both_dedup_name(new GremlinPipeline(g.getVertices()).optimize(false).both().dedup().property("name")); 24 | } 25 | 26 | public void test_g_V_both_dedupXlangX_name() { 27 | super.test_g_V_both_dedupXlangX_name(new GremlinPipeline(g.getVertices()).both().dedup(new PipeFunction() { 28 | public String compute(final Vertex vertex) { 29 | return (String) vertex.getProperty("lang"); 30 | } 31 | }).property("name")); 32 | 33 | super.test_g_V_both_dedupXlangX_name(new GremlinPipeline(g).optimize(false).V().both().dedup(new PipeFunction() { 34 | public String compute(final Vertex vertex) { 35 | return (String) vertex.getProperty("lang"); 36 | } 37 | }).property("name")); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/filter/ExceptStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.filter; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 6 | import com.tinkerpop.gremlin.java.GremlinPipeline; 7 | import com.tinkerpop.gremlin.test.ComplianceTest; 8 | 9 | import java.util.Arrays; 10 | import java.util.HashSet; 11 | import java.util.Set; 12 | 13 | /** 14 | * @author Marko A. Rodriguez (http://markorodriguez.com) 15 | */ 16 | public class ExceptStepTest extends com.tinkerpop.gremlin.test.filter.ExceptStepTest { 17 | 18 | Graph g = TinkerGraphFactory.createTinkerGraph(); 19 | 20 | public void testCompliance() { 21 | ComplianceTest.testCompliance(this.getClass()); 22 | } 23 | 24 | public void test_g_v1_out_exceptXg_v2X() { 25 | super.test_g_v1_out_exceptXg_v2X(new GremlinPipeline(g.getVertex(1)).out().except(Arrays.asList(g.getVertex(2)))); 26 | super.test_g_v1_out_exceptXg_v2X(new GremlinPipeline(g.getVertex(1)).optimize(false).out().except(Arrays.asList(g.getVertex(2)))); 27 | } 28 | 29 | public void test_g_v1_out_aggregateXxX_out_exceptXxX() { 30 | Set x = new HashSet(); 31 | super.test_g_v1_out_aggregateXxX_out_exceptXxX(new GremlinPipeline(g.getVertex(1)).out().aggregate(x).out().except(x)); 32 | 33 | x = new HashSet(); 34 | super.test_g_v1_out_aggregateXxX_out_exceptXxX(new GremlinPipeline(g.getVertex(1)).optimize(false).out().aggregate(x).out().except(x)); 35 | } 36 | 37 | public void test_g_v1_outXcreatedX_inXcreatedX_exceptXg_v1X_propertyXnameX() { 38 | super.test_g_v1_outXcreatedX_inXcreatedX_exceptXg_v1X_propertyXnameX(new GremlinPipeline(g.getVertex(1)).out("created").in("created").except(Arrays.asList(g.getVertex(1))).property("name")); 39 | super.test_g_v1_outXcreatedX_inXcreatedX_exceptXg_v1X_propertyXnameX(new GremlinPipeline(g.getVertex(1)).optimize(false).out("created").in("created").except(Arrays.asList(g.getVertex(1))).property("name")); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/filter/HasNotStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.filter; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 5 | import com.tinkerpop.gremlin.java.GremlinPipeline; 6 | import com.tinkerpop.gremlin.test.ComplianceTest; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class HasNotStepTest extends com.tinkerpop.gremlin.test.filter.HasNotStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | 15 | public void testCompliance() { 16 | ComplianceTest.testCompliance(this.getClass()); 17 | } 18 | 19 | public void test_g_V_hasNotXname_markoX() { 20 | super.test_g_V_hasNotXname_markoX(new GremlinPipeline(g).V().hasNot("name", "marko")); 21 | super.test_g_V_hasNotXname_markoX(new GremlinPipeline(g).optimize(false).V().hasNot("name", "marko")); 22 | } 23 | 24 | public void test_g_V_hasNotXname_blahX() { 25 | super.test_g_V_hasNotXname_blahX(new GremlinPipeline(g.getVertices()).hasNot("name", "blah")); 26 | super.test_g_V_hasNotXname_blahX(new GremlinPipeline(g).optimize(false).V().hasNot("name", "blah")); 27 | } 28 | 29 | public void test_g_V_hasNotXblahX() { 30 | super.test_g_V_hasNotXblahX(new GremlinPipeline(g).V().hasNot("blah")); 31 | super.test_g_V_hasNotXblahX(new GremlinPipeline(g.getVertices()).optimize(false).hasNot("blah")); 32 | } 33 | } -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/filter/HasStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.filter; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 5 | import com.tinkerpop.gremlin.Tokens.T; 6 | import com.tinkerpop.gremlin.java.GremlinPipeline; 7 | import com.tinkerpop.gremlin.test.ComplianceTest; 8 | 9 | import java.util.Arrays; 10 | 11 | /** 12 | * @author Marko A. Rodriguez (http://markorodriguez.com) 13 | */ 14 | public class HasStepTest extends com.tinkerpop.gremlin.test.filter.HasStepTest { 15 | 16 | Graph g = TinkerGraphFactory.createTinkerGraph(); 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_V_hasXname_markoX() { 23 | super.test_g_V_hasXname_markoX(new GremlinPipeline(g).V().has("name", "marko")); 24 | super.test_g_V_hasXname_markoX(new GremlinPipeline(g.getVertices()).optimize(false).has("name", "marko")); 25 | } 26 | 27 | public void test_g_V_hasXname_blahX() { 28 | super.test_g_V_hasXname_blahX(new GremlinPipeline(g.getVertices()).has("name", "blah")); 29 | super.test_g_V_hasXname_blahX(new GremlinPipeline(g.getVertices()).optimize(false).has("name", "blah")); 30 | } 31 | 32 | public void test_g_V_hasXblahX() { 33 | super.test_g_V_hasXblahX(new GremlinPipeline(g.getVertices()).has("blah")); 34 | super.test_g_V_hasXblahX(new GremlinPipeline(g).V().optimize(false).has("blah")); 35 | } 36 | 37 | public void test_g_v1_out_hasXid_2X() { 38 | super.test_g_v1_out_hasXid_2X(new GremlinPipeline(g.getVertex(1)).out().has("id", "2")); 39 | super.test_g_v1_out_hasXid_2X(new GremlinPipeline(g.getVertex(1)).optimize(false).out().has("id", "2")); 40 | } 41 | 42 | public void test_g_V_hasXage_gt_30X() { 43 | super.test_g_V_hasXage_gt_30X(new GremlinPipeline(g).V().has("age", T.gt, 30)); 44 | super.test_g_V_hasXage_gt_30X(new GremlinPipeline(g).V().optimize(false).has("age", T.gt, 30)); 45 | } 46 | 47 | public void test_g_E_hasXlabelXknowsX() { 48 | super.test_g_E_hasXlabelXknowsX(new GremlinPipeline(g).E().has("label", T.eq, "knows")); 49 | super.test_g_E_hasXlabelXknowsX(new GremlinPipeline(g).optimize(false).E().has("label", T.eq, "knows")); 50 | } 51 | 52 | public void test_g_E_hasXlabelXknows_createdX() { 53 | super.test_g_E_hasXlabelXknows_createdX(new GremlinPipeline(g.getEdges()).has("label", T.in, Arrays.asList("knows", "created"))); 54 | super.test_g_E_hasXlabelXknows_createdX(new GremlinPipeline(g).E().optimize(false).has("label", T.in, Arrays.asList("knows", "created"))); 55 | 56 | } 57 | } -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/filter/IntervalStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.filter; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 5 | import com.tinkerpop.gremlin.java.GremlinPipeline; 6 | import com.tinkerpop.gremlin.test.ComplianceTest; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class IntervalStepTest extends com.tinkerpop.gremlin.test.filter.IntervalStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | 15 | public void testCompliance() { 16 | ComplianceTest.testCompliance(this.getClass()); 17 | } 18 | 19 | public void test_g_v1_outE_intervalXweight_0_06X_inV() { 20 | super.test_g_v1_outE_intervalXweight_0_06X_inV(new GremlinPipeline(g.getVertex(1)).outE().interval("weight", 0.0f, 0.6f).inV()); 21 | super.test_g_v1_outE_intervalXweight_0_06X_inV(new GremlinPipeline(g.getVertex(1)).optimize(false).outE().interval("weight", 0.0f, 0.6f).inV()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/filter/RangeStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.filter; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 5 | import com.tinkerpop.gremlin.java.GremlinPipeline; 6 | import com.tinkerpop.gremlin.test.ComplianceTest; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class RangeStepTest extends com.tinkerpop.gremlin.test.filter.RangeStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | 15 | public void testCompliance() { 16 | ComplianceTest.testCompliance(this.getClass()); 17 | } 18 | 19 | public void test_g_v1_out_rangeX0_1X() { 20 | super.test_g_v1_out_rangeX0_1X(new GremlinPipeline(g.getVertex(1)).out().range(0, 1)); 21 | super.test_g_v1_out_rangeX0_1X(new GremlinPipeline(g.getVertex(1)).optimize(false).out().range(0, 1)); 22 | } 23 | 24 | public void test_g_v1_outXknowsX_outEXcreatedX_rangeX0_0X_inV() { 25 | super.test_g_v1_outXknowsX_outEXcreatedX_rangeX0_0X_inV(new GremlinPipeline(g.getVertex(1)).out("knows").outE("created").range(0, 0).inV()); 26 | super.test_g_v1_outXknowsX_outEXcreatedX_rangeX0_0X_inV(new GremlinPipeline(g.getVertex(1)).optimize(false).out("knows").outE("created").range(0, 0).inV()); 27 | } 28 | 29 | public void test_g_v1_outXknowsX_outXcreatedX_rangeX0_0X() { 30 | super.test_g_v1_outXknowsX_outXcreatedX_rangeX0_0X(new GremlinPipeline(g.getVertex(1)).out("knows").out("created").range(0, 0)); 31 | super.test_g_v1_outXknowsX_outXcreatedX_rangeX0_0X(new GremlinPipeline(g.getVertex(1)).optimize(false).out("knows").out("created").range(0, 0)); 32 | } 33 | 34 | public void test_g_v1_outXcreatedX_inXcreatedX_rangeX1_2X() { 35 | super.test_g_v1_outXcreatedX_inXcreatedX_rangeX1_2X(new GremlinPipeline((g.getVertex(1))).out("created").in("created").range(1, 2)); 36 | super.test_g_v1_outXcreatedX_inXcreatedX_rangeX1_2X(new GremlinPipeline((g.getVertex(1))).optimize(false).out("created").in("created").range(1, 2)); 37 | } 38 | 39 | public void test_g_v1_outXcreatedX_inEXcreatedX_rangeX1_2X_outV() { 40 | super.test_g_v1_outXcreatedX_inEXcreatedX_rangeX1_2X_outV(new GremlinPipeline((g.getVertex(1))).out("created").inE("created").range(1, 2).outV()); 41 | super.test_g_v1_outXcreatedX_inEXcreatedX_rangeX1_2X_outV(new GremlinPipeline((g.getVertex(1))).optimize(false).out("created").inE("created").range(1, 2).outV()); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/filter/RetainStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.filter; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 6 | import com.tinkerpop.gremlin.java.GremlinPipeline; 7 | import com.tinkerpop.gremlin.test.ComplianceTest; 8 | 9 | import java.util.Arrays; 10 | import java.util.HashSet; 11 | import java.util.Set; 12 | 13 | /** 14 | * @author Marko A. Rodriguez (http://markorodriguez.com) 15 | */ 16 | public class RetainStepTest extends com.tinkerpop.gremlin.test.filter.RetainStepTest { 17 | 18 | Graph g = TinkerGraphFactory.createTinkerGraph(); 19 | 20 | public void testCompliance() { 21 | ComplianceTest.testCompliance(this.getClass()); 22 | } 23 | 24 | public void test_g_v1_out_retainXg_v2X() { 25 | super.test_g_v1_out_retainXg_v2X(new GremlinPipeline(g.getVertex(1)).out().retain(Arrays.asList(g.getVertex(2)))); 26 | super.test_g_v1_out_retainXg_v2X(new GremlinPipeline(g.getVertex(1)).optimize(false).out().retain(Arrays.asList(g.getVertex(2)))); 27 | } 28 | 29 | public void test_g_v1_out_aggregateXxX_out_retainXxX() { 30 | Set x = new HashSet(); 31 | super.test_g_v1_out_aggregateXxX_out_retainXxX(new GremlinPipeline(g.getVertex(1)).out().aggregate(x).out().retain(x)); 32 | 33 | x = new HashSet(); 34 | super.test_g_v1_out_aggregateXxX_out_retainXxX(new GremlinPipeline(g.getVertex(1)).optimize(false).out().aggregate(x).out().retain(x)); 35 | } 36 | } -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/sideeffect/AggregateStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.sideeffect; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 6 | import com.tinkerpop.gremlin.java.GremlinPipeline; 7 | import com.tinkerpop.gremlin.test.ComplianceTest; 8 | import com.tinkerpop.pipes.PipeFunction; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | * @author Marko A. Rodriguez (http://markorodriguez.com) 15 | */ 16 | public class AggregateStepTest extends com.tinkerpop.gremlin.test.sideeffect.AggregateStepTest { 17 | 18 | Graph g = TinkerGraphFactory.createTinkerGraph(); 19 | 20 | public void testCompliance() { 21 | ComplianceTest.testCompliance(this.getClass()); 22 | } 23 | 24 | public void test_g_v1_aggregateXxX_outXcreatedX_inXcreatedX_exceptXxX() { 25 | List x = new ArrayList(); 26 | super.test_g_v1_aggregateXxX_outXcreatedX_inXcreatedX_exceptXxX(new GremlinPipeline(g.getVertex(1)).aggregate(x).out("created").in("created").except(x)); 27 | 28 | x = new ArrayList(); 29 | super.test_g_v1_aggregateXxX_outXcreatedX_inXcreatedX_exceptXxX(new GremlinPipeline(g.getVertex(1)).optimize(false).aggregate(x).out("created").in("created").except(x)); 30 | } 31 | 32 | public void test_g_V_propertyXnameX_aggregate_cap() { 33 | super.test_g_V_propertyXnameX_aggregate_cap(new GremlinPipeline(g.getVertices()).property("name").aggregate().cap()); 34 | super.test_g_V_propertyXnameX_aggregate_cap(new GremlinPipeline(g).optimize(false).V().property("name").aggregate().cap()); 35 | } 36 | 37 | public void test_g_V_aggregateXnameX_cap() { 38 | super.test_g_V_aggregateXnameX_cap(new GremlinPipeline(g).V().aggregate(new PipeFunction() { 39 | public String compute(Vertex vertex) { 40 | return (String) vertex.getProperty("name"); 41 | } 42 | }).cap()); 43 | 44 | super.test_g_V_aggregateXnameX_cap(new GremlinPipeline(g.getVertices()).optimize(false).aggregate(new PipeFunction() { 45 | public String compute(Vertex vertex) { 46 | return (String) vertex.getProperty("name"); 47 | } 48 | }).cap()); 49 | } 50 | } -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/sideeffect/GroupByStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.sideeffect; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 6 | import com.tinkerpop.gremlin.java.GremlinPipeline; 7 | import com.tinkerpop.gremlin.test.ComplianceTest; 8 | import com.tinkerpop.pipes.PipeFunction; 9 | 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author Marko A. Rodriguez (http://markorodriguez.com) 16 | */ 17 | public class GroupByStepTest extends com.tinkerpop.gremlin.test.sideeffect.GroupByStepTest { 18 | 19 | Graph g = TinkerGraphFactory.createTinkerGraph(); 20 | 21 | public void testCompliance() { 22 | ComplianceTest.testCompliance(this.getClass()); 23 | } 24 | 25 | public void test_g_V_groupByXlang_nameX() { 26 | Map> m = new HashMap>(); 27 | super.test_g_V_groupByXlang_nameX(new GremlinPipeline(g.getVertices()).groupBy(m, new PipeFunction() { 28 | public String compute(Vertex vertex) { 29 | return (String) vertex.getProperty("lang"); 30 | } 31 | }, new PipeFunction() { 32 | public String compute(Vertex vertex) { 33 | return (String) vertex.getProperty("name"); 34 | } 35 | } 36 | ), (Map) m); 37 | 38 | m = new HashMap>(); 39 | super.test_g_V_groupByXlang_nameX(new GremlinPipeline(g.getVertices()).optimize(false).groupBy(m, new PipeFunction() { 40 | public String compute(Vertex vertex) { 41 | return (String) vertex.getProperty("lang"); 42 | } 43 | }, new PipeFunction() { 44 | public String compute(Vertex vertex) { 45 | return (String) vertex.getProperty("name"); 46 | } 47 | } 48 | ), (Map) m); 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/sideeffect/LinkedStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.sideeffect; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 5 | import com.tinkerpop.gremlin.java.GremlinPipeline; 6 | 7 | /** 8 | * @author Marko A. Rodriguez (http://markorodriguez.com) 9 | */ 10 | public class LinkedStepTest extends com.tinkerpop.gremlin.test.sideeffect.LinkStepTest { 11 | 12 | public void test_g_v1_asXaX_outXcreatedX_inXcreatedX_linkBothXcocreator_aX() { 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | super.test_g_v1_asXaX_outXcreatedX_inXcreatedX_linkBothXcocreator_aX( 15 | new GremlinPipeline(g.getVertex(1)).as("a").out("created").in("created").linkBoth("cocreator", "a")); 16 | 17 | g = TinkerGraphFactory.createTinkerGraph(); 18 | super.test_g_v1_asXaX_outXcreatedX_inXcreatedX_linkBothXcocreator_aX( 19 | new GremlinPipeline(g.getVertex(1)).optimize(false).as("a").out("created").in("created").linkBoth("cocreator", "a")); 20 | } 21 | } -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/sideeffect/SideEffectStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.sideeffect; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 6 | import com.tinkerpop.gremlin.java.GremlinPipeline; 7 | import com.tinkerpop.gremlin.test.ComplianceTest; 8 | import com.tinkerpop.pipes.PipeFunction; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | * @author Marko A. Rodriguez (http://markorodriguez.com) 15 | */ 16 | public class SideEffectStepTest extends com.tinkerpop.gremlin.test.sideeffect.SideEffectStepTest { 17 | 18 | Graph g = TinkerGraphFactory.createTinkerGraph(); 19 | 20 | public void testCompliance() { 21 | ComplianceTest.testCompliance(this.getClass()); 22 | } 23 | 24 | public void test_g_v1_sideEffectXstore_aX_propertyXnameX() { 25 | final List a = new ArrayList(); 26 | super.test_g_v1_sideEffectXstore_aX_propertyXnameX(new GremlinPipeline(g.getVertex(1)).sideEffect(new PipeFunction() { 27 | public Object compute(Vertex vertex) { 28 | a.clear(); 29 | a.add(vertex); 30 | return null; 31 | } 32 | }).property("name")); 33 | assertEquals(a.get(0), g.getVertex(1)); 34 | } 35 | 36 | public void test_g_v1_out_sideEffectXincr_cX_propertyXnameX() { 37 | final List c = new ArrayList(); 38 | c.add(0); 39 | super.test_g_v1_out_sideEffectXincr_cX_propertyXnameX(new GremlinPipeline(g.getVertex(1)).out().sideEffect(new PipeFunction() { 40 | public Object compute(Vertex vertex) { 41 | Integer temp = c.get(0); 42 | c.clear(); 43 | c.add(temp + 1); 44 | return null; 45 | } 46 | }).property("name")); 47 | assertEquals(c.get(0), new Integer(3)); 48 | } 49 | 50 | public void test_g_v1_out_sideEffectXfalseX_propertyXnameX() { 51 | super.test_g_v1_out_sideEffectXfalseX_propertyXnameX(new GremlinPipeline(g.getVertex(1)).out().sideEffect(new PipeFunction() { 52 | public Object compute(Vertex vertex) { 53 | return false; 54 | } 55 | }).property("name")); 56 | 57 | super.test_g_v1_out_sideEffectXfalseX_propertyXnameX(new GremlinPipeline(g.getVertex(1)).optimize(false).out().sideEffect(new PipeFunction() { 58 | public Object compute(Vertex vertex) { 59 | return false; 60 | } 61 | }).property("name")); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/sideeffect/StoreStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.sideeffect; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 6 | import com.tinkerpop.gremlin.java.GremlinPipeline; 7 | import com.tinkerpop.gremlin.test.ComplianceTest; 8 | import com.tinkerpop.pipes.PipeFunction; 9 | 10 | /** 11 | * @author Marko A. Rodriguez (http://markorodriguez.com) 12 | */ 13 | public class StoreStepTest extends com.tinkerpop.gremlin.test.sideeffect.StoreStepTest { 14 | 15 | Graph g = TinkerGraphFactory.createTinkerGraph(); 16 | 17 | public void testCompliance() { 18 | ComplianceTest.testCompliance(this.getClass()); 19 | } 20 | 21 | public void test_g_V_propertyXnameX_store_cap() { 22 | super.test_g_V_propertyXnameX_store_cap(new GremlinPipeline(g).V().property("name").store().cap()); 23 | super.test_g_V_propertyXnameX_store_cap(new GremlinPipeline(g).optimize(false).V().property("name").store().cap()); 24 | } 25 | 26 | public void test_g_V_storeXnameX_cap() { 27 | super.test_g_V_storeXnameX_cap(new GremlinPipeline(g.getVertices()).store(new PipeFunction() { 28 | public String compute(Vertex vertex) { 29 | return (String) vertex.getProperty("name"); 30 | } 31 | }).cap()); 32 | 33 | super.test_g_V_storeXnameX_cap(new GremlinPipeline(g).optimize(false).V().store(new PipeFunction() { 34 | public String compute(Vertex vertex) { 35 | return (String) vertex.getProperty("name"); 36 | } 37 | }).cap()); 38 | } 39 | } -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/sideeffect/TreeStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.sideeffect; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 6 | import com.tinkerpop.gremlin.java.GremlinPipeline; 7 | import com.tinkerpop.gremlin.test.ComplianceTest; 8 | import com.tinkerpop.pipes.PipeFunction; 9 | 10 | /** 11 | * @author Marko A. Rodriguez (http://markorodriguez.com) 12 | */ 13 | public class TreeStepTest extends com.tinkerpop.gremlin.test.sideeffect.TreeStepTest { 14 | 15 | Graph graph = TinkerGraphFactory.createTinkerGraph(); 16 | 17 | 18 | public void testCompliance() { 19 | ComplianceTest.testCompliance(this.getClass()); 20 | } 21 | 22 | public void test_g_v1_out_out_treeXnameX_cap() { 23 | super.test_g_v1_out_out_treeXnameX_cap(new GremlinPipeline(graph.getVertex(1)).out().out().tree(new PipeFunction() { 24 | public String compute(Vertex vertex) { 25 | return (String) vertex.getProperty("name"); 26 | } 27 | }).cap()); 28 | 29 | super.test_g_v1_out_out_treeXnameX_cap(new GremlinPipeline(graph.getVertex(1)).optimize(false).out().out().tree(new PipeFunction() { 30 | public String compute(Vertex vertex) { 31 | return (String) vertex.getProperty("name"); 32 | } 33 | }).cap()); 34 | } 35 | } -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/transform/GatherStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.transform; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 6 | import com.tinkerpop.gremlin.java.GremlinPipeline; 7 | import com.tinkerpop.gremlin.test.ComplianceTest; 8 | import com.tinkerpop.pipes.Pipe; 9 | import com.tinkerpop.pipes.PipeFunction; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @author Marko A. Rodriguez (http://markorodriguez.com) 15 | */ 16 | public class GatherStepTest extends com.tinkerpop.gremlin.test.transform.GatherStepTest { 17 | 18 | Graph g = TinkerGraphFactory.createTinkerGraph(); 19 | 20 | public void testCompliance() { 21 | ComplianceTest.testCompliance(this.getClass()); 22 | } 23 | 24 | public void test_g_v1_out_gather(final Pipe> pipe) { 25 | super.test_g_v1_out_gather(new GremlinPipeline(g.getVertex(1)).out().gather()); 26 | super.test_g_v1_out_gather(new GremlinPipeline(g.getVertex(1)).optimize(false).out().gather()); 27 | } 28 | 29 | public void test_g_v1_out_gatherXget0X(final Pipe pipe) { 30 | super.test_g_v1_out_gatherXget0X(new GremlinPipeline(g.getVertex(1)).out().gather(new PipeFunction() { 31 | public Vertex compute(List argument) { 32 | return (Vertex) argument.get(0); 33 | } 34 | })); 35 | 36 | super.test_g_v1_out_gatherXget0X(new GremlinPipeline(g.getVertex(1)).optimize(false).out().gather(new PipeFunction() { 37 | public Vertex compute(List argument) { 38 | return (Vertex) argument.get(0); 39 | } 40 | })); 41 | } 42 | } -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/transform/MapStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.transform; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 5 | import com.tinkerpop.gremlin.java.GremlinPipeline; 6 | import com.tinkerpop.gremlin.test.ComplianceTest; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class MapStepTest extends com.tinkerpop.gremlin.test.transform.MapStepTest { 12 | 13 | Graph g = TinkerGraphFactory.createTinkerGraph(); 14 | 15 | public void testCompliance() { 16 | ComplianceTest.testCompliance(this.getClass()); 17 | } 18 | 19 | public void test_g_v1_map() { 20 | super.test_g_v1_map(new GremlinPipeline(g.getVertex(1)).map()); 21 | super.test_g_v1_map(new GremlinPipeline(g.getVertex(1)).optimize(false).map()); 22 | } 23 | 24 | public void test_g_v1_mapXname_idX() { 25 | super.test_g_v1_mapXname_idX(new GremlinPipeline(g.getVertex(1)).map("name", "id")); 26 | super.test_g_v1_mapXname_idX(new GremlinPipeline(g.getVertex(1)).optimize(false).map("name", "id")); 27 | } 28 | 29 | public void test_g_v1_outXknowsX_map() { 30 | super.test_g_v1_outXknowsX_map(new GremlinPipeline(g.getVertex(1)).out("knows").map()); 31 | super.test_g_v1_outXknowsX_map(new GremlinPipeline(g.getVertex(1)).optimize(false).out("knows").map()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /gremlin-java/src/test/java/com/tinkerpop/gremlin/java/transform/SelectStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.java.transform; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory; 6 | import com.tinkerpop.gremlin.java.GremlinPipeline; 7 | import com.tinkerpop.gremlin.test.ComplianceTest; 8 | import com.tinkerpop.pipes.PipeFunction; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | /** 14 | * @author Marko A. Rodriguez (http://markorodriguez.com) 15 | */ 16 | public class SelectStepTest extends com.tinkerpop.gremlin.test.transform.SelectStepTest { 17 | 18 | Graph g = TinkerGraphFactory.createTinkerGraph(); 19 | 20 | public void testCompliance() { 21 | ComplianceTest.testCompliance(this.getClass()); 22 | } 23 | 24 | public void test_g_v1_asXaX_outXknowsX_asXbX_select() { 25 | super.test_g_v1_asXaX_outXknowsX_asXbX_select(new GremlinPipeline(g.getVertex(1)).as("a").out("knows").as("b").select()); 26 | super.test_g_v1_asXaX_outXknowsX_asXbX_select(new GremlinPipeline(g.getVertex(1)).optimize(false).as("a").out("knows").as("b").select()); 27 | } 28 | 29 | public void test_g_v1_asXaX_outXknowsX_asXbX_selectXnameX() { 30 | super.test_g_v1_asXaX_outXknowsX_asXbX_selectXnameX(new GremlinPipeline(g.getVertex(1)).as("a").out("knows").as("b").select(new PipeFunction() { 31 | public String compute(Vertex vertex) { 32 | return (String) vertex.getProperty("name"); 33 | } 34 | })); 35 | 36 | super.test_g_v1_asXaX_outXknowsX_asXbX_selectXnameX(new GremlinPipeline(g.getVertex(1)).optimize(false).as("a").out("knows").as("b").select(new PipeFunction() { 37 | public String compute(Vertex vertex) { 38 | return (String) vertex.getProperty("name"); 39 | } 40 | })); 41 | } 42 | 43 | public void test_g_v1_asXaX_outXknowsX_asXbX_selectXaX() { 44 | super.test_g_v1_asXaX_outXknowsX_asXbX_selectXaX(new GremlinPipeline(g.getVertex(1)).as("a").out("knows").as("b").select(Arrays.asList("a"))); 45 | } 46 | 47 | public void test_g_v1_asXaX_outXknowsX_asXbX_selectXa_nameX() { 48 | super.test_g_v1_asXaX_outXknowsX_asXbX_selectXa_nameX(new GremlinPipeline(g.getVertex(1)).as("a").out("knows").as("b").select(Arrays.asList("a"), new PipeFunction() { 49 | public String compute(Vertex vertex) { 50 | return (String) vertex.getProperty("name"); 51 | } 52 | })); 53 | } 54 | } -------------------------------------------------------------------------------- /gremlin-test/src/assembly/distribution.xml: -------------------------------------------------------------------------------- 1 | 2 | distribution 3 | 4 | zip 5 | 6 | 7 | 8 | 9 | pom.xml 10 | 11 | 12 | 13 | src 14 | 15 | 16 | target/apidocs 17 | 18 | 19 | target/site 20 | 21 | 22 | target 23 | 24 | gremlin-test-*.jar 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/ComplianceTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import java.lang.reflect.Method; 6 | import java.util.HashSet; 7 | import java.util.Set; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public class ComplianceTest extends TestCase { 13 | 14 | public void testCompliance() { 15 | assertTrue(true); 16 | } 17 | 18 | public static void testCompliance(final Class testClass) { 19 | Set methodNames = new HashSet(); 20 | for (Method method : testClass.getMethods()) { 21 | if (method.getDeclaringClass().equals(testClass) && method.getName().startsWith("test")) { 22 | methodNames.add(method.getName()); 23 | } 24 | } 25 | for (Method method : testClass.getMethods()) { 26 | if (method.getName().startsWith("test")) { 27 | assertTrue(methodNames.contains(method.getName())); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/FunctionStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Iterator; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public class FunctionStepTest extends TestCase { 13 | 14 | public void testCompliance() { 15 | assertTrue(true); 16 | } 17 | 18 | public void test_g_v1_out_stepXnext_nameX(Iterator pipe) { 19 | List names = new ArrayList(); 20 | while (pipe.hasNext()) { 21 | names.add(pipe.next()); 22 | } 23 | assertEquals(names.size(), 3); 24 | assertTrue(names.contains("josh")); 25 | assertTrue(names.contains("vadas")); 26 | assertTrue(names.contains("lop")); 27 | } 28 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/UtilitiesTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test; 2 | 3 | import com.tinkerpop.blueprints.Edge; 4 | import com.tinkerpop.blueprints.Graph; 5 | import com.tinkerpop.blueprints.Vertex; 6 | import com.tinkerpop.pipes.Pipe; 7 | import junit.framework.TestCase; 8 | 9 | import java.util.ArrayList; 10 | import java.util.Arrays; 11 | import java.util.Collection; 12 | import java.util.List; 13 | 14 | /** 15 | * @author Marko A. Rodriguez (http://markorodriguez.com) 16 | */ 17 | public class UtilitiesTest extends TestCase { 18 | 19 | public void testCompliance() { 20 | assertTrue(true); 21 | } 22 | 23 | public void test_g_v1_out_toList(List vertices) { 24 | assertEquals(vertices.size(), 3); 25 | List names = new ArrayList(); 26 | for (Vertex vertex : vertices) { 27 | names.add((String) vertex.getProperty("name")); 28 | } 29 | assertEquals(names.size(), 3); 30 | assertTrue(names.contains("josh")); 31 | assertTrue(names.contains("lop")); 32 | assertTrue(names.contains("vadas")); 33 | } 34 | 35 | public void test_g_v1_out_nextX1X(List vertices) { 36 | assertEquals(vertices.size(), 1); 37 | Vertex vertex = vertices.get(0); 38 | List names = Arrays.asList("josh", "vadas", "lop"); 39 | assertTrue(names.contains((String) vertex.getProperty("name"))); 40 | } 41 | 42 | public void test_g_v1_out_fillXlistX(Collection list) { 43 | this.test_g_v1_out_toList(new ArrayList(list)); 44 | } 45 | 46 | public void test_g_V_countXX(Long count) { 47 | assertEquals(count, new Long(6)); 48 | } 49 | 50 | public void test_g_E_remove(Graph graph) { 51 | int count = 0; 52 | for (Edge e : graph.getEdges()) { 53 | count++; 54 | } 55 | assertEquals(count, 0); 56 | for (Vertex v : graph.getVertices()) { 57 | count++; 58 | } 59 | assertEquals(count, 6); 60 | } 61 | 62 | public void test_g_V_hasXidX1X_name_equals_g_v1_name(Pipe pipe1, Pipe pipe2) { 63 | assertTrue(pipe1.equals(pipe2)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/branch/IfThenElseStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.branch; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import java.util.HashSet; 6 | import java.util.Iterator; 7 | import java.util.Set; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public class IfThenElseStepTest extends TestCase { 13 | 14 | public void testCompliance() { 15 | assertTrue(true); 16 | } 17 | 18 | public void test_g_v1_out_ifThenElseXlang_eq_java__it__outX_name(Iterator pipe) { 19 | int counter = 0; 20 | Set names = new HashSet(); 21 | while (pipe.hasNext()) { 22 | counter++; 23 | names.add(pipe.next()); 24 | } 25 | assertEquals(counter, 3); 26 | assertEquals(names.size(), 2); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/branch/LoopStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.branch; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Iterator; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public class LoopStepTest extends TestCase { 13 | 14 | public void testCompliance() { 15 | assertTrue(true); 16 | } 17 | 18 | public void test_g_v1_out_loopX1_loops_lt_3X_propertyXnameX(Iterator pipe) { 19 | List names = new ArrayList(); 20 | while (pipe.hasNext()) { 21 | names.add(pipe.next()); 22 | } 23 | assertEquals(names.size(), 2); 24 | assertTrue(names.contains("ripple")); 25 | assertTrue(names.contains("lop")); 26 | } 27 | 28 | public void test_g_v1_asXhereX_out_loopXhere_loops_lt_3X_propertyXnameX(Iterator pipe) { 29 | this.test_g_v1_out_loopX1_loops_lt_3X_propertyXnameX(pipe); 30 | } 31 | 32 | public void test_g_V_out_loopX1_loops_lt_3X_propertyXnameX(Iterator pipe) { 33 | List names = new ArrayList(); 34 | while (pipe.hasNext()) { 35 | names.add(pipe.next()); 36 | } 37 | assertEquals(names.size(), 2); 38 | assertTrue(names.contains("ripple")); 39 | assertTrue(names.contains("lop")); 40 | } 41 | 42 | public void test_g_V_asXhereX_out_loopXhere_loops_lt_3X_propertyXnameX(Iterator pipe) { 43 | this.test_g_V_out_loopX1_loops_lt_3X_propertyXnameX(pipe); 44 | } 45 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/filter/BackStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.filter; 2 | 3 | import com.tinkerpop.blueprints.Edge; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import junit.framework.TestCase; 6 | 7 | import java.util.HashSet; 8 | import java.util.Iterator; 9 | import java.util.Set; 10 | 11 | /** 12 | * @author Marko A. Rodriguez (http://markorodriguez.com) 13 | */ 14 | public class BackStepTest extends TestCase { 15 | 16 | public void testCompliance() { 17 | assertTrue(true); 18 | } 19 | 20 | public void test_g_v1_out_backX1X(Iterator pipe) { 21 | int counter = 0; 22 | while (pipe.hasNext()) { 23 | counter++; 24 | assertEquals(((Vertex) pipe.next()).getProperty("name"), "marko"); 25 | } 26 | assertEquals(counter, 1); 27 | } 28 | 29 | public void test_g_v1_asXhereX_out_backXhereX(Iterator pipe) { 30 | this.test_g_v1_out_backX1X(pipe); 31 | } 32 | 33 | public void test_g_v4_out_filterXlang_eq_javaX_backX1X(Iterator pipe) { 34 | int counter = 0; 35 | while (pipe.hasNext()) { 36 | counter++; 37 | Vertex vertex = (Vertex) pipe.next(); 38 | assertEquals(vertex.getProperty("lang"), "java"); 39 | assertTrue(vertex.getProperty("name").equals("ripple") || vertex.getProperty("name").equals("lop")); 40 | } 41 | assertEquals(counter, 2); 42 | } 43 | 44 | public void test_g_v1_outE_inV_hasXname_vadasX_backX2X(Iterator pipe) { 45 | Edge edge = pipe.next(); 46 | assertEquals(edge.getLabel(), "knows"); 47 | assertEquals(edge.getId(), "7"); 48 | assertEquals(edge.getProperty("weight"), 0.5f); 49 | assertFalse(pipe.hasNext()); 50 | } 51 | 52 | public void test_g_v1_outE_asXhereX_inV_hasXname_vadasX_backXhereX(Iterator pipe) { 53 | this.test_g_v1_outE_inV_hasXname_vadasX_backX2X(pipe); 54 | } 55 | 56 | public void test_g_v4_out_asXhereX_filterXlang_eq_javaX_backXhereX(Iterator pipe) { 57 | this.test_g_v4_out_filterXlang_eq_javaX_backX1X(pipe); 58 | } 59 | 60 | public void test_g_v4_out_asXhereX_filterXlang_eq_javaX_backXhereX_propertyXnameX(Iterator pipe) { 61 | int counter = 0; 62 | Set names = new HashSet(); 63 | while (pipe.hasNext()) { 64 | counter++; 65 | names.add(pipe.next()); 66 | } 67 | assertEquals(counter, 2); 68 | assertEquals(names.size(), 2); 69 | assertTrue(names.contains("ripple")); 70 | assertTrue(names.contains("lop")); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/filter/DedupStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.filter; 2 | 3 | import com.tinkerpop.pipes.util.PipeHelper; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Iterator; 8 | import java.util.List; 9 | 10 | /** 11 | * @author Marko A. Rodriguez (http://markorodriguez.com) 12 | */ 13 | public class DedupStepTest extends TestCase { 14 | 15 | public void testCompliance() { 16 | assertTrue(true); 17 | } 18 | 19 | public void test_g_V_both_dedup_name(Iterator pipe) { 20 | List names = new ArrayList(); 21 | PipeHelper.fillCollection(pipe, names); 22 | assertEquals(names.size(), 6); 23 | assertTrue(names.contains("marko")); 24 | assertTrue(names.contains("vadas")); 25 | assertTrue(names.contains("lop")); 26 | assertTrue(names.contains("josh")); 27 | assertTrue(names.contains("ripple")); 28 | assertTrue(names.contains("peter")); 29 | assertFalse(pipe.hasNext()); 30 | } 31 | 32 | public void test_g_V_both_dedupXlangX_name(Iterator pipe) { 33 | List names = new ArrayList(); 34 | PipeHelper.fillCollection(pipe, names); 35 | assertEquals(names.size(), 2); 36 | assertTrue(names.contains("marko") || names.contains("peter") || names.contains("josh") || names.contains("vadas")); 37 | assertTrue(names.contains("lop") || names.contains("ripple")); 38 | assertFalse(pipe.hasNext()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/filter/ExceptStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.filter; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.Arrays; 7 | import java.util.HashSet; 8 | import java.util.Iterator; 9 | import java.util.List; 10 | import java.util.Set; 11 | 12 | /** 13 | * @author Marko A. Rodriguez (http://markorodriguez.com) 14 | */ 15 | public class ExceptStepTest extends TestCase { 16 | 17 | public void testCompliance() { 18 | assertTrue(true); 19 | } 20 | 21 | public void test_g_v1_out_exceptXg_v2X(Iterator pipe) { 22 | int counter = 0; 23 | Set vertices = new HashSet(); 24 | while (pipe.hasNext()) { 25 | counter++; 26 | Vertex vertex = pipe.next(); 27 | vertices.add(vertex); 28 | assertTrue(vertex.getProperty("name").equals("josh") || vertex.getProperty("name").equals("lop")); 29 | } 30 | assertEquals(counter, 2); 31 | assertEquals(vertices.size(), 2); 32 | } 33 | 34 | public void test_g_v1_out_aggregateXxX_out_exceptXxX(Iterator pipe) { 35 | assertEquals(pipe.next().getProperty("name"), "ripple"); 36 | assertFalse(pipe.hasNext()); 37 | } 38 | 39 | public void test_g_v1_outXcreatedX_inXcreatedX_exceptXg_v1X_propertyXnameX(Iterator pipe) { 40 | List names = Arrays.asList(pipe.next(), pipe.next()); 41 | assertFalse(pipe.hasNext()); 42 | assertEquals(names.size(), 2); 43 | assertTrue(names.contains("peter")); 44 | assertTrue(names.contains("josh")); 45 | } 46 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/filter/FilterStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.filter; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.HashSet; 7 | import java.util.Iterator; 8 | import java.util.Set; 9 | 10 | /** 11 | * @author Marko A. Rodriguez (http://markorodriguez.com) 12 | */ 13 | public class FilterStepTest extends TestCase { 14 | 15 | public void testCompliance() { 16 | assertTrue(true); 17 | } 18 | 19 | public void test_g_V_filterXfalseX(Iterator pipe) { 20 | assertFalse(pipe.hasNext()); 21 | } 22 | 23 | public void test_g_V_filterXtrueX(Iterator pipe) { 24 | int counter = 0; 25 | Set vertices = new HashSet(); 26 | while (pipe.hasNext()) { 27 | counter++; 28 | vertices.add(pipe.next()); 29 | } 30 | assertEquals(counter, 6); 31 | assertEquals(vertices.size(), 6); 32 | } 33 | 34 | public void test_g_V_filterXlang_eq_javaX(Iterator pipe) { 35 | int counter = 0; 36 | Set vertices = new HashSet(); 37 | while (pipe.hasNext()) { 38 | counter++; 39 | Vertex vertex = pipe.next(); 40 | vertices.add(vertex); 41 | assertTrue(vertex.getProperty("name").equals("ripple") || 42 | vertex.getProperty("name").equals("lop")); 43 | } 44 | assertEquals(counter, 2); 45 | assertEquals(vertices.size(), 2); 46 | } 47 | 48 | public void test_g_v1_out_filterXage_gt_30X(Iterator pipe) { 49 | assertEquals(pipe.next().getProperty("age"), 32); 50 | assertFalse(pipe.hasNext()); 51 | } 52 | 53 | public void test_g_V_filterXname_startsWith_m_OR_name_startsWith_pX(Iterator pipe) { 54 | int counter = 0; 55 | Set vertices = new HashSet(); 56 | while (pipe.hasNext()) { 57 | counter++; 58 | Vertex vertex = pipe.next(); 59 | vertices.add(vertex); 60 | assertTrue(vertex.getProperty("name").equals("marko") || 61 | vertex.getProperty("name").equals("peter")); 62 | } 63 | assertEquals(counter, 2); 64 | assertEquals(vertices.size(), 2); 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/filter/HasNotStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.filter; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.Iterator; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class HasNotStepTest extends TestCase { 12 | 13 | public void testCompliance() { 14 | assertTrue(true); 15 | } 16 | 17 | public void test_g_V_hasNotXname_markoX(Iterator pipe) { 18 | int counter = 0; 19 | while (pipe.hasNext()) { 20 | counter++; 21 | assertNotSame(pipe.next().getProperty("name"), "marko"); 22 | } 23 | assertEquals(counter, 5); 24 | } 25 | 26 | public void test_g_V_hasNotXname_blahX(Iterator pipe) { 27 | int counter = 0; 28 | while (pipe.hasNext()) { 29 | counter++; 30 | pipe.next(); 31 | } 32 | assertEquals(counter, 6); 33 | } 34 | 35 | public void test_g_V_hasNotXblahX(Iterator pipe) { 36 | int counter = 0; 37 | while (pipe.hasNext()) { 38 | pipe.next(); 39 | counter++; 40 | } 41 | assertEquals(counter, 6); 42 | } 43 | 44 | 45 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/filter/HasStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.filter; 2 | 3 | import com.tinkerpop.blueprints.Edge; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import com.tinkerpop.pipes.util.PipeHelper; 6 | import junit.framework.TestCase; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Iterator; 10 | import java.util.List; 11 | 12 | /** 13 | * @author Marko A. Rodriguez (http://markorodriguez.com) 14 | */ 15 | public class HasStepTest extends TestCase { 16 | 17 | public void testCompliance() { 18 | assertTrue(true); 19 | } 20 | 21 | public void test_g_V_hasXname_markoX(Iterator pipe) { 22 | assertEquals(pipe.next().getProperty("name"), "marko"); 23 | assertFalse(pipe.hasNext()); 24 | } 25 | 26 | public void test_g_V_hasXname_blahX(Iterator pipe) { 27 | assertFalse(pipe.hasNext()); 28 | } 29 | 30 | public void test_g_V_hasXage_gt_30X(Iterator pipe) { 31 | List list = new ArrayList(); 32 | PipeHelper.fillCollection(pipe, list); 33 | assertEquals(list.size(), 2); 34 | for (Vertex v : list) { 35 | assertTrue((Integer) v.getProperty("age") > 30); 36 | } 37 | } 38 | 39 | public void test_g_v1_out_hasXid_2X(Iterator pipe) { 40 | assertTrue(pipe.hasNext()); 41 | assertEquals(pipe.next().getId().toString(), "2"); 42 | } 43 | 44 | public void test_g_V_hasXblahX(Iterator pipe) { 45 | assertFalse(pipe.hasNext()); 46 | } 47 | 48 | public void test_g_E_hasXlabelXknowsX(Iterator pipe) { 49 | int counter = 0; 50 | while (pipe.hasNext()) { 51 | counter++; 52 | assertEquals(pipe.next().getLabel(), "knows"); 53 | } 54 | assertEquals(counter, 2); 55 | } 56 | 57 | public void test_g_E_hasXlabelXknows_createdX(Iterator pipe) { 58 | int counter = 0; 59 | while (pipe.hasNext()) { 60 | counter++; 61 | String label = pipe.next().getLabel(); 62 | assertTrue(label.equals("knows") || label.equals("created")); 63 | } 64 | assertEquals(counter, 6); 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/filter/IntervalStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.filter; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.Iterator; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class IntervalStepTest extends TestCase { 12 | 13 | public void testCompliance() { 14 | assertTrue(true); 15 | } 16 | 17 | public void test_g_v1_outE_intervalXweight_0_06X_inV(Iterator pipe) { 18 | while (pipe.hasNext()) { 19 | Vertex vertex = pipe.next(); 20 | assertTrue(vertex.getProperty("name").equals("vadas") || vertex.getProperty("name").equals("lop")); 21 | } 22 | assertFalse(pipe.hasNext()); 23 | } 24 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/filter/RangeStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.filter; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.Iterator; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class RangeStepTest extends TestCase { 12 | 13 | public void testCompliance() { 14 | assertTrue(true); 15 | } 16 | 17 | public void test_g_v1_out_rangeX0_1X(Iterator pipe) { 18 | int counter = 0; 19 | while (pipe.hasNext()) { 20 | counter++; 21 | pipe.next(); 22 | } 23 | assertEquals(counter, 2); 24 | } 25 | 26 | public void test_g_v1_outXknowsX_outEXcreatedX_rangeX0_0X_inV(Iterator pipe) { 27 | int counter = 0; 28 | while (pipe.hasNext()) { 29 | counter++; 30 | String name = (String) pipe.next().getProperty("name"); 31 | assertTrue(name.equals("lop") || name.equals("ripple")); 32 | } 33 | assertEquals(counter, 1); 34 | } 35 | 36 | public void test_g_v1_outXknowsX_outXcreatedX_rangeX0_0X(Iterator pipe) { 37 | this.test_g_v1_outXknowsX_outEXcreatedX_rangeX0_0X_inV(pipe); 38 | } 39 | 40 | public void test_g_v1_outXcreatedX_inXcreatedX_rangeX1_2X(Iterator pipe) { 41 | int counter = 0; 42 | while (pipe.hasNext()) { 43 | counter++; 44 | String name = (String) pipe.next().getProperty("name"); 45 | assertTrue(name.equals("marko") || name.equals("josh") || name.equals("peter")); 46 | } 47 | assertEquals(counter, 2); 48 | } 49 | 50 | public void test_g_v1_outXcreatedX_inEXcreatedX_rangeX1_2X_outV(Iterator pipe) { 51 | this.test_g_v1_outXcreatedX_inXcreatedX_rangeX1_2X(pipe); 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/filter/RetainStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.filter; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.Iterator; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class RetainStepTest extends TestCase { 12 | 13 | public void testCompliance() { 14 | assertTrue(true); 15 | } 16 | 17 | public void test_g_v1_out_retainXg_v2X(Iterator pipe) { 18 | assertEquals(pipe.next().getProperty("name"), "vadas"); 19 | assertFalse(pipe.hasNext()); 20 | } 21 | 22 | public void test_g_v1_out_aggregateXxX_out_retainXxX(Iterator pipe) { 23 | assertEquals(pipe.next().getProperty("name"), "lop"); 24 | assertFalse(pipe.hasNext()); 25 | } 26 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/sideeffect/AggregateStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.sideeffect; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.Iterator; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public class AggregateStepTest extends TestCase { 13 | 14 | public void testCompliance() { 15 | assertTrue(true); 16 | } 17 | 18 | public void test_g_v1_aggregateXxX_outXcreatedX_inXcreatedX_exceptXxX(final Iterator pipe) { 19 | int counter = 0; 20 | while (pipe.hasNext()) { 21 | counter++; 22 | Vertex vertex = pipe.next(); 23 | assertTrue(vertex.getProperty("name").equals("peter") || vertex.getProperty("name").equals("josh")); 24 | } 25 | assertEquals(counter, 2); 26 | } 27 | 28 | public void test_g_V_propertyXnameX_aggregate_cap(final Iterator> pipe) { 29 | List names = pipe.next(); 30 | assertFalse(pipe.hasNext()); 31 | assertEquals(names.size(), 6); 32 | assertTrue(names.contains("marko")); 33 | assertTrue(names.contains("josh")); 34 | assertTrue(names.contains("peter")); 35 | assertTrue(names.contains("lop")); 36 | assertTrue(names.contains("vadas")); 37 | assertTrue(names.contains("ripple")); 38 | } 39 | 40 | public void test_g_V_aggregateXnameX_cap(final Iterator> pipe) { 41 | this.test_g_V_propertyXnameX_aggregate_cap(pipe); 42 | } 43 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/sideeffect/GroupByStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.sideeffect; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.Iterator; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | /** 11 | * @author Marko A. Rodriguez (http://markorodriguez.com) 12 | */ 13 | public class GroupByStepTest extends TestCase { 14 | 15 | public void testCompliance() { 16 | assertTrue(true); 17 | } 18 | 19 | public void test_g_V_groupByXlang_nameX(Iterator pipe, Map> m) { 20 | int counter = 0; 21 | while (pipe.hasNext()) { 22 | pipe.next(); 23 | counter++; 24 | } 25 | assertEquals(counter, 6); 26 | assertEquals(m.size(), 2); 27 | assertTrue(m.containsKey("java")); 28 | assertTrue(m.containsKey(null)); 29 | assertEquals(m.get("java").size(), 2); 30 | assertTrue(m.get("java").contains("ripple")); 31 | assertTrue(m.get("java").contains("lop")); 32 | assertEquals(m.get(null).size(), 4); 33 | assertTrue(m.get(null).contains("marko")); 34 | assertTrue(m.get(null).contains("josh")); 35 | assertTrue(m.get(null).contains("peter")); 36 | assertTrue(m.get(null).contains("vadas")); 37 | 38 | } 39 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/sideeffect/GroupCountStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.sideeffect; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.Iterator; 7 | import java.util.Map; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public class GroupCountStepTest extends TestCase { 13 | 14 | public void testCompliance() { 15 | assertTrue(true); 16 | } 17 | 18 | public void test_g_V_outXcreatedX_groupCountXm__nameX(Iterator pipe, Map m) { 19 | int counter = 0; 20 | while (pipe.hasNext()) { 21 | Vertex vertex = pipe.next(); 22 | counter++; 23 | assertTrue(vertex.getProperty("name").equals("lop") || vertex.getProperty("name").equals("ripple")); 24 | } 25 | assertEquals(counter, 4); 26 | assertEquals(m.size(), 2); 27 | assertEquals(m.get("lop"), 3l); 28 | assertEquals(m.get("ripple"), 1l); 29 | } 30 | 31 | public void test_g_V_outXcreatedX_groupCountXm__name__plus_2X(Iterator pipe, Map m) { 32 | int counter = 0; 33 | while (pipe.hasNext()) { 34 | Vertex vertex = pipe.next(); 35 | counter++; 36 | assertTrue(vertex.getProperty("name").equals("lop") || vertex.getProperty("name").equals("ripple")); 37 | } 38 | assertEquals(counter, 4); 39 | assertEquals(m.size(), 2); 40 | assertEquals(m.get("lop"), 6l); 41 | assertEquals(m.get("ripple"), 2l); 42 | } 43 | 44 | public void test_g_V_outXcreatedX_groupCountXnameX_cap(Iterator> pipe) { 45 | Map m = pipe.next(); 46 | assertFalse(pipe.hasNext()); 47 | assertEquals(m.size(), 2); 48 | assertEquals(m.get("lop"), 3l); 49 | assertEquals(m.get("ripple"), 1l); 50 | } 51 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/sideeffect/LinkStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.sideeffect; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import junit.framework.TestCase; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Iterator; 9 | import java.util.List; 10 | 11 | /** 12 | * @author Marko A. Rodriguez (http://markorodriguez.com) 13 | */ 14 | public class LinkStepTest extends TestCase { 15 | 16 | public void testCompliance() { 17 | assertTrue(true); 18 | } 19 | 20 | public void test_g_v1_asXaX_outXcreatedX_inXcreatedX_linkBothXcocreator_aX(final Iterator pipe) { 21 | List cocreators = new ArrayList(); 22 | List ids = new ArrayList(); 23 | while (pipe.hasNext()) { 24 | Vertex vertex = pipe.next(); 25 | cocreators.add(vertex); 26 | ids.add(vertex.getId()); 27 | } 28 | assertEquals(cocreators.size(), 3); 29 | assertTrue(ids.contains("1")); 30 | assertTrue(ids.contains("6")); 31 | assertTrue(ids.contains("4")); 32 | 33 | for (Vertex vertex : cocreators) { 34 | if (vertex.getId().equals("1")) { 35 | assertEquals(vertex.query().direction(Direction.OUT).labels("cocreator").count(), 4); 36 | assertEquals(vertex.query().direction(Direction.IN).labels("cocreator").count(), 4); 37 | } else { 38 | assertEquals(vertex.query().direction(Direction.OUT).labels("cocreator").count(), 1); 39 | assertEquals(vertex.query().direction(Direction.IN).labels("cocreator").count(), 1); 40 | } 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/sideeffect/SideEffectStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.sideeffect; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Iterator; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public class SideEffectStepTest extends TestCase { 13 | 14 | public void testCompliance() { 15 | assertTrue(true); 16 | } 17 | 18 | public void test_g_v1_sideEffectXstore_aX_propertyXnameX(final Iterator pipe) { 19 | assertEquals(pipe.next(), "marko"); 20 | assertFalse(pipe.hasNext()); 21 | } 22 | 23 | public void test_g_v1_out_sideEffectXincr_cX_propertyXnameX(final Iterator pipe) { 24 | List names = new ArrayList(); 25 | while (pipe.hasNext()) { 26 | names.add(pipe.next()); 27 | } 28 | assertEquals(names.size(), 3); 29 | assertTrue(names.contains("josh")); 30 | assertTrue(names.contains("lop")); 31 | assertTrue(names.contains("vadas")); 32 | } 33 | 34 | public void test_g_v1_out_sideEffectXfalseX_propertyXnameX(final Iterator pipe) { 35 | this.test_g_v1_out_sideEffectXincr_cX_propertyXnameX(pipe); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/sideeffect/StoreStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.sideeffect; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Iterator; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public class StoreStepTest extends TestCase { 13 | 14 | public void testCompliance() { 15 | assertTrue(true); 16 | } 17 | 18 | 19 | public void test_g_V_propertyXnameX_store_cap(final Iterator> pipe) { 20 | List names = new ArrayList(); 21 | while (pipe.hasNext()) 22 | names = pipe.next(); 23 | 24 | assertFalse(pipe.hasNext()); 25 | assertEquals(names.size(), 6); 26 | assertTrue(names.contains("marko")); 27 | assertTrue(names.contains("josh")); 28 | assertTrue(names.contains("peter")); 29 | assertTrue(names.contains("lop")); 30 | assertTrue(names.contains("vadas")); 31 | assertTrue(names.contains("ripple")); 32 | } 33 | 34 | public void test_g_V_storeXnameX_cap(final Iterator> pipe) { 35 | this.test_g_V_propertyXnameX_store_cap(pipe); 36 | } 37 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/sideeffect/TreeStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.sideeffect; 2 | 3 | import com.tinkerpop.pipes.util.structures.Tree; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.Iterator; 7 | import java.util.Map; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public class TreeStepTest extends TestCase { 13 | 14 | public void testCompliance() { 15 | assertTrue(true); 16 | } 17 | 18 | public void test_g_v1_out_out_treeXnameX_cap(final Iterator pipe) { 19 | Map map = pipe.next(); 20 | assertFalse(pipe.hasNext()); 21 | assertEquals(map.size(), 1); 22 | assertTrue(map.containsKey("marko")); 23 | assertEquals(((Map) map.get("marko")).size(), 1); 24 | assertTrue(((Map) map.get("marko")).containsKey("josh")); 25 | assertTrue(((Map) ((Map) map.get("marko")).get("josh")).containsKey("lop")); 26 | assertTrue(((Map) ((Map) map.get("marko")).get("josh")).containsKey("ripple")); 27 | } 28 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/transform/GatherStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.transform; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.Iterator; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public class GatherStepTest extends TestCase { 13 | 14 | public void testCompliance() { 15 | assertTrue(true); 16 | } 17 | 18 | public void test_g_v1_out_gather(final Iterator> pipe) { 19 | List list = pipe.next(); 20 | assertFalse(pipe.hasNext()); 21 | for (Vertex vertex : list) { 22 | assertTrue(vertex.getId().equals(2) || vertex.getId().equals(4)); 23 | } 24 | } 25 | 26 | public void test_g_v1_out_gatherXget0X(final Iterator pipe) { 27 | Vertex vertex = pipe.next(); 28 | assertFalse(pipe.hasNext()); 29 | assertTrue(vertex.getId().equals(2) || vertex.getId().equals(4)); 30 | } 31 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/transform/MapStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.transform; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import java.util.Iterator; 6 | import java.util.Map; 7 | 8 | /** 9 | * @author Marko A. Rodriguez (http://markorodriguez.com) 10 | */ 11 | public class MapStepTest extends TestCase { 12 | 13 | public void testCompliance() { 14 | assertTrue(true); 15 | } 16 | 17 | public void test_g_v1_map(final Iterator> pipe) { 18 | Map map = pipe.next(); 19 | assertFalse(pipe.hasNext()); 20 | assertEquals(map.get("name"), "marko"); 21 | assertEquals(map.get("age"), 29); 22 | assertEquals(map.size(), 2); 23 | } 24 | 25 | public void test_g_v1_mapXname_idX(final Iterator> pipe) { 26 | Map map = pipe.next(); 27 | assertFalse(pipe.hasNext()); 28 | assertEquals(map.get("name"), "marko"); 29 | assertNull(map.get("age")); 30 | assertEquals(map.get("id").toString(), "1"); 31 | assertEquals(map.size(), 2); 32 | } 33 | 34 | public void test_g_v1_outXknowsX_map(final Iterator> pipe) { 35 | int counter = 0; 36 | while (pipe.hasNext()) { 37 | Map map = pipe.next(); 38 | if (map.get("name").equals("vadas")) { 39 | assertEquals(map.get("age"), 27); 40 | } else if (map.get("name").equals("josh")) { 41 | assertEquals(map.get("age"), 32); 42 | } else { 43 | assertFalse(true); 44 | } 45 | counter++; 46 | } 47 | assertEquals(counter, 2); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/transform/OrderStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.transform; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import com.tinkerpop.pipes.Pipe; 5 | import junit.framework.TestCase; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Iterator; 9 | import java.util.List; 10 | 11 | /** 12 | * @author Marko A. Rodriguez (http://markorodriguez.com) 13 | */ 14 | public class OrderStepTest extends TestCase { 15 | 16 | public void testCompliance() { 17 | assertTrue(true); 18 | } 19 | 20 | public void test_g_V_name_order(final Iterator pipe) { 21 | List names = new ArrayList(); 22 | while (pipe.hasNext()) { 23 | names.add(pipe.next()); 24 | } 25 | assertEquals(names.size(), 6); 26 | assertEquals(names.get(0), "josh"); 27 | assertEquals(names.get(1), "lop"); 28 | assertEquals(names.get(2), "marko"); 29 | assertEquals(names.get(3), "peter"); 30 | assertEquals(names.get(4), "ripple"); 31 | assertEquals(names.get(5), "vadas"); 32 | } 33 | 34 | public void test_g_V_name_orderXabX(final Iterator pipe) { 35 | List names = new ArrayList(); 36 | while (pipe.hasNext()) { 37 | names.add(pipe.next()); 38 | } 39 | assertEquals(names.size(), 6); 40 | assertEquals(names.get(5), "josh"); 41 | assertEquals(names.get(4), "lop"); 42 | assertEquals(names.get(3), "marko"); 43 | assertEquals(names.get(2), "peter"); 44 | assertEquals(names.get(1), "ripple"); 45 | assertEquals(names.get(0), "vadas"); 46 | 47 | 48 | } 49 | 50 | public void test_g_V_orderXa_nameXb_nameX_name(final Pipe pipe) { 51 | List names = new ArrayList(); 52 | while (pipe.hasNext()) { 53 | names.add(pipe.next()); 54 | } 55 | assertEquals(names.size(), 6); 56 | assertEquals(names.get(5), "josh"); 57 | assertEquals(names.get(4), "lop"); 58 | assertEquals(names.get(3), "marko"); 59 | assertEquals(names.get(2), "peter"); 60 | assertEquals(names.get(1), "ripple"); 61 | assertEquals(names.get(0), "vadas"); 62 | 63 | 64 | } 65 | 66 | public void test_g_V_name_orderXdecrX(final Pipe pipe) { 67 | this.test_g_V_orderXa_nameXb_nameX_name(pipe); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/transform/PathStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.transform; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import junit.framework.TestCase; 5 | 6 | import java.util.HashSet; 7 | import java.util.Iterator; 8 | import java.util.List; 9 | import java.util.Set; 10 | 11 | /** 12 | * @author Marko A. Rodriguez (http://markorodriguez.com) 13 | */ 14 | public class PathStepTest extends TestCase { 15 | 16 | public void testCompliance() { 17 | assertTrue(true); 18 | } 19 | 20 | public void test_g_v1_propertyXnameX_path(final Iterator pipe) { 21 | List list = pipe.next(); 22 | assertFalse(pipe.hasNext()); 23 | assertEquals(list.size(), 2); 24 | assertEquals(((Vertex) list.get(0)).getProperty("name"), "marko"); 25 | assertEquals(list.get(1), "marko"); 26 | } 27 | 28 | public void test_g_v1_out_pathXage__nameX(final Iterator pipe) { 29 | int counter = 0; 30 | Set names = new HashSet(); 31 | while (pipe.hasNext()) { 32 | counter++; 33 | List list = pipe.next(); 34 | assertEquals(list.get(0), 29); 35 | assertTrue(list.get(1).equals("josh") || list.get(1).equals("vadas") || list.get(1).equals("lop")); 36 | names.add((String) list.get(1)); 37 | } 38 | assertEquals(counter, 3); 39 | assertEquals(names.size(), 3); 40 | } 41 | 42 | public void test_g_V_out_loopX1__loops_lt_3X_pathXit__name__langX(final Iterator pipe) { 43 | int counter = 0; 44 | while (pipe.hasNext()) { 45 | counter++; 46 | List list = pipe.next(); 47 | assertEquals(list.size(), 3); 48 | assertEquals(((Vertex) list.get(0)).getProperty("name"), "marko"); 49 | assertEquals(list.get(1), "josh"); 50 | assertEquals(list.get(2), "java"); 51 | } 52 | assertEquals(counter, 2); 53 | } 54 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/transform/SelectStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.transform; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import com.tinkerpop.pipes.util.structures.Row; 5 | import junit.framework.TestCase; 6 | 7 | import java.util.Iterator; 8 | import java.util.List; 9 | 10 | /** 11 | * @author Marko A. Rodriguez (http://markorodriguez.com) 12 | */ 13 | public class SelectStepTest extends TestCase { 14 | 15 | public void testCompliance() { 16 | assertTrue(true); 17 | } 18 | 19 | public void test_g_v1_asXaX_outXknowsX_asXbX_select(final Iterator pipe) { 20 | int counter = 0; 21 | while (pipe.hasNext()) { 22 | counter++; 23 | List list = pipe.next(); 24 | assertEquals(list.size(), 2); 25 | assertEquals(((Vertex) list.get(0)).getId().toString(), "1"); 26 | assertTrue(((Vertex) list.get(1)).getId().toString().equals("2") || ((Vertex) list.get(1)).getId().toString().equals("4")); 27 | } 28 | assertEquals(counter, 2); 29 | } 30 | 31 | public void test_g_v1_asXaX_outXknowsX_asXbX_selectXnameX(final Iterator pipe) { 32 | int counter = 0; 33 | while (pipe.hasNext()) { 34 | counter++; 35 | Row list = pipe.next(); 36 | assertEquals(list.size(), 2); 37 | assertEquals(list.get(0).toString(), "marko"); 38 | assertTrue(list.get(1).toString().equals("josh") || list.get(1).toString().equals("vadas")); 39 | assertTrue(list.getColumn("b").toString().equals("josh") || list.getColumn("b").toString().equals("vadas")); 40 | } 41 | assertEquals(counter, 2); 42 | } 43 | 44 | public void test_g_v1_asXaX_outXknowsX_asXbX_selectXaX(final Iterator pipe) { 45 | int counter = 0; 46 | while (pipe.hasNext()) { 47 | counter++; 48 | Row list = pipe.next(); 49 | assertEquals(list.size(), 1); 50 | assertEquals(((Vertex) list.get(0)).getId().toString(), "1"); 51 | assertEquals(((Vertex) list.getColumn("a")).getId().toString(), "1"); 52 | } 53 | assertEquals(counter, 2); 54 | } 55 | 56 | public void test_g_v1_asXaX_outXknowsX_asXbX_selectXa_nameX(final Iterator pipe) { 57 | int counter = 0; 58 | while (pipe.hasNext()) { 59 | counter++; 60 | Row list = pipe.next(); 61 | assertEquals(list.size(), 1); 62 | assertEquals(list.get(0).toString(), "marko"); 63 | assertEquals(list.getColumn("a"), "marko"); 64 | } 65 | assertEquals(counter, 2); 66 | } 67 | } -------------------------------------------------------------------------------- /gremlin-test/src/main/java/com/tinkerpop/gremlin/test/transform/TransformStepTest.java: -------------------------------------------------------------------------------- 1 | package com.tinkerpop.gremlin.test.transform; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Iterator; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Marko A. Rodriguez (http://markorodriguez.com) 11 | */ 12 | public class TransformStepTest extends TestCase { 13 | 14 | public void testCompliance() { 15 | assertTrue(true); 16 | } 17 | 18 | public void test_g_v1_transformXnameX(final Iterator pipe) { 19 | assertEquals(pipe.next(), "marko"); 20 | assertFalse(pipe.hasNext()); 21 | } 22 | 23 | public void test_g_v1_outE_label_transformXlengthX(final Iterator pipe) { 24 | List lengths = new ArrayList(); 25 | while (pipe.hasNext()) { 26 | lengths.add(pipe.next()); 27 | } 28 | assertTrue(lengths.contains("created".length())); 29 | assertTrue(lengths.contains("knows".length())); 30 | assertEquals(lengths.size(), 3); 31 | } 32 | 33 | public void test_g_v1_out_transformXnameX_transformXlengthX(final Iterator pipe) { 34 | List lengths = new ArrayList(); 35 | while (pipe.hasNext()) { 36 | lengths.add(pipe.next()); 37 | } 38 | assertTrue(lengths.contains("josh".length())); 39 | assertTrue(lengths.contains("vadas".length())); 40 | assertTrue(lengths.contains("lop".length())); 41 | assertEquals(lengths.size(), 3); 42 | } 43 | 44 | public void test_g_V_asXaX_out_transformXa_nameX(final Iterator pipe) { 45 | int marko = 0; 46 | int peter = 0; 47 | int josh = 0; 48 | int other = 0; 49 | while (pipe.hasNext()) { 50 | String name = pipe.next(); 51 | if (name.equals("marko")) marko++; 52 | else if (name.equals("peter")) peter++; 53 | else if (name.equals("josh")) josh++; 54 | else other++; 55 | } 56 | assertEquals(marko, 3); 57 | assertEquals(josh, 2); 58 | assertEquals(peter, 1); 59 | assertEquals(other, 0); 60 | } 61 | } 62 | --------------------------------------------------------------------------------