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());
}
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);
}
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));
}
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);
});
}
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());
}
Aggregations