Package com.tinkerpop.blueprints.impls.tg

Examples of com.tinkerpop.blueprints.impls.tg.TinkerGraph


public class GraphSONReaderTest {

    @Test
    public void inputGraphModeExtended() throws IOException {
        TinkerGraph graph = new TinkerGraph();

        String json = "{ \"mode\":\"EXTENDED\", \"vertices\": [ {\"_id\":1, \"_type\":\"vertex\", \"test\": { \"type\":\"string\", \"value\":\"please work\"}, \"testlist\":{\"type\":\"list\", \"value\":[{\"type\":\"int\", \"value\":1}, {\"type\":\"int\",\"value\":2}, {\"type\":\"int\",\"value\":3}]}, \"testmap\":{\"type\":\"map\", \"value\":{\"big\":{\"type\":\"long\", \"value\":10000000000}, \"small\":{\"type\":\"double\", \"value\":0.4954959595959}}}}, {\"_id\":2, \"_type\":\"vertex\", \"testagain\":{\"type\":\"string\", \"value\":\"please work again\"}}], \"edges\":[{\"_id\":100, \"_type\":\"edge\", \"_outV\":1, \"_inV\":2, \"_label\":\"works\", \"teste\": {\"type\":\"string\", \"value\":\"please worke\"}}]}";

        byte[] bytes = json.getBytes();
        InputStream inputStream = new ByteArrayInputStream(bytes);

        GraphSONReader.inputGraph(graph, inputStream);

        Assert.assertEquals(2, getIterableCount(graph.getVertices()));
        Assert.assertEquals(1, getIterableCount(graph.getEdges()));

        Vertex v1 = graph.getVertex(1);
        Assert.assertNotNull(v1);
        Assert.assertEquals("please work", v1.getProperty("test"));

        Map map = (Map) v1.getProperty("testmap");
        Assert.assertNotNull(map);
        Assert.assertEquals(10000000000l, Long.parseLong(map.get("big").toString()));
        Assert.assertEquals(0.4954959595959, Double.parseDouble(map.get("small").toString()), 0);
        //Assert.assertNull(map.get("nullKey"));

        List list = (List) v1.getProperty("testlist");
        Assert.assertEquals(3, list.size());

        boolean foundNull = false;
        for (int ix = 0; ix < list.size(); ix++) {
            if (list.get(ix) == null) {
                foundNull = true;
                break;
            }
        }

        Assert.assertTrue(foundNull);

        Vertex v2 = graph.getVertex(2);
        Assert.assertNotNull(v2);
        Assert.assertEquals("please work again", v2.getProperty("testagain"));

        Edge e = graph.getEdge(100);
        Assert.assertNotNull(e);
        Assert.assertEquals("works", e.getLabel());
        Assert.assertEquals(v1, e.getVertex(Direction.OUT));
        Assert.assertEquals(v2, e.getVertex(Direction.IN));
        Assert.assertEquals("please worke", e.getProperty("teste"));
View Full Code Here


    }

    @Test
    public void inputGraphModeNormal() throws IOException {
        TinkerGraph graph = new TinkerGraph();

        String json = "{ \"mode\":\"NORMAL\",\"vertices\": [ {\"_id\":1, \"_type\":\"vertex\", \"test\": \"please work\", \"testlist\":[1, 2, 3, null], \"testmap\":{\"big\":10000000000, \"small\":0.4954959595959}}, {\"_id\":2, \"_type\":\"vertex\", \"testagain\":\"please work again\"}], \"edges\":[{\"_id\":100, \"_type\":\"edge\", \"_outV\":1, \"_inV\":2, \"_label\":\"works\", \"teste\": \"please worke\"}]}";

        byte[] bytes = json.getBytes();
        InputStream inputStream = new ByteArrayInputStream(bytes);

        GraphSONReader.inputGraph(graph, inputStream);

        Assert.assertEquals(2, getIterableCount(graph.getVertices()));
        Assert.assertEquals(1, getIterableCount(graph.getEdges()));

        Vertex v1 = graph.getVertex(1);
        Assert.assertNotNull(v1);
        Assert.assertEquals("please work", v1.getProperty("test"));

        Map map = (Map) v1.getProperty("testmap");
        Assert.assertNotNull(map);
        Assert.assertEquals(10000000000l, Long.parseLong(map.get("big").toString()));
        Assert.assertEquals(0.4954959595959, Double.parseDouble(map.get("small").toString()), 0);
        Assert.assertNull(map.get("nullKey"));

        List list = (List) v1.getProperty("testlist");
        Assert.assertEquals(4, list.size());

        boolean foundNull = false;
        for (int ix = 0; ix < list.size(); ix++) {
            if (list.get(ix) == null) {
                foundNull = true;
                break;
            }
        }

        Assert.assertTrue(foundNull);

        Vertex v2 = graph.getVertex(2);
        Assert.assertNotNull(v2);
        Assert.assertEquals("please work again", v2.getProperty("testagain"));

        Edge e = graph.getEdge(100);
        Assert.assertNotNull(e);
        Assert.assertEquals("works", e.getLabel());
        Assert.assertEquals(v1, e.getVertex(Direction.OUT));
        Assert.assertEquals(v2, e.getVertex(Direction.IN));
        Assert.assertEquals("please worke", e.getProperty("teste"));
View Full Code Here

            printPerformance(graph.toString(), null, "graph-example-3 loaded", this.stopWatch());

            this.stopWatch();
            // FIXME Should not explicitly define the Graph type (TinkerGraph)
            // here. Need to accept 2 graphs as input params?
            Graph toGraph = new TinkerGraph();
            GraphMigrator.migrateGraph(graph, toGraph);
            printPerformance(toGraph.toString(), null, "graph-example-3 migrated", this.stopWatch());

            // Specific Graph Characteristics

            assertEquals(count(toGraph.getVertex(1).getEdges(Direction.OUT)), 3);
            assertEquals(count(toGraph.getVertex(1).getEdges(Direction.IN)), 0);
            Vertex marko = toGraph.getVertex(1);
            assertEquals(marko.getProperty("name"), "marko");
            assertEquals(marko.getProperty("age"), 29);
            assertEquals(marko.getProperty("id2"), 2);
            int counter = 0;
            for (Edge e : toGraph.getVertex(1).getEdges(Direction.OUT)) {
                if (e.getVertex(Direction.IN).getId().equals("2")) {
                    // assertEquals(e.getProperty("weight"), 0.5);
                    assertEquals(e.getProperty("id2"), 8);
                    assertEquals(e.getProperty("label2"), "has high fived");
                    assertEquals(e.getLabel(), "knows");
                    assertEquals(e.getId(), "7");
                    counter++;
                } else if (e.getVertex(Direction.IN).getId().equals("3")) {
                    assertEquals(Math.round((Float) e.getProperty("weight")), 0);
                    assertEquals(e.getProperty("id2"), 10);
                    assertEquals(e.getProperty("label2"), "has high fived");
                    assertEquals(e.getLabel(), "created");
                    assertEquals(e.getId(), "9");
                    counter++;
                } else if (e.getVertex(Direction.IN).getId().equals("4")) {
                    assertEquals(Math.round((Float) e.getProperty("weight")), 1);
                    assertEquals(e.getProperty("id2"), 9);
                    assertEquals(e.getProperty("label2"), "has high fived");
                    assertEquals(e.getLabel(), "knows");
                    assertEquals(e.getId(), "8");
                    counter++;
                }
            }

            assertEquals(count(toGraph.getVertex(2).getEdges(Direction.OUT)), 0);
            assertEquals(count(toGraph.getVertex(2).getEdges(Direction.IN)), 1);
            Vertex vadas = toGraph.getVertex(2);
            assertEquals(vadas.getProperty("name"), "vadas");
            assertEquals(vadas.getProperty("age"), 27);
            assertEquals(vadas.getProperty("id2"), 3);

            assertEquals(count(toGraph.getVertex(3).getEdges(Direction.OUT)), 0);
            assertEquals(count(toGraph.getVertex(3).getEdges(Direction.IN)), 3);
            Vertex lop = toGraph.getVertex(3);
            assertEquals(lop.getProperty("name"), "lop");
            assertEquals(lop.getProperty("lang"), "java");
            assertEquals(lop.getProperty("id2"), 4);

            assertEquals(count(toGraph.getVertex(4).getEdges(Direction.OUT)), 2);
            assertEquals(count(toGraph.getVertex(4).getEdges(Direction.IN)), 1);
            Vertex josh = toGraph.getVertex(4);
            assertEquals(josh.getProperty("name"), "josh");
            assertEquals(josh.getProperty("age"), 32);
            for (Edge e : toGraph.getVertex(4).getEdges(Direction.OUT)) {
                if (e.getVertex(Direction.IN).getId().equals("3")) {
                    assertEquals(Math.round((Float) e.getProperty("weight")), 0);
                    assertEquals(e.getProperty("id2"), 13);
                    assertEquals(e.getProperty("label2"), null);
                    assertEquals(e.getLabel(), "created");
                    assertEquals(e.getId(), "11");
                    counter++;
                } else if (e.getVertex(Direction.IN).getId().equals("5")) {
                    assertEquals(Math.round((Float) e.getProperty("weight")), 1);
                    assertEquals(e.getProperty("id2"), 11);
                    assertEquals(e.getProperty("label2"), "has high fived");
                    assertEquals(e.getLabel(), "created");
                    assertEquals(e.getId(), "10");
                    counter++;
                }
            }

            assertEquals(count(toGraph.getVertex(5).getEdges(Direction.OUT)), 0);
            assertEquals(count(toGraph.getVertex(5).getEdges(Direction.IN)), 1);
            Vertex ripple = toGraph.getVertex(5);
            assertEquals(ripple.getProperty("name"), "ripple");
            assertEquals(ripple.getProperty("lang"), "java");
            assertEquals(ripple.getProperty("id2"), 7);

            assertEquals(count(toGraph.getVertex(6).getEdges(Direction.OUT)), 1);
            assertEquals(count(toGraph.getVertex(6).getEdges(Direction.IN)), 0);
            Vertex peter = toGraph.getVertex(6);
            assertEquals(peter.getProperty("name"), "peter");
            assertEquals(peter.getProperty("age"), 35);

            for (Edge e : toGraph.getVertex(6).getEdges(Direction.OUT)) {
                if (e.getVertex(Direction.IN).getId().equals("3")) {
                    assertEquals(Math.round((Float) e.getProperty("weight")), 0);
                    assertEquals(e.getProperty("id2"), null);
                    assertEquals(e.getProperty("label2"), null);
                    assertEquals(e.getLabel(), "created");
                    assertEquals(e.getId(), "12");
                    counter++;
                }
            }

            assertEquals(counter, 6);

            // General Graph Characteristics

            Set<String> vertexIds = new HashSet<String>();
            Set<String> vertexKeys = new HashSet<String>();
            int vertexCount = 0;
            for (Vertex v : toGraph.getVertices()) {
                vertexCount++;
                vertexIds.add(v.getId().toString());
                for (String key : v.getPropertyKeys()) {
                    vertexKeys.add(key);
                }
            }

            Set<String> edgeIds = new HashSet<String>();
            Set<String> edgeKeys = new HashSet<String>();
            int edgeCount = 0;
            for (Edge e : toGraph.getEdges()) {
                edgeCount++;
                edgeIds.add(e.getId().toString());
                for (String key : e.getPropertyKeys()) {
                    edgeKeys.add(key);
                }
View Full Code Here

        System.out.println(b.getID());
        System.out.println(b.stringValue());
        System.exit(1);
        */

        return new TinkerGraph();
    }
View Full Code Here

        return new TinkerGraph();
    }

    @Test
    public void testTmp() throws Exception {
        KeyIndexableGraph g = new TinkerGraph();
        GraphSail sail = new GraphSail(g, "sp,p,c,pc");
    }
View Full Code Here

        }
    }

    @Test
    public void testCodePlay() throws Exception {
        Sail sail = new GraphSail(new TinkerGraph());
        sail.initialize();
        try {
            SailConnection sc = sail.getConnection();
            try {
                sc.begin();
View Full Code Here

* @author Joshua Shinavier (http://fortytwo.net)
*/
public class SailLoaderTest {
    @Test
    public void testAll() throws Exception {
        KeyIndexableGraph g = new TinkerGraph();
        Sail sail = new GraphSail(g);
        sail.initialize();
        try {
            SailLoader loader = new SailLoader(sail);

View Full Code Here

            printPerformance(graph.toString(), null, "graph-example-3 loaded", this.stopWatch());

            this.stopWatch();
            // FIXME Should not explicitly define the Graph type (TinkerGraph)
            // here. Need to accept 2 graphs as input params?
            Graph toGraph = new TinkerGraph();
            GraphMigrator.migrateGraph(graph, toGraph);
            printPerformance(toGraph.toString(), null, "graph-example-3 migrated", this.stopWatch());

            // Specific Graph Characteristics

            assertEquals(count(toGraph.getVertex("1").getEdges(Direction.OUT)), 3);
            assertEquals(count(toGraph.getVertex("1").getEdges(Direction.IN)), 0);
            Vertex marko = toGraph.getVertex("1");
            assertEquals(marko.getProperty("name"), "marko");
            assertEquals(marko.getProperty("age"), 29);
            assertEquals(marko.getProperty("_id"), 2);
            int counter = 0;
            for (Edge e : toGraph.getVertex("1").getEdges(Direction.OUT)) {
                if (e.getVertex(Direction.IN).getId().equals("2")) {
                    // assertEquals(e.getProperty("weight"), 0.5);
                    assertEquals(e.getProperty("_id"), 8);
                    assertEquals(e.getProperty("_label"), "has high fived");
                    assertEquals(e.getLabel(), "knows");
                    assertEquals(e.getId(), "7");
                    counter++;
                } else if (e.getVertex(Direction.IN).getId().equals("3")) {
                    assertEquals(Math.round((Float) e.getProperty("weight")), 0);
                    assertEquals(e.getProperty("_id"), 10);
                    assertEquals(e.getProperty("_label"), "has high fived");
                    assertEquals(e.getLabel(), "created");
                    assertEquals(e.getId(), "9");
                    counter++;
                } else if (e.getVertex(Direction.IN).getId().equals("4")) {
                    assertEquals(Math.round((Float) e.getProperty("weight")), 1);
                    assertEquals(e.getProperty("_id"), 9);
                    assertEquals(e.getProperty("_label"), "has high fived");
                    assertEquals(e.getLabel(), "knows");
                    assertEquals(e.getId(), "8");
                    counter++;
                }
            }

            assertEquals(count(toGraph.getVertex("2").getEdges(Direction.OUT)), 0);
            assertEquals(count(toGraph.getVertex("2").getEdges(Direction.IN)), 1);
            Vertex vadas = toGraph.getVertex("2");
            assertEquals(vadas.getProperty("name"), "vadas");
            assertEquals(vadas.getProperty("age"), 27);
            assertEquals(vadas.getProperty("_id"), 3);

            assertEquals(count(toGraph.getVertex("3").getEdges(Direction.OUT)), 0);
            assertEquals(count(toGraph.getVertex("3").getEdges(Direction.IN)), 3);
            Vertex lop = toGraph.getVertex("3");
            assertEquals(lop.getProperty("name"), "lop");
            assertEquals(lop.getProperty("lang"), "java");
            assertEquals(lop.getProperty("_id"), 4);

            assertEquals(count(toGraph.getVertex("4").getEdges(Direction.OUT)), 2);
            assertEquals(count(toGraph.getVertex("4").getEdges(Direction.IN)), 1);
            Vertex josh = toGraph.getVertex("4");
            assertEquals(josh.getProperty("name"), "josh");
            assertEquals(josh.getProperty("age"), 32);
            for (Edge e : toGraph.getVertex("4").getEdges(Direction.OUT)) {
                if (e.getVertex(Direction.IN).getId().equals("3")) {
                    assertEquals(Math.round((Float) e.getProperty("weight")), 0);
                    assertEquals(e.getProperty("_id"), 13);
                    assertEquals(e.getProperty("_label"), null);
                    assertEquals(e.getLabel(), "created");
                    assertEquals(e.getId(), "11");
                    counter++;
                } else if (e.getVertex(Direction.IN).getId().equals("5")) {
                    assertEquals(Math.round((Float) e.getProperty("weight")), 1);
                    assertEquals(e.getProperty("_id"), 11);
                    assertEquals(e.getProperty("_label"), "has high fived");
                    assertEquals(e.getLabel(), "created");
                    assertEquals(e.getId(), "10");
                    counter++;
                }
            }

            assertEquals(count(toGraph.getVertex("5").getEdges(Direction.OUT)), 0);
            assertEquals(count(toGraph.getVertex("5").getEdges(Direction.IN)), 1);
            Vertex ripple = toGraph.getVertex("5");
            assertEquals(ripple.getProperty("name"), "ripple");
            assertEquals(ripple.getProperty("lang"), "java");
            assertEquals(ripple.getProperty("_id"), 7);

            assertEquals(count(toGraph.getVertex("6").getEdges(Direction.OUT)), 1);
            assertEquals(count(toGraph.getVertex("6").getEdges(Direction.IN)), 0);
            Vertex peter = toGraph.getVertex("6");
            assertEquals(peter.getProperty("name"), "peter");
            assertEquals(peter.getProperty("age"), 35);

            for (Edge e : toGraph.getVertex("6").getEdges(Direction.OUT)) {
                if (e.getVertex(Direction.IN).getId().equals("3")) {
                    assertEquals(Math.round((Float) e.getProperty("weight")), 0);
                    assertEquals(e.getProperty("_id"), null);
                    assertEquals(e.getProperty("_label"), null);
                    assertEquals(e.getLabel(), "created");
                    assertEquals(e.getId(), "12");
                    counter++;
                }
            }

            assertEquals(counter, 6);

            // General Graph Characteristics

            Set<String> vertexIds = new HashSet<String>();
            Set<String> vertexKeys = new HashSet<String>();
            int vertexCount = 0;
            for (Vertex v : toGraph.getVertices()) {
                vertexCount++;
                vertexIds.add(v.getId().toString());
                for (String key : v.getPropertyKeys())
                    vertexKeys.add(key);
            }

            Set<String> edgeIds = new HashSet<String>();
            Set<String> edgeKeys = new HashSet<String>();
            int edgeCount = 0;
            for (Edge e : toGraph.getEdges()) {
                edgeCount++;
                edgeIds.add(e.getId().toString());
                for (String key : e.getPropertyKeys())
                    edgeKeys.add(key);
            }
View Full Code Here

        engine.eval("SUCCESS.toString(); FAILURE.toString()");
        engine.eval("TransactionalGraph.Conclusion.SUCCESS.toString(); TransactionalGraph.Conclusion.FAILURE.toString()");
    }

    public void testBindings() throws Exception {
        final TinkerGraph g = TinkerGraphFactory.createTinkerGraph();
        final ScriptEngine engine = new GremlinGroovyScriptEngine();
        assertTrue(engine.eval("g = TinkerGraphFactory.createTinkerGraph()") instanceof TinkerGraph);
        assertTrue(engine.get("g") instanceof TinkerGraph);
        assertEquals(engine.eval("g.v(1)"), g.getVertex(1));

        final Bindings bindings = engine.createBindings();
        bindings.put("g", g);
        bindings.put("s", "marko");
        bindings.put("f", 0.5f);
        bindings.put("i", 1);
        bindings.put("b", true);
        bindings.put("l", 100l);
        bindings.put("d", 1.55555d);

        assertEquals(g.getEdge(7), engine.eval("g.E.has('weight',f).next()", bindings));
        assertEquals(g.getVertex(1), engine.eval("g.V.has('name',s).next()", bindings));
        assertEquals(g.getVertex(1), engine.eval("g.V.sideEffect{it.bbb=it.name=='marko'}.iterate();g.V.has('bbb',b).next()", bindings));
        assertEquals(g.getVertex(1), engine.eval("g.V.sideEffect{it.iii=it.name=='marko'?1:0}.iterate();g.V.has('iii',i).next()", bindings));
        assertEquals(g.getVertex(1), engine.eval("g.V.sideEffect{it.lll=it.name=='marko'?100l:0l}.iterate();g.V.has('lll',l).next()", bindings));
        assertEquals(g.getVertex(1), engine.eval("g.V.sideEffect{it.ddd=it.name=='marko'?1.55555d:0}.iterate();g.V.has('ddd',d).next()", bindings));
    }
View Full Code Here

        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);
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.impls.tg.TinkerGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.