use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class TaskAPI method list.
public List<Task> list(List<Long> ids) {
Map<String, Object> params = new LinkedHashMap<>();
params.put("ids", ids);
RestResult result = this.client.get(this.path(), params);
return result.readList(TASKS, Task.class);
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class TaskAPI method cancel.
public Task cancel(long id) {
Map<String, Object> params = ImmutableMap.of("action", "cancel");
RestResult result = this.client.put(path(), String.valueOf(id), ImmutableMap.of(), params);
return result.readObject(Task.class);
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class AccessAPI method update.
public Access update(Access access) {
String id = formatRelationId(access.id());
RestResult result = this.client.put(this.path(), id, access);
return result.readObject(Access.class);
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadIndexLabel.
@Test
public void testReadIndexLabel() {
String json = "{" + "\"id\": \"4\"," + "\"index_type\": \"SEARCH\"," + "\"base_value\": \"software\"," + "\"name\": \"softwareByPrice\"," + "\"fields\": [\"price\"]," + "\"base_type\": \"VERTEX_LABEL\"" + "}";
Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
RestResult result = new RestResult(this.mockResponse);
Assert.assertEquals(200, result.status());
Assert.assertNull(result.headers());
IndexLabel indexLabel = result.readObject(IndexLabel.class);
Assert.assertEquals("softwareByPrice", indexLabel.name());
Assert.assertEquals(HugeType.VERTEX_LABEL, indexLabel.baseType());
Assert.assertEquals("software", indexLabel.baseValue());
Assert.assertEquals(IndexType.SEARCH, indexLabel.indexType());
Assert.assertEquals(ImmutableList.of("price"), indexLabel.indexFields());
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadGremlinPathWithVertexAndEdge.
@Test
public void testReadGremlinPathWithVertexAndEdge() {
String json = "{" + "\"requestId\": \"238c74ca-18f7-4377-b8e1-2bb3b165e5d6\"," + "\"status\":{" + "\"message\": \"\"," + "\"code\": 200," + "\"attributes\":{}" + "}," + "\"result\":{" + "\"data\":[" + "{" + "\"labels\":[[], []]," + "\"objects\":[" + "{" + "\"id\": \"person:marko\"," + "\"label\": \"person\"," + "\"type\": \"vertex\"," + "\"properties\":{" + "\"city\":\"Beijing\"," + "\"name\":\"marko\"," + "\"age\":29" + "}" + "}," + "{" + "\"id\": \"person:marko>knows>>person:vadas\"," + "\"label\": \"knows\"," + "\"type\": \"edge\"," + "\"inVLabel\": \"person\"," + "\"outVLabel\": \"person\"," + "\"inV\": \"person:vadas\"," + "\"outV\": \"person:marko\"," + "\"properties\":{" + "\"date\": 1452355200000," + "\"weight\": 0.5" + "}" + "}" + "]" + "}" + "]," + "\"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(200, response.status().code());
Iterator<Result> results = response.result().iterator();
Assert.assertTrue(results.hasNext());
Result result = results.next();
Object object = result.getObject();
Assert.assertEquals(Path.class, object.getClass());
Path path = (Path) object;
Assert.assertEquals(2, path.labels().size());
Assert.assertEquals(ImmutableList.of(), path.labels().get(0));
Assert.assertEquals(ImmutableList.of(), path.labels().get(1));
Vertex vertex = new Vertex("person");
vertex.id("person:marko");
vertex.property("name", "marko");
vertex.property("age", 29);
vertex.property("city", "Beijing");
Edge edge = new Edge("knows");
edge.id("person:marko>knows>>person:vadas");
edge.sourceId("person:marko");
edge.sourceLabel("person");
edge.targetId("person:vadas");
edge.targetLabel("person");
edge.property("date", 1452355200000L);
edge.property("weight", 0.5);
Assert.assertEquals(2, path.objects().size());
Utils.assertGraphEqual(ImmutableList.of(vertex), ImmutableList.of(edge), path.objects());
}
Aggregations