use of com.baidu.hugegraph.structure.gremlin.Response in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadGremlinVertices.
@Test
public void testReadGremlinVertices() {
String json = "{" + "\"requestId\": \"b0fd8ead-333f-43ac-97b0-4d78784726ae\"," + "\"status\": {" + "\"message\": \"\"," + "\"code\": 200," + "\"attributes\": {}" + "}," + "\"result\": {" + "\"data\": [" + "{" + "\"id\": \"person:marko\"," + "\"label\": \"person\"," + "\"type\": \"vertex\"," + "\"properties\": {" + "\"city\": [\"Beijing\",\"Wuhan\",\"Beijing\"]," + "\"name\": \"marko\"," + "\"age\": 29" + "}" + "}," + "{" + "\"id\": \"software:lop\"," + "\"label\": \"software\"," + "\"type\": \"vertex\"," + "\"properties\": {" + "\"price\": 328," + "\"name\": \"lop\"," + "\"lang\": [\"java\",\"python\",\"c++\"]" + "}" + "}," + "{" + "\"id\": \"person:peter\"," + "\"label\": \"person\"," + "\"type\": \"vertex\"," + "\"properties\": {" + "\"city\": [\"Shanghai\"]," + "\"name\": \"peter\"," + "\"age\": 35" + "}" + "}" + "]," + "\"meta\": {}" + "}" + "}";
Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
RestResult restResult = new RestResult(this.mockResponse);
Assert.assertEquals(200, restResult.status());
Assert.assertNull(restResult.headers());
Response response = restResult.readObject(Response.class);
response.graphManager(graph());
Assert.assertEquals("b0fd8ead-333f-43ac-97b0-4d78784726ae", response.requestId());
Assert.assertEquals(200, response.status().code());
Vertex marko = new Vertex("person");
marko.id("person:marko");
marko.property("name", "marko");
marko.property("city", ImmutableList.of("Beijing", "Wuhan", "Beijing"));
marko.property("age", 29);
Vertex lop = new Vertex("software");
lop.id("software:lop");
lop.property("name", "lop");
lop.property("lang", ImmutableList.of("java", "python", "c++"));
lop.property("price", 328);
Vertex peter = new Vertex("person");
peter.id("person:peter");
peter.property("name", "peter");
peter.property("city", ImmutableList.of("Shanghai"));
peter.property("age", 35);
List<Vertex> vertices = new ArrayList<>(3);
vertices.add(peter);
vertices.add(marko);
vertices.add(lop);
Iterator<Result> results = response.result().iterator();
while (results.hasNext()) {
Result result = results.next();
Assert.assertEquals(Vertex.class, result.getObject().getClass());
Vertex vertex = result.getVertex();
Assert.assertTrue(Utils.contains(vertices, vertex));
}
}
use of com.baidu.hugegraph.structure.gremlin.Response in project incubator-hugegraph-toolchain by apache.
the class GremlinManager method execute.
public ResultSet execute(GremlinRequest request) {
// Bind "graph" to all graphs
request.aliases.put("graph", this.graph);
// Bind "g" to all graphs by custom rule which define in gremlin server.
request.aliases.put("g", "__g_" + this.graph);
Response response = this.gremlinAPI.post(request);
response.graphManager(this.graphManager);
// TODO: Can add some checks later
return response.result();
}
Aggregations