Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.Graph


    }

    @Test
    public void vertexFromJsonExtendedTypesValid() throws IOException, JSONException {
        // need to test those data types that are not covered by the toy graphs
        Graph g = new TinkerGraph();
        ElementFactory factory = new GraphElementFactory(g);

        Vertex v = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson3)), factory, GraphSONMode.EXTENDED, null);

        Assert.assertSame(v, g.getVertex(1));

        Assert.assertEquals((byte) 4, v.getProperty("byteValue"));
        Assert.assertEquals(new Short("10"), v.getProperty("shortValue"));
        Assert.assertEquals(true, v.getProperty("booleanValue"));
    }
View Full Code Here


        Assert.assertEquals(true, v.getProperty("booleanValue"));
    }

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

        Vertex v = GraphSONUtility.vertexFromJson(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"));
View Full Code Here

        Assert.assertEquals(29, v.getProperty("age"));
    }

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

        Vertex v = GraphSONUtility.vertexFromJson(inputStreamVertexJson1, 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"));
View Full Code Here

        Assert.assertEquals(29, v.getProperty("age"));
    }

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

        Set<String> ignoreAge = new HashSet<String>();
        ignoreAge.add("age");
        ElementPropertyConfig config = ElementPropertyConfig.excludeProperties(ignoreAge, null);
        GraphSONUtility utility = new GraphSONUtility(GraphSONMode.NORMAL, factory, config);
        Vertex v = utility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)));

        Assert.assertSame(v, g.getVertex(1));

        // tinkergraph converts id to string
        Assert.assertEquals("1", v.getId());
        Assert.assertEquals("marko", v.getProperty("name"));
        Assert.assertNull(v.getProperty("age"));
View Full Code Here

        Assert.assertNull(v.getProperty("age"));
    }

    @Test
    public void edgeFromJsonValid() 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(edgeJson)), v1, v2, factory, GraphSONMode.NORMAL, null);

        Assert.assertSame(v1, g.getVertex(1));
        Assert.assertSame(v2, g.getVertex(2));
        Assert.assertSame(e, g.getEdge(7));

        // tinkergraph converts id to string
        Assert.assertEquals("7", e.getId());
        Assert.assertEquals(0.5d, e.getProperty("weight"));
        Assert.assertEquals("knows", e.getLabel());
View Full Code Here

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

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

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

        Assert.assertSame(v1, g.getVertex(1));
        Assert.assertSame(v2, g.getVertex(2));
        Assert.assertSame(e, g.getEdge(7));

        // tinkergraph converts id to string
        Assert.assertEquals("7", e.getId());
        Assert.assertEquals(0.5d, e.getProperty("weight"));
        Assert.assertEquals("knows", e.getLabel());
View Full Code Here

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

    @Test
    public void edgeFromJsonIgnoreWeightValid() 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);

        Set<String> ignoreWeight = new HashSet<String>();
        ignoreWeight.add("weight");
        ElementPropertyConfig config = ElementPropertyConfig.excludeProperties(null, ignoreWeight);
        GraphSONUtility utility = new GraphSONUtility(GraphSONMode.NORMAL, factory, config);
        Edge e = utility.edgeFromJson(new JSONObject(new JSONTokener(edgeJson)), v1, v2);

        Assert.assertSame(v1, g.getVertex(1));
        Assert.assertSame(v2, g.getVertex(2));
        Assert.assertSame(e, g.getEdge(7));

        // tinkergraph converts id to string
        Assert.assertEquals("7", e.getId());
        Assert.assertNull(e.getProperty("weight"));
        Assert.assertEquals("knows", e.getLabel());
View Full Code Here

        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

TOP

Related Classes of com.tinkerpop.blueprints.Graph

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.