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());
}
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"));
}
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));
}
}
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));
}
}
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"));
}
Aggregations