use of org.codehaus.jettison.json.JSONTokener in project blueprints by tinkerpop.
the class GraphSONUtilityTest method edgeFromJsonNormalLabelOrIdOnEdge.
@Test
public void edgeFromJsonNormalLabelOrIdOnEdge() 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(edgeJsonLight)), v1, v2, factory, GraphSONMode.NORMAL, null);
Assert.assertSame(v1, g.getVertex(1));
Assert.assertSame(v2, g.getVertex(2));
Assert.assertSame(e, g.getEdge(0));
}
use of org.codehaus.jettison.json.JSONTokener in project blueprints by tinkerpop.
the class GraphSONUtilityTest method vertexFromJsonIgnoreKeyValid.
@Test
public void vertexFromJsonIgnoreKeyValid() throws IOException, JSONException {
Graph g = new TinkerGraph();
ElementFactory factory = new GraphElementFactory(g);
Set<String> ignoreAge = new HashSet<String>();
ignoreAge.add("age");
ElementPropertyConfig config = ElementPropertyConfig.excludeProperties(ignoreAge, null);
GraphSONUtility utility = new GraphSONUtility(GraphSONMode.NORMAL, factory, config);
Vertex v = utility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)));
Assert.assertSame(v, g.getVertex(1));
// tinkergraph converts id to string
Assert.assertEquals("1", v.getId());
Assert.assertEquals("marko", v.getProperty("name"));
Assert.assertNull(v.getProperty("age"));
}
use of org.codehaus.jettison.json.JSONTokener 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 org.codehaus.jettison.json.JSONTokener 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 org.codehaus.jettison.json.JSONTokener 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));
}
Aggregations