Search in sources :

Example 66 with RestResult

use of com.baidu.hugegraph.rest.RestResult in project hugegraph-common by hugegraph.

the class RestClientTest method testPostHttpsWithTokenAndAllParams.

@Test
public void testPostHttpsWithTokenAndAllParams() {
    String trustStoreFile = "src/test/resources/cacerts.jks";
    String trustStorePassword = "changeit";
    RestClient client = new RestClientImpl("/test", "token", 1000, 10, 5, trustStoreFile, trustStorePassword, 200);
    RestResult restResult = client.post("path", "body");
    Assert.assertEquals(200, restResult.status());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) AbstractRestClient(com.baidu.hugegraph.rest.AbstractRestClient) RestClient(com.baidu.hugegraph.rest.RestClient) Test(org.junit.Test)

Example 67 with RestResult

use of com.baidu.hugegraph.rest.RestResult in project hugegraph-common by hugegraph.

the class RestResultTest method newRestResult.

private static RestResult newRestResult(int status, String content, MultivaluedMap<String, Object> h) {
    Response response = Mockito.mock(Response.class);
    Mockito.when(response.getStatus()).thenReturn(status);
    Mockito.when(response.getHeaders()).thenReturn(h);
    Mockito.when(response.readEntity(String.class)).thenReturn(content);
    return new RestResult(response);
}
Also used : Response(jakarta.ws.rs.core.Response) RestResult(com.baidu.hugegraph.rest.RestResult)

Example 68 with RestResult

use of com.baidu.hugegraph.rest.RestResult in project hugegraph-common by hugegraph.

the class RestResultTest method testContentList.

@Test
public void testContentList() {
    String content = "{\"names\": [\"marko\", \"josh\", \"lop\"]}";
    RestResult result = newRestResult(200, content);
    Assert.assertEquals(200, result.status());
    Assert.assertEquals(content, result.content());
    Assert.assertEquals(ImmutableList.of("marko", "josh", "lop"), result.readList("names", String.class));
    content = "[\"marko\", \"josh\", \"lop\"]";
    result = newRestResult(200, content);
    Assert.assertEquals(200, result.status());
    Assert.assertEquals(content, result.content());
    Assert.assertEquals(ImmutableList.of("marko", "josh", "lop"), result.readList(String.class));
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) Test(org.junit.Test)

Example 69 with RestResult

use of com.baidu.hugegraph.rest.RestResult in project hugegraph-common by hugegraph.

the class RestResultTest method testContentListWithException.

@Test
public void testContentListWithException() {
    String content = "{\"names\": [\"marko\", \"josh\", \"lop\"]}";
    RestResult result = newRestResult(200, content);
    Assert.assertEquals(200, result.status());
    Assert.assertEquals(content, result.content());
    Assert.assertThrows(SerializeException.class, () -> {
        result.readList("unexitsed key", String.class);
    });
    content = "{\"names\": [marko, josh, \"lop\"]}";
    RestResult result2 = newRestResult(200, content);
    Assert.assertEquals(200, result2.status());
    Assert.assertEquals(content, result2.content());
    Assert.assertThrows(SerializeException.class, () -> {
        result2.readList("names", String.class);
    });
    content = "[marko, josh, \"lop\"]";
    RestResult result3 = newRestResult(200, content);
    Assert.assertEquals(200, result3.status());
    Assert.assertEquals(content, result3.content());
    Assert.assertThrows(SerializeException.class, () -> {
        result3.readList(String.class);
    });
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) Test(org.junit.Test)

Example 70 with RestResult

use of com.baidu.hugegraph.rest.RestResult in project hugegraph-common by hugegraph.

the class RestResultTest method testHeaders.

@Test
public void testHeaders() {
    MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
    headers.add("key1", "value1-1");
    headers.add("key1", "value1-2");
    headers.add("key2", "value2");
    RestResult result = newRestResult(200, headers);
    Assert.assertEquals(200, result.status());
    Assert.assertEquals(headers, result.headers());
}
Also used : MultivaluedHashMap(jakarta.ws.rs.core.MultivaluedHashMap) 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