use of org.codehaus.jettison.json.JSONTokener 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 org.codehaus.jettison.json.JSONTokener in project blueprints by tinkerpop.
the class RestHelper method post.
private static JSONObject post(final String uri, final String postData, final String contentType, final String accept, final boolean noResult) {
try {
final HttpURLConnection connection = createConnection(uri, contentType, accept);
connection.setDoOutput(true);
final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
// post data with Content-Length automatically set
writer.write(postData);
writer.close();
if (noResult) {
new InputStreamReader(connection.getInputStream()).close();
return null;
} else {
return new JSONObject(new JSONTokener(convertStreamToString(connection.getInputStream())));
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of org.codehaus.jettison.json.JSONTokener in project blueprints by tinkerpop.
the class GraphSONUtilityTest method edgeFromJsonInputStreamCompactLabelOrIdOnEdge.
@Test
public void edgeFromJsonInputStreamCompactLabelOrIdOnEdge() throws IOException, JSONException {
Graph g = new TinkerGraph();
ElementFactory factory = new GraphElementFactory(g);
Vertex v1 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.COMPACT, null);
Vertex v2 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)), factory, GraphSONMode.COMPACT, null);
Edge e = GraphSONUtility.edgeFromJson(inputStreamEdgeJsonLight, v1, v2, factory, GraphSONMode.COMPACT, 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 edgeFromJsonIgnoreWeightValid.
@Test
public void edgeFromJsonIgnoreWeightValid() 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);
Set<String> ignoreWeight = new HashSet<String>();
ignoreWeight.add("weight");
ElementPropertyConfig config = ElementPropertyConfig.excludeProperties(null, ignoreWeight);
GraphSONUtility utility = new GraphSONUtility(GraphSONMode.NORMAL, factory, config);
Edge e = utility.edgeFromJson(new JSONObject(new JSONTokener(edgeJson)), v1, v2);
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.assertNull(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 RestHelper method get.
static JSONObject get(final String uri) {
try {
final URLConnection connection = createConnection(uri, null, RexsterTokens.APPLICATION_REXSTER_TYPED_JSON);
connection.connect();
return new JSONObject(new JSONTokener(convertStreamToString(connection.getInputStream())));
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
Aggregations