use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project frames by tinkerpop.
the class FramedGraphTest method testCreateFrame.
public void testCreateFrame() {
Graph graph = new TinkerGraph();
FramedGraph<Graph> framedGraph = new FramedGraphFactory().create(graph);
Person person = framedGraph.addVertex(null, Person.class);
assertEquals(person.asVertex(), graph.getVertices().iterator().next());
int counter = 0;
for (Vertex v : graph.getVertices()) {
counter++;
}
assertEquals(counter, 1);
counter = 0;
for (Edge e : graph.getEdges()) {
counter++;
}
assertEquals(counter, 0);
Person person2 = framedGraph.addVertex("aPerson", Person.class);
assertEquals(person2.asVertex().getId(), "aPerson");
counter = 0;
for (Vertex v : graph.getVertices()) {
counter++;
}
assertEquals(counter, 2);
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project gremlin by tinkerpop.
the class GremlinGroovyScriptEngineTest method testGremlinScriptEngineWithScriptBaseClass.
public void testGremlinScriptEngineWithScriptBaseClass() throws Exception {
ScriptEngine engine = new GremlinGroovyScriptEngine();
List list = new ArrayList();
engine.put("g", TinkerGraphFactory.createTinkerGraph());
engine.put("list", list);
assertEquals(list.size(), 0);
engine.eval("g.V.fill(list)");
assertEquals(6, list.size());
list.clear();
TinkerGraph tinkerGraph = TinkerGraphFactory.createTinkerGraph();
Vertex marko = tinkerGraph.getVertex(1L);
Assert.assertEquals("marko", marko.getProperty("name"));
marko.setProperty("deleted", new Date());
engine = new GremlinGroovyScriptEngine("com.tinkerpop.gremlin.groovy.basescript.GremlinGroovyScriptBaseClassForTest");
engine.put("g", tinkerGraph);
engine.put("list", list);
assertEquals(list.size(), 0);
String groovy = "g.V.fill(list)";
groovy = "useInterceptor( GremlinGroovyPipeline, com.tinkerpop.gremlin.groovy.basescript.GremlinGroovyPipelineInterceptor) {" + groovy + "}";
engine.eval(groovy);
assertEquals(5, list.size());
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GMLReaderTestSuite method testReadingTinkerGraph.
public void testReadingTinkerGraph() throws Exception {
Graph graph = graphTest.generateGraph();
// like tinkergraph.
if (!graph.getFeatures().ignoresSuppliedIds) {
this.stopWatch();
GMLReader gmlReader = new GMLReader(graph);
gmlReader.inputGraph(GMLReader.class.getResourceAsStream("graph-example-1.gml"));
printPerformance(graph.toString(), null, "graph-example-1 loaded", this.stopWatch());
assertEquals(count(graph.getVertex("1").getEdges(Direction.OUT)), 3);
assertEquals(count(graph.getVertex("1").getEdges(Direction.IN)), 0);
Vertex marko = graph.getVertex("1");
assertEquals(marko.getProperty("name"), "marko");
assertEquals(marko.getProperty("age"), 29);
int counter = 0;
for (Edge e : graph.getVertex("1").getEdges(Direction.OUT)) {
if (e.getVertex(Direction.IN).getId().equals("2")) {
// assertEquals(e.getProperty("weight"), 0.5);
assertEquals(e.getLabel(), "knows");
counter++;
} else if (e.getVertex(Direction.IN).getId().equals("3")) {
assertEquals(0, Math.round(((Number) e.getProperty("weight")).floatValue()));
assertEquals(e.getLabel(), "created");
counter++;
} else if (e.getVertex(Direction.IN).getId().equals("4")) {
assertEquals(1, Math.round(((Number) e.getProperty("weight")).floatValue()));
assertEquals(e.getLabel(), "knows");
counter++;
}
}
assertEquals(count(graph.getVertex("4").getEdges(Direction.OUT)), 2);
assertEquals(count(graph.getVertex("4").getEdges(Direction.IN)), 1);
Vertex josh = graph.getVertex("4");
assertEquals(josh.getProperty("name"), "josh");
assertEquals(josh.getProperty("age"), 32);
for (Edge e : graph.getVertex("4").getEdges(Direction.OUT)) {
if (e.getVertex(Direction.IN).getId().equals("3")) {
assertEquals(0, Math.round(((Number) e.getProperty("weight")).floatValue()));
assertEquals(e.getLabel(), "created");
counter++;
} else if (e.getVertex(Direction.IN).getId().equals("5")) {
assertEquals(1, Math.round(((Number) e.getProperty("weight")).floatValue()));
assertEquals(e.getLabel(), "created");
counter++;
}
}
assertEquals(counter, 5);
}
graph.shutdown();
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GraphSONUtilityTest method vertexFromJsonValid.
@Test
public void vertexFromJsonValid() throws IOException, JSONException {
Graph g = new TinkerGraph();
ElementFactory factory = new GraphElementFactory(g);
Vertex v = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.NORMAL, null);
Assert.assertSame(v, g.getVertex(1));
// tinkergraph converts id to string
Assert.assertEquals("1", v.getId());
Assert.assertEquals("marko", v.getProperty("name"));
Assert.assertEquals(29, v.getProperty("age"));
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class BatchGraphTest method loadingTest.
public void loadingTest(int total, int bufferSize, VertexIDType type, LoadingFactory ids) {
final VertexEdgeCounter counter = new VertexEdgeCounter();
MockTransactionalGraph tgraph = null;
if (ignoreIDs) {
tgraph = new MockTransactionalGraph(new IgnoreIdTinkerGraph());
} else {
tgraph = new MockTransactionalGraph(new TinkerGraph());
}
BLGraph graph = new BLGraph(tgraph, counter, ids);
BatchGraph<BLGraph> loader = new BatchGraph<BLGraph>(graph, type, bufferSize);
if (assignKeys) {
loader.setVertexIdKey(vertexIDKey);
loader.setEdgeIdKey(edgeIDKey);
}
// Create a chain
int chainLength = total;
Vertex previous = null;
for (int i = 0; i <= chainLength; i++) {
Vertex next = loader.addVertex(ids.getVertexID(i));
next.setProperty(UID, i);
counter.numVertices++;
counter.totalVertices++;
if (previous != null) {
Edge e = loader.addEdge(ids.getEdgeID(i), loader.getVertex(previous.getId()), loader.getVertex(next.getId()), "next");
e.setProperty(UID, i);
counter.numEdges++;
}
previous = next;
}
loader.stopTransaction(TransactionalGraph.Conclusion.SUCCESS);
assertTrue(tgraph.allSuccessful());
loader.shutdown();
}
Aggregations