Search in sources :

Example 76 with RestResult

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());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 77 with RestResult

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());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 78 with RestResult

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());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) RestResult(com.baidu.hugegraph.rest.RestResult) Test(org.junit.Test)

Example 79 with RestResult

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());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) RestResult(com.baidu.hugegraph.rest.RestResult) Test(org.junit.Test)

Example 80 with RestResult

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());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) PropertyKey(com.baidu.hugegraph.structure.schema.PropertyKey) Test(org.junit.Test)

Aggregations

RestResult (com.baidu.hugegraph.rest.RestResult)132 Test (org.junit.Test)44 LinkedHashMap (java.util.LinkedHashMap)23 AbstractRestClient (com.baidu.hugegraph.rest.AbstractRestClient)19 RestClient (com.baidu.hugegraph.rest.RestClient)19 MultivaluedHashMap (jakarta.ws.rs.core.MultivaluedHashMap)12 Response (com.baidu.hugegraph.structure.gremlin.Response)6 Result (com.baidu.hugegraph.structure.gremlin.Result)6 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)6 Edge (com.baidu.hugegraph.structure.graph.Edge)5 Vertex (com.baidu.hugegraph.structure.graph.Vertex)5 Map (java.util.Map)5 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)4 InvalidResponseException (com.baidu.hugegraph.exception.InvalidResponseException)3 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)3 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)3 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)3 ArrayList (java.util.ArrayList)3 NotAllCreatedException (com.baidu.hugegraph.exception.NotAllCreatedException)2 Project (com.baidu.hugegraph.structure.auth.Project)2