use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadEdges.
@Test
public void testReadEdges() {
String json = "{\"edges\": [" + "{" + "\"id\": \"person:peter>created>>software:lop\"," + "\"label\": \"created\"," + "\"type\": \"edge\"," + "\"inVLabel\": \"software\"," + "\"outVLabel\": \"person\"," + "\"inV\": \"software:lop\"," + "\"outV\": \"person:peter\"," + "\"properties\": {" + "\"date\": 1495036800000," + "\"city\": \"Hongkong\"" + "}" + "}," + "{" + "\"id\": \"person:peter>knows>>person:marko\"," + "\"label\": \"knows\"," + "\"type\": \"edge\"," + "\"inVLabel\": \"person\"," + "\"outVLabel\": \"person\"," + "\"inV\": \"person:marko\"," + "\"outV\": \"person:peter\"," + "\"properties\": {" + "\"date\": 1476720000000" + "}" + "}" + "]}";
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<Edge> edges = result.readList("edges", Edge.class);
Assert.assertEquals(2, edges.size());
Edge edge1 = edges.get(0);
Edge edge2 = edges.get(1);
Assert.assertEquals("person:peter>created>>software:lop", edge1.id());
Assert.assertEquals("created", edge1.label());
Assert.assertEquals("person:peter", edge1.sourceId());
Assert.assertEquals("software:lop", edge1.targetId());
Assert.assertEquals("person", edge1.sourceLabel());
Assert.assertEquals("software", edge1.targetLabel());
Assert.assertEquals(ImmutableMap.of("city", "Hongkong", "date", 1495036800000L), edge1.properties());
Assert.assertEquals("person:peter>knows>>person:marko", edge2.id());
Assert.assertEquals("knows", edge2.label());
Assert.assertEquals("person:peter", edge2.sourceId());
Assert.assertEquals("person:marko", edge2.targetId());
Assert.assertEquals("person", edge2.sourceLabel());
Assert.assertEquals("person", edge2.targetLabel());
Assert.assertEquals(ImmutableMap.of("date", 1476720000000L), edge2.properties());
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadEdge.
@Test
public void testReadEdge() {
String json = "{" + "\"id\": \"person:peter>created>>software:lop\"," + "\"label\": \"created\"," + "\"type\": \"edge\"," + "\"outV\": \"person:peter\"," + "\"inV\": \"software:lop\"," + "\"outVLabel\": \"person\"," + "\"inVLabel\": \"software\"," + "\"properties\": {" + "\"city\": \"Hongkong\"," + "\"date\": 1495036800000" + "}" + "}";
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());
Edge edge = result.readObject(Edge.class);
Assert.assertEquals("person:peter>created>>software:lop", edge.id());
Assert.assertEquals("created", edge.label());
Assert.assertEquals("person:peter", edge.sourceId());
Assert.assertEquals("software:lop", edge.targetId());
Assert.assertEquals("person", edge.sourceLabel());
Assert.assertEquals("software", edge.targetLabel());
Assert.assertEquals(ImmutableMap.of("city", "Hongkong", "date", 1495036800000L), edge.properties());
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadVertex.
@Test
public void testReadVertex() {
String json = "{" + "\"id\": \"person:marko\"," + "\"label\": \"person\"," + "\"type\": \"vertex\"," + "\"properties\": {" + "\"name\": \"marko\"" + "}" + "}";
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());
Vertex vertex = result.readObject(Vertex.class);
Assert.assertEquals("person:marko", vertex.id());
Assert.assertEquals("person", vertex.label());
Assert.assertEquals(ImmutableMap.of("name", "marko"), vertex.properties());
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadVertices.
@Test
public void testReadVertices() {
String json = "{\"vertices\": [" + "{" + "\"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\": 29" + "}" + "}" + "]}";
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<Vertex> vertices = result.readList("vertices", Vertex.class);
Assert.assertEquals(3, vertices.size());
Vertex vertex1 = vertices.get(0);
Vertex vertex2 = vertices.get(1);
Vertex vertex3 = vertices.get(2);
Assert.assertEquals("person:marko", vertex1.id());
Assert.assertEquals("person", vertex1.label());
Assert.assertEquals(ImmutableMap.of("name", "marko", "age", 29, "city", ImmutableList.of("Beijing", "Wuhan", "Beijing")), vertex1.properties());
Assert.assertEquals("software:lop", vertex2.id());
Assert.assertEquals("software", vertex2.label());
Assert.assertEquals(ImmutableMap.of("name", "lop", "lang", ImmutableList.of("java", "python", "c++"), "price", 328), vertex2.properties());
Assert.assertEquals("person:peter", vertex3.id());
Assert.assertEquals("person", vertex3.label());
Assert.assertEquals(ImmutableMap.of("name", "peter", "age", 29, "city", ImmutableList.of("Shanghai")), vertex3.properties());
}
use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadPropertyKey.
@Test
public void testReadPropertyKey() {
String json = "{" + "\"id\": 3," + "\"data_type\": \"INT\"," + "\"name\": \"id\"," + "\"cardinality\": \"SINGLE\"," + "\"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());
PropertyKey propertyKey = result.readObject(PropertyKey.class);
Assert.assertEquals("id", propertyKey.name());
Assert.assertEquals(DataType.INT, propertyKey.dataType());
Assert.assertEquals(Cardinality.SINGLE, propertyKey.cardinality());
Assert.assertEquals(Collections.emptySet(), propertyKey.properties());
}
Aggregations