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