Search in sources :

Example 6 with AllDocsQuery

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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) PostAllDocsQueriesOptions(com.ibm.cloud.cloudant.v1.model.PostAllDocsQueriesOptions) AllDocsQuery(com.ibm.cloud.cloudant.v1.model.AllDocsQuery) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

AllDocsQuery (com.ibm.cloud.cloudant.v1.model.AllDocsQuery)6 Test (org.testng.annotations.Test)6 PostAllDocsQueriesOptions (com.ibm.cloud.cloudant.v1.model.PostAllDocsQueriesOptions)3 ArrayList (java.util.ArrayList)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 AllDocsQueriesResult (com.ibm.cloud.cloudant.v1.model.AllDocsQueriesResult)2 PostDesignDocsQueriesOptions (com.ibm.cloud.cloudant.v1.model.PostDesignDocsQueriesOptions)2 InputStream (java.io.InputStream)1