Search in sources :

Example 21 with TinkerGraph

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);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Person(com.tinkerpop.frames.domain.classes.Person) Edge(com.tinkerpop.blueprints.Edge)

Example 22 with TinkerGraph

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());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) ScriptEngine(javax.script.ScriptEngine)

Example 23 with TinkerGraph

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();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) Edge(com.tinkerpop.blueprints.Edge)

Example 24 with TinkerGraph

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"));
}
Also used : JSONTokener(org.codehaus.jettison.json.JSONTokener) Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) JSONObject(org.codehaus.jettison.json.JSONObject) Test(org.junit.Test)

Example 25 with TinkerGraph

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();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) MockTransactionalGraph(com.tinkerpop.blueprints.impls.tg.MockTransactionalGraph) Edge(com.tinkerpop.blueprints.Edge)

Aggregations

TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)105 Vertex (com.tinkerpop.blueprints.Vertex)66 Graph (com.tinkerpop.blueprints.Graph)58 Test (org.junit.Test)42 Edge (com.tinkerpop.blueprints.Edge)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 JSONObject (org.codehaus.jettison.json.JSONObject)10 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)10 InputStream (java.io.InputStream)9 HashSet (java.util.HashSet)9 JSONTokener (org.codehaus.jettison.json.JSONTokener)8 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)7 Map (java.util.Map)6 MetaverseBuilder (org.pentaho.metaverse.impl.MetaverseBuilder)6 TypedGraphModuleBuilder (com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder)5 HashMap (java.util.HashMap)5 Before (org.junit.Before)5 IndexableGraph (com.tinkerpop.blueprints.IndexableGraph)4 IgnoreIdTinkerGraph (com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph)4