Package com.tinkerpop.blueprints.impls.tg

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


        Assert.assertFalse(json.has("alwaysNull"));
    }

    @Test
    public void jsonFromElementNullsNoKeysNoTypes() throws JSONException {
        Graph g = new TinkerGraph();
        Vertex v = g.addVertex(1);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("innerkey", null);

        List<String> innerList = new ArrayList<String>();
View Full Code Here


        Assert.assertEquals("string", jsonArray.get(1));
    }

    @Test
    public void jsonFromElementNullsNoKeysWithTypes() throws JSONException {
        Graph g = new TinkerGraph();
        Vertex v = g.addVertex(1);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("innerkey", null);

        List<String> innerList = new ArrayList<String>();
View Full Code Here

        Assert.assertEquals(GraphSONTokens.TYPE_UNKNOWN, jsonObjectListFirst.optString(GraphSONTokens.TYPE));
    }

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

    }

    @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

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.