Package com.tinkerpop.blueprints.impls.tg

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


        Assert.assertEquals(v2, e.getVertex(Direction.IN));
    }

    @Test
    public void edgeFromJsonNormalLabelOrIdOnEdge() throws IOException, JSONException {
        Graph g = new TinkerGraph();
        ElementFactory factory = new GraphElementFactory(g);

        Vertex v1 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.NORMAL, null);
        Vertex v2 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)), factory, GraphSONMode.NORMAL, null);
        Edge e = GraphSONUtility.edgeFromJson(new JSONObject(new JSONTokener(edgeJsonLight)), v1, v2, factory, GraphSONMode.NORMAL, null);

        Assert.assertSame(v1, g.getVertex(1));
        Assert.assertSame(v2, g.getVertex(2));
        Assert.assertSame(e, g.getEdge(0));
    }
View Full Code Here


        Assert.assertSame(e, g.getEdge(0));
    }

    @Test
    public void edgeFromJsonInputStreamCompactLabelOrIdOnEdge() throws IOException, JSONException {
        Graph g = new TinkerGraph();
        ElementFactory factory = new GraphElementFactory(g);

        Vertex v1 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.COMPACT, null);
        Vertex v2 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)), factory, GraphSONMode.COMPACT, null);
        Edge e = GraphSONUtility.edgeFromJson(inputStreamEdgeJsonLight, v1, v2, factory, GraphSONMode.COMPACT, null);

        Assert.assertSame(v1, g.getVertex(1));
        Assert.assertSame(v2, g.getVertex(2));
        Assert.assertSame(e, g.getEdge(0));
    }
View Full Code Here

        Assert.assertSame(e, g.getEdge(0));
    }

    @Test
    public void edgeFromJsonInputStreamCompactNoIdOnEdge() throws IOException, JSONException {
        Graph g = new TinkerGraph();
        ElementFactory factory = new GraphElementFactory(g);

        Set<String> vertexKeys = new HashSet<String>() {{
            add(GraphSONTokens._ID);
        }};

        Set<String> edgeKeys = new HashSet<String>() {{
            add(GraphSONTokens._IN_V);
        }};

        GraphSONUtility graphson = new GraphSONUtility(GraphSONMode.COMPACT, factory, vertexKeys, edgeKeys);

        Vertex v1 = graphson.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)));
        Vertex v2 = graphson.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)));
        Edge e = graphson.edgeFromJson(inputStreamEdgeJsonLight, v1, v2);

        Assert.assertSame(v1, g.getVertex(1));
        Assert.assertSame(v2, g.getVertex(2));
        Assert.assertSame(e, g.getEdge(0));
    }
View Full Code Here

* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class GraphHelperTest extends BaseTest {

    public void testAddVertex() {
        Graph graph = new TinkerGraph();
        Vertex vertex = GraphHelper.addVertex(graph, null, "name", "marko", "age", 31);
        assertEquals(vertex.getProperty("name"), "marko");
        assertEquals(vertex.getProperty("age"), 31);
        assertEquals(vertex.getPropertyKeys().size(), 2);
        assertEquals(count(graph.getVertices()), 1);

        try {
            vertex = GraphHelper.addVertex(graph, null, "name", "marko", "age");
            assertTrue(false);
        } catch (Exception e) {
            assertFalse(false);
            assertEquals(count(graph.getVertices()), 1);
        }
    }
View Full Code Here

            assertEquals(count(graph.getVertices()), 1);
        }
    }

    public void testAddEdge() {
        Graph graph = new TinkerGraph();
        Edge edge = GraphHelper.addEdge(graph, null, graph.addVertex(null), graph.addVertex(null), "knows", "weight", 10.0f);
        assertEquals(edge.getProperty("weight"), 10.0f);
        assertEquals(edge.getLabel(), "knows");
        assertEquals(edge.getPropertyKeys().size(), 1);
        assertEquals(count(graph.getVertices()), 2);
        assertEquals(count(graph.getEdges()), 1);

        try {
            edge = GraphHelper.addEdge(graph, null, graph.addVertex(null), graph.addVertex(null), "knows", "weight");
            assertTrue(false);
        } catch (Exception e) {
            assertFalse(false);
            assertEquals(count(graph.getVertices()), 4);
            assertEquals(count(graph.getEdges()), 1);
        }
    }
View Full Code Here

        }
    }

    public void testCopyGraph() {
        Graph g = TinkerGraphFactory.createTinkerGraph();
        Graph h = new TinkerGraph();

        GraphHelper.copyGraph(g, h);
        assertEquals(count(h.getVertices()), 6);
        assertEquals(count(h.getEdges()), 6);
        assertEquals(count(h.getVertex("1").getEdges(Direction.OUT)), 3);
        assertEquals(count(h.getVertex("1").getEdges(Direction.IN)), 0);
        Vertex marko = h.getVertex("1");
        assertEquals(marko.getProperty("name"), "marko");
        assertEquals(marko.getProperty("age"), 29);
        int counter = 0;
        for (Edge e : h.getVertex("1").getEdges(Direction.OUT)) {
            if (e.getVertex(Direction.IN).getId().equals("2")) {
                assertEquals(e.getProperty("weight"), 0.5f);
                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.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.getLabel(), "knows");
                assertEquals(e.getId(), "8");
                counter++;
            }
        }

        assertEquals(count(h.getVertex("4").getEdges(Direction.OUT)), 2);
        assertEquals(count(h.getVertex("4").getEdges(Direction.IN)), 1);
        Vertex josh = h.getVertex("4");
        assertEquals(josh.getProperty("name"), "josh");
        assertEquals(josh.getProperty("age"), 32);
        for (Edge e : h.getVertex("4").getEdges(Direction.OUT)) {
            if (e.getVertex(Direction.IN).getId().equals("3")) {
                assertEquals(Math.round((Float) e.getProperty("weight")), 0);
                assertEquals(e.getLabel(), "created");
                assertEquals(e.getId(), "11");
                counter++;
View Full Code Here

* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class KeyIndexableGraphHelperTest extends BaseTest {

    public void testReIndexElements() {
        TinkerGraph graph = TinkerGraphFactory.createTinkerGraph();
        assertTrue(graph.getVertices("name", "marko") instanceof PropertyFilteredIterable);
        assertEquals(count(graph.getVertices("name", "marko")), 1);
        assertEquals(graph.getVertices("name", "marko").iterator().next(), graph.getVertex(1));
        graph.createKeyIndex("name", Vertex.class);
        //KeyIndexableGraphHelper.reIndexElements(graph, graph.getVertices(), new HashSet<String>(Arrays.asList("name")));
        assertFalse(graph.getVertices("name", "marko") instanceof PropertyFilteredIterable);
        assertEquals(count(graph.getVertices("name", "marko")), 1);
        assertEquals(graph.getVertices("name", "marko").iterator().next(), graph.getVertex(1));
    }
View Full Code Here

* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class PropertyFilteredIterableTest extends BaseTest {

    public void testBasicFunctionality() {
        TinkerGraph graph = new TinkerGraph();
        Vertex a = graph.addVertex("a");
        a.setProperty("age", 29);
        Vertex b = graph.addVertex("b");
        b.setProperty("age", 29);
        Vertex c = graph.addVertex("c");
        c.setProperty("age", 30);
        Vertex d = graph.addVertex("d");
        d.setProperty("age", 31);

        // throw a vertex without the expected key in the mix
        Vertex e = graph.addVertex("e");
        List<Vertex> list = Arrays.asList(a, b, c, d, e);

        PropertyFilteredIterable<Vertex> iterable = new PropertyFilteredIterable<Vertex>("age", 29, list);
        assertEquals(count(iterable), 2);
        assertEquals(count(iterable), 2);
        for (Vertex vertex : iterable) {
            assertTrue(vertex.equals(a) || vertex.equals(b));
        }
        iterable = new PropertyFilteredIterable<Vertex>("age", 30, list);
        assertEquals(count(iterable), 1);
        assertEquals(iterable.iterator().next(), c);

        iterable = new PropertyFilteredIterable<Vertex>("age", 30, graph.getVertices());
        assertEquals(count(iterable), 1);
        assertEquals(iterable.iterator().next(), c);

        iterable = new PropertyFilteredIterable<Vertex>("age", 37, list);
        assertEquals(count(iterable), 0);
View Full Code Here

    private final URI markoKnowsVadas, markoKnowsJosh, markoCreatedLop, joshCreatedRipple, joshCreatedLop, peterCreatedLop;

    private SailConnection sc;

    public PropertyGraphSailTest() throws Exception {
        Graph g = new TinkerGraph();
        GraphMLReader r = new GraphMLReader(g);
        r.inputGraph(GraphMLReader.class.getResourceAsStream("graph-example-1.xml"));

        sail = new PropertyGraphSail(g);
        sail.initialize();
View Full Code Here

    public Graph generateGraph() {
        return generateGraph("");
    }

    public Graph generateGraph(final String graphDirectoryName) {
        return new PartitionIndexableGraph<TinkerGraph>(new TinkerGraph(), "_writeGraph", "writeGraph", new HashSet<String>(Arrays.asList("writeGraph")));
    }
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.