use of com.ibm.cloud.cloudant.v1.model.AllDocsQuery in project cloudant-java-sdk by IBM.
the class CloudantTest method testPostAllDocsQueriesAsStreamWOptions.
@Test
public void testPostAllDocsQueriesAsStreamWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"foo\": \"this is a mock response for JSON streaming\"}";
String postAllDocsQueriesAsStreamPath = "/testString/_all_docs/queries";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the AllDocsQuery model
AllDocsQuery allDocsQueryModel = new AllDocsQuery.Builder().attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(false).inclusiveEnd(true).limit(Long.valueOf("0")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").key("testString").keys(new java.util.ArrayList<String>(java.util.Arrays.asList("small-appliances:1000042", "small-appliances:1000043"))).startkey("testString").build();
// Construct an instance of the PostAllDocsQueriesOptions model
PostAllDocsQueriesOptions postAllDocsQueriesOptionsModel = new PostAllDocsQueriesOptions.Builder().db("testString").queries(new java.util.ArrayList<AllDocsQuery>(java.util.Arrays.asList(allDocsQueryModel))).build();
// Invoke operation with valid options model (positive test)
Response<InputStream> response = cloudantService.postAllDocsQueriesAsStream(postAllDocsQueriesOptionsModel).execute();
assertNotNull(response);
InputStream responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, postAllDocsQueriesAsStreamPath);
// Verify streamed JSON response
java.util.Scanner s = new java.util.Scanner(responseObj).useDelimiter("\\A");
String streamedResponseBody = s.hasNext() ? s.next() : "";
assertEquals(streamedResponseBody, mockResponseBody);
}
Aggregations