Search in sources :

Example 51 with RestResult

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

Example 52 with RestResult

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

Example 53 with RestResult

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

Example 54 with RestResult

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

Example 55 with RestResult

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);
}
Also used : Response(com.baidu.hugegraph.structure.gremlin.Response) RestResult(com.baidu.hugegraph.rest.RestResult) Result(com.baidu.hugegraph.structure.gremlin.Result) RestResult(com.baidu.hugegraph.rest.RestResult) 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