use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.
the class GraphSONUtilityTest method jsonFromElementNullsNoKeysWithTypes.
@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>();
innerList.add(null);
innerList.add("innerstring");
map.put("list", innerList);
v.setProperty("keyMap", map);
List<String> list = new ArrayList<String>();
list.add(null);
list.add("string");
v.setProperty("keyList", list);
JSONObject json = GraphSONUtility.jsonFromElement(v, null, GraphSONMode.EXTENDED);
Assert.assertNotNull(json);
JSONObject jsonMap = json.optJSONObject("keyMap").optJSONObject(GraphSONTokens.VALUE);
Assert.assertNotNull(jsonMap);
JSONObject jsonObjectMap = jsonMap.optJSONObject("innerkey");
Assert.assertTrue(jsonObjectMap.isNull(GraphSONTokens.VALUE));
Assert.assertEquals(GraphSONTokens.TYPE_UNKNOWN, jsonObjectMap.optString(GraphSONTokens.TYPE));
JSONArray jsonInnerArray = jsonMap.getJSONObject("list").getJSONArray(GraphSONTokens.VALUE);
Assert.assertNotNull(jsonInnerArray);
JSONObject jsonObjectInnerListFirst = jsonInnerArray.getJSONObject(0);
Assert.assertTrue(jsonObjectInnerListFirst.isNull(GraphSONTokens.VALUE));
Assert.assertEquals(GraphSONTokens.TYPE_UNKNOWN, jsonObjectInnerListFirst.optString(GraphSONTokens.TYPE));
JSONArray jsonArray = json.getJSONObject("keyList").getJSONArray(GraphSONTokens.VALUE);
Assert.assertNotNull(jsonArray);
JSONObject jsonObjectListFirst = jsonArray.getJSONObject(0);
Assert.assertTrue(jsonObjectListFirst.isNull(GraphSONTokens.VALUE));
Assert.assertEquals(GraphSONTokens.TYPE_UNKNOWN, jsonObjectListFirst.optString(GraphSONTokens.TYPE));
}
use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.
the class GraphSONUtilityTest method jsonFromElementVertexCompactIdOnlyAsInclude.
@Test
public void jsonFromElementVertexCompactIdOnlyAsInclude() throws JSONException {
Vertex v = this.graph.addVertex(1);
v.setProperty("name", "marko");
Set<String> propertiesToInclude = new HashSet<String>() {
{
add(GraphSONTokens._ID);
}
};
JSONObject json = GraphSONUtility.jsonFromElement(v, propertiesToInclude, GraphSONMode.COMPACT);
Assert.assertNotNull(json);
Assert.assertFalse(json.has(GraphSONTokens._TYPE));
Assert.assertTrue(json.has(GraphSONTokens._ID));
Assert.assertFalse(json.has("name"));
}
use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.
the class GraphSONUtilityTest method jsonFromElementVertexCompactAllOnly.
@Test
public void jsonFromElementVertexCompactAllOnly() throws JSONException {
Vertex v = this.graph.addVertex(1);
v.setProperty("name", "marko");
JSONObject json = GraphSONUtility.jsonFromElement(v, null, GraphSONMode.COMPACT);
Assert.assertNotNull(json);
Assert.assertTrue(json.has(GraphSONTokens._TYPE));
Assert.assertTrue(json.has(GraphSONTokens._ID));
Assert.assertTrue(json.has("name"));
}
use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.
the class GraphSONUtilityTest method edgeFromJsonValid.
@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());
Assert.assertEquals(v1, e.getVertex(Direction.OUT));
Assert.assertEquals(v2, e.getVertex(Direction.IN));
}
use of com.tinkerpop.blueprints.Vertex in project blueprints by tinkerpop.
the class GraphSONUtilityTest method jsonFromElementFloatArrayPropertyNoKeysNoTypes.
@Test
public void jsonFromElementFloatArrayPropertyNoKeysNoTypes() throws JSONException {
Vertex v = this.graph.addVertex(1);
float[] floatArray = new float[] { 1.0f, 2.0f, 3.0f };
v.setProperty("keyFloatArray", floatArray);
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("keyFloatArray"));
JSONArray floatArrayAsJSON = json.optJSONArray("keyFloatArray");
Assert.assertNotNull(floatArrayAsJSON);
Assert.assertEquals(3, floatArrayAsJSON.length());
}
Aggregations