use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadEdgeLabels.
@Test
public void testReadEdgeLabels() {
String json = "{\"edgelabels\": [" + "{" + "\"id\": 2," + "\"source_label\": \"person\"," + "\"index_labels\": [\"createdByDate\"]," + "\"name\": \"created\"," + "\"target_label\": \"software\"," + "\"sort_keys\": []," + "\"properties\": [\"date\"]," + "\"frequency\": \"SINGLE\"" + "}," + "{\"id\": 3," + "\"source_label\": \"person\"," + "\"index_labels\": []," + "\"name\": \"knows\"," + "\"target_label\": \"person\"," + "\"sort_keys\": []," + "\"properties\": [\"date\", \"city\"]," + "\"frequency\": \"SINGLE\"" + "}" + "]}";
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<EdgeLabel> edgeLabels = result.readList("edgelabels", EdgeLabel.class);
Assert.assertEquals(2, edgeLabels.size());
EdgeLabel edgeLabel1 = edgeLabels.get(0);
EdgeLabel edgeLabel2 = edgeLabels.get(1);
Assert.assertEquals("created", edgeLabel1.name());
Assert.assertEquals("person", edgeLabel1.sourceLabel());
Assert.assertEquals("software", edgeLabel1.targetLabel());
Assert.assertEquals(Frequency.SINGLE, edgeLabel1.frequency());
Assert.assertEquals(Collections.emptyList(), edgeLabel1.sortKeys());
Assert.assertEquals(ImmutableSet.of("date"), edgeLabel1.properties());
Assert.assertEquals("knows", edgeLabel2.name());
Assert.assertEquals("person", edgeLabel2.sourceLabel());
Assert.assertEquals("person", edgeLabel2.targetLabel());
Assert.assertEquals(Frequency.SINGLE, edgeLabel2.frequency());
Assert.assertEquals(Collections.emptyList(), edgeLabel2.sortKeys());
Assert.assertEquals(ImmutableSet.of("date", "city"), edgeLabel2.properties());
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadPropertyKeys.
@Test
public void testReadPropertyKeys() {
String json = "{\"propertykeys\": [" + "{" + "\"id\": 3," + "\"data_type\": \"TEXT\"," + "\"name\": \"id\"," + "\"cardinality\": \"SINGLE\"," + "\"properties\": []" + "}," + "{\"id\": 4," + "\"data_type\": \"FLOAT\"," + "\"name\": \"date\"," + "\"cardinality\": \"SET\"," + "\"properties\": []" + "}" + "]}";
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<PropertyKey> propertyKeys = result.readList("propertykeys", PropertyKey.class);
Assert.assertEquals(2, propertyKeys.size());
PropertyKey propertyKey1 = propertyKeys.get(0);
PropertyKey propertyKey2 = propertyKeys.get(1);
Assert.assertEquals("id", propertyKey1.name());
Assert.assertEquals(DataType.TEXT, propertyKey1.dataType());
Assert.assertEquals(Cardinality.SINGLE, propertyKey1.cardinality());
Assert.assertEquals(Collections.emptySet(), propertyKey1.properties());
Assert.assertEquals("date", propertyKey2.name());
Assert.assertEquals(DataType.FLOAT, propertyKey2.dataType());
Assert.assertEquals(Cardinality.SET, propertyKey2.cardinality());
Assert.assertEquals(Collections.emptySet(), propertyKey2.properties());
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadEdgeLabel.
@Test
public void testReadEdgeLabel() {
String json = "{" + "\"id\": 2," + "\"source_label\": \"person\"," + "\"index_labels\": [\"createdByDate\"]," + "\"name\": \"created\"," + "\"target_label\": \"software\"," + "\"sort_keys\": []," + "\"properties\": [\"date\"]," + "\"frequency\": \"SINGLE\"" + "}";
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());
EdgeLabel edgeLabel = result.readObject(EdgeLabel.class);
Assert.assertEquals("created", edgeLabel.name());
Assert.assertEquals("person", edgeLabel.sourceLabel());
Assert.assertEquals("software", edgeLabel.targetLabel());
Assert.assertEquals(Frequency.SINGLE, edgeLabel.frequency());
Assert.assertEquals(Collections.emptyList(), edgeLabel.sortKeys());
Assert.assertEquals(ImmutableSet.of("date"), edgeLabel.properties());
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadGremlinNullAndVertex.
@Test
public void testReadGremlinNullAndVertex() {
String json = "{" + "\"requestId\": \"d95ac131-24b5-4140-a3ff-91b0c020764a\"," + "\"status\": {" + "\"message\": \"\"," + "\"code\": 200," + "\"attributes\": {}" + "}," + "\"result\": {" + "\"data\": [" + "null," + "{" + "\"id\": \"person:marko\"," + "\"label\": \"person\"," + "\"type\": \"vertex\"," + "\"properties\": {" + "\"city\": \"Beijing\"," + "\"name\": \"marko\"," + "\"age\": 29" + "}" + "}" + "]," + "\"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();
Assert.assertNull(result);
Assert.assertTrue(results.hasNext());
result = results.next();
Assert.assertEquals(Vertex.class, result.getObject().getClass());
Vertex marko = new Vertex("person");
marko.id("person:marko");
marko.property("name", "marko");
marko.property("city", "Beijing");
marko.property("age", 29);
Vertex vertex = result.getVertex();
Assert.assertTrue(Utils.contains(ImmutableList.of(marko), vertex));
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadGremlinNullData.
@Test
public void testReadGremlinNullData() {
String json = "{" + "\"requestId\": \"d95ac131-24b5-4140-a3ff-91b0c020764a\"," + "\"status\": {" + "\"message\": \"\"," + "\"code\": 200," + "\"attributes\": {}" + "}," + "\"result\": {" + "\"data\": [null]," + "\"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());
Object object = results.next();
Assert.assertNull(object);
}
Aggregations