use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadIndexLabels.
@Test
public void testReadIndexLabels() {
String json = "{\"indexlabels\": [" + "{" + "\"id\": \"4\"," + "\"index_type\": \"SEARCH\"," + "\"base_value\": \"software\"," + "\"name\": \"softwareByPrice\"," + "\"fields\": [\"price\"]," + "\"base_type\": \"VERTEX_LABEL\"" + "}," + "{" + "\"id\": \"4\"," + "\"index_type\": \"SECONDARY\"," + "\"base_value\": \"person\"," + "\"name\": \"personByName\"," + "\"fields\": [\"name\"]," + "\"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());
List<IndexLabel> indexLabels = result.readList("indexlabels", IndexLabel.class);
Assert.assertEquals(2, indexLabels.size());
IndexLabel indexLabel1 = indexLabels.get(0);
IndexLabel indexLabel2 = indexLabels.get(1);
Assert.assertEquals("softwareByPrice", indexLabel1.name());
Assert.assertEquals(HugeType.VERTEX_LABEL, indexLabel1.baseType());
Assert.assertEquals("software", indexLabel1.baseValue());
Assert.assertEquals(IndexType.SEARCH, indexLabel1.indexType());
Assert.assertEquals(ImmutableList.of("price"), indexLabel1.indexFields());
Assert.assertEquals("personByName", indexLabel2.name());
Assert.assertEquals(HugeType.VERTEX_LABEL, indexLabel2.baseType());
Assert.assertEquals("person", indexLabel2.baseValue());
Assert.assertEquals(IndexType.SECONDARY, indexLabel2.indexType());
Assert.assertEquals(ImmutableList.of("name"), indexLabel2.indexFields());
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class GraphsAPI method mode.
public GraphMode mode(String graph) {
RestResult result = this.client.get(joinPath(this.path(), graph), MODE);
@SuppressWarnings("unchecked") Map<String, String> mode = result.readObject(Map.class);
String value = mode.get(MODE);
if (value == null) {
throw new InvalidResponseException("Invalid response, expect 'mode' in response");
}
try {
return GraphMode.valueOf(value);
} catch (IllegalArgumentException e) {
throw new InvalidResponseException("Invalid GraphMode value '%s'", value);
}
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class GraphsAPI method readMode.
public GraphReadMode readMode(String graph) {
this.client.checkApiVersion("0.59", "graph read mode");
RestResult result = this.client.get(joinPath(this.path(), graph), GRAPH_READ_MODE);
@SuppressWarnings("unchecked") Map<String, String> readMode = result.readObject(Map.class);
String value = readMode.get(GRAPH_READ_MODE);
if (value == null) {
throw new InvalidResponseException("Invalid response, expect 'graph_read_mode' in response");
}
try {
return GraphReadMode.valueOf(value);
} catch (IllegalArgumentException e) {
throw new InvalidResponseException("Invalid GraphReadMode value '%s'", value);
}
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class EdgeAPI method append.
public Edge append(Edge edge) {
String id = edge.id();
Map<String, Object> params = ImmutableMap.of("action", "append");
RestResult result = this.client.put(this.path(), id, edge, params);
return result.readObject(Edge.class);
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class VertexAPI method append.
public Vertex append(Vertex vertex) {
String id = GraphAPI.formatVertexId(vertex.id());
Map<String, Object> params = ImmutableMap.of("action", "append");
RestResult result = this.client.put(this.path(), id, vertex, params);
return result.readObject(Vertex.class);
}
Aggregations