@Test
public void getRecord() throws Exception {
// GIVEN a fake remote kinto url
String remote = "https://fake.kinto.url";
// AND expected headers
Map<String, List<String>> expectedHeaders = new HashMap<>(defaultHeaders);
// AND a kintoClient
KintoClient kintoClient = spy(new KintoClient(remote));
// AND a mocked kintoClient
doAnswer(new Answer<JSONObject>() {
public JSONObject answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
GetRequest getRequest = (GetRequest)args[0];
// THEN the correct endpoint is called
assertThat(
getRequest.getUrl(),
is(remote + "/buckets/bucketName/collections/collectionName/records/recordId")
);
// AND headers are corrects
assertThat(getRequest.getHeaders(), is(expectedHeaders));
// AND the get method is used
assertThat(getRequest.getHttpMethod(), is(HttpMethod.GET));
return new JSONObject("{}");
}
})
.when(kintoClient)
.execute(any(GetRequest.class));
// WHEN calling bucket.collection.listRecords
JSONObject jsonObject = kintoClient
.bucket("bucketName")
.collection("collectionName")
.getRecord("recordId");
// THEN check if the answer is correctly called by checking the result
assertThat(jsonObject.toString(), is("{}"));
}
CollectionTest.java 文件源码
java
阅读 30
收藏 0
点赞 0
评论 0
项目:kinto-http-java
作者:
评论列表
文章目录