Search in sources :

Example 86 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class GraphSONUtilityTest method vertexFromJsonExtendedTypesValid.

@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"));
}
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 87 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class GraphSONUtilityTest method edgeFromJsonInputStreamCompactNoIdOnEdge.

@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));
}
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) Edge(com.tinkerpop.blueprints.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 88 with Vertex

use of com.tinkerpop.blueprints.Vertex 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 89 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class GraphSONUtilityTest method jsonFromElementVertexStringArrayPropertyNoKeysNoTypes.

@Test
public void jsonFromElementVertexStringArrayPropertyNoKeysNoTypes() throws JSONException {
    Vertex v = this.graph.addVertex(1);
    String[] stringArray = new String[] { "this", "that", "other" };
    v.setProperty("keyStringArray", stringArray);
    JSONObject json = GraphSONUtility.jsonFromElement(v, null, GraphSONMode.NORMAL);
    Assert.assertNotNull(json);
    Assert.assertTrue(json.has(GraphSONTokens._ID));
    Assert.assertEquals(1, json.optInt(GraphSONTokens._ID));
    Assert.assertTrue(json.has("keyStringArray"));
    JSONArray stringArrayAsJSON = json.optJSONArray("keyStringArray");
    Assert.assertNotNull(stringArrayAsJSON);
    Assert.assertEquals(3, stringArrayAsJSON.length());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test)

Example 90 with Vertex

use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.

the class GraphSONUtilityTest method jsonFromElementVertexIntIteratorPropertiesNoKeysWithTypes.

@Test
public void jsonFromElementVertexIntIteratorPropertiesNoKeysWithTypes() throws JSONException {
    Vertex v = this.graph.addVertex(1);
    List<Integer> list = new ArrayList<Integer>();
    list.add(1);
    list.add(1);
    list.add(1);
    // might be kinda weird if there were an Iterator in there but perhaps there is something that implements it
    v.setProperty("keyList", list.iterator());
    JSONObject json = GraphSONUtility.jsonFromElement(v, null, GraphSONMode.EXTENDED);
    Assert.assertNotNull(json);
    Assert.assertTrue(json.has(GraphSONTokens._ID));
    Assert.assertEquals(1, json.optInt(GraphSONTokens._ID));
    Assert.assertTrue(json.has("keyList"));
    JSONObject listWithTypeAsJson = json.optJSONObject("keyList");
    Assert.assertNotNull(listWithTypeAsJson);
    Assert.assertTrue(listWithTypeAsJson.has(GraphSONTokens.TYPE));
    Assert.assertEquals(GraphSONTokens.TYPE_LIST, listWithTypeAsJson.optString(GraphSONTokens.TYPE));
    Assert.assertTrue(listWithTypeAsJson.has(GraphSONTokens.VALUE));
    JSONArray listAsJSON = listWithTypeAsJson.optJSONArray(GraphSONTokens.VALUE);
    Assert.assertNotNull(listAsJSON);
    Assert.assertEquals(3, listAsJSON.length());
    for (int ix = 0; ix < listAsJSON.length(); ix++) {
        JSONObject valueAsJson = listAsJSON.optJSONObject(ix);
        Assert.assertNotNull(valueAsJson);
        Assert.assertTrue(valueAsJson.has(GraphSONTokens.TYPE));
        Assert.assertEquals(GraphSONTokens.TYPE_INTEGER, valueAsJson.optString(GraphSONTokens.TYPE));
        Assert.assertTrue(valueAsJson.has(GraphSONTokens.VALUE));
        Assert.assertEquals(1, valueAsJson.optInt(GraphSONTokens.VALUE));
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) JSONObject(org.codehaus.jettison.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test)

Aggregations

Vertex (com.tinkerpop.blueprints.Vertex)406 Test (org.junit.Test)119 Edge (com.tinkerpop.blueprints.Edge)111 Graph (com.tinkerpop.blueprints.Graph)85 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)84 JSONObject (org.codehaus.jettison.json.JSONObject)51 HashSet (java.util.HashSet)49 ArrayList (java.util.ArrayList)40 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)37 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)28 HashMap (java.util.HashMap)25 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)22 JSONArray (org.codehaus.jettison.json.JSONArray)20 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)19 Test (org.testng.annotations.Test)16 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)15 Map (java.util.Map)15 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)14 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11