Search in sources :

Example 56 with Vertex

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

the class EventGraphTest method testFireVertexRemoved.

public void testFireVertexRemoved() {
    graph.addListener(graphChangedListener);
    Vertex vertex = createVertex();
    graph.removeVertex(vertex);
    assertEquals(1, graphChangedListener.vertexRemovedEventRecorded());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex)

Example 57 with Vertex

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

the class GraphSONReaderTest method inputGraphModeExtended.

@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"));
//Assert.assertNull(e.getProperty("keyNull"));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) List(java.util.List) Map(java.util.Map) Edge(com.tinkerpop.blueprints.Edge) Test(org.junit.Test)

Example 58 with Vertex

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

the class GraphSONUtilityTest method jsonFromElementVertexBooleanListPropertiesNoKeysWithTypes.

@Test
public void jsonFromElementVertexBooleanListPropertiesNoKeysWithTypes() throws JSONException {
    Vertex v = this.graph.addVertex(1);
    List<Boolean> list = new ArrayList<Boolean>();
    list.add(true);
    list.add(true);
    list.add(true);
    v.setProperty("keyList", list);
    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_BOOLEAN, valueAsJson.optString(GraphSONTokens.TYPE));
        Assert.assertTrue(valueAsJson.has(GraphSONTokens.VALUE));
        Assert.assertEquals(true, valueAsJson.optBoolean(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)

Example 59 with Vertex

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

the class GraphSONUtilityTest method jsonFromElementVertexLongListPropertiesNoKeysWithTypes.

@Test
public void jsonFromElementVertexLongListPropertiesNoKeysWithTypes() throws JSONException {
    Vertex v = this.graph.addVertex(1);
    List<Long> list = new ArrayList<Long>();
    list.add(1000L);
    list.add(1000L);
    list.add(1000L);
    v.setProperty("keyList", list);
    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_LONG, valueAsJson.optString(GraphSONTokens.TYPE));
        Assert.assertTrue(valueAsJson.has(GraphSONTokens.VALUE));
        Assert.assertEquals(1000L, valueAsJson.optLong(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)

Example 60 with Vertex

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

the class GraphSONUtilityTest method jsonFromElementVertexNoPropertiesWithKeysNoTypes.

@Test
public void jsonFromElementVertexNoPropertiesWithKeysNoTypes() throws JSONException {
    Vertex v = this.graph.addVertex(1);
    v.setProperty("x", "X");
    v.setProperty("y", "Y");
    v.setProperty("z", "Z");
    Set<String> propertiesToInclude = new HashSet<String>();
    propertiesToInclude.add("y");
    JSONObject json = GraphSONUtility.jsonFromElement(v, propertiesToInclude, GraphSONMode.NORMAL);
    Assert.assertNotNull(json);
    Assert.assertTrue(json.has(GraphSONTokens._ID));
    Assert.assertEquals(1, json.optInt(GraphSONTokens._ID));
    Assert.assertTrue(json.has(GraphSONTokens._TYPE));
    Assert.assertEquals("vertex", json.optString(GraphSONTokens._TYPE));
    Assert.assertFalse(json.has("x"));
    Assert.assertFalse(json.has("z"));
    Assert.assertTrue(json.has("y"));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) JSONObject(org.codehaus.jettison.json.JSONObject) HashSet(java.util.HashSet) 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