Search in sources :

Example 1 with BulkGetResult

use of com.ibm.cloud.cloudant.v1.model.BulkGetResult in project cloudant-java-sdk by IBM.

the class BulkGetResultTest method testBulkGetResult.

@Test
public void testBulkGetResult() throws Throwable {
    BulkGetResult bulkGetResultModel = new BulkGetResult();
    assertNull(bulkGetResultModel.getResults());
}
Also used : BulkGetResult(com.ibm.cloud.cloudant.v1.model.BulkGetResult) Test(org.testng.annotations.Test)

Example 2 with BulkGetResult

use of com.ibm.cloud.cloudant.v1.model.BulkGetResult in project cloudant-java-sdk by IBM.

the class CloudantTest method testPostBulkGetWOptions.

@Test
public void testPostBulkGetWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"results\": [{\"docs\": [{\"error\": {\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}, \"ok\": {\"_attachments\": {\"mapKey\": {\"content_type\": \"contentType\", \"data\": \"VGhpcyBpcyBhbiBlbmNvZGVkIGJ5dGUgYXJyYXku\", \"digest\": \"digest\", \"encoded_length\": 0, \"encoding\": \"encoding\", \"follows\": false, \"length\": 0, \"revpos\": 1, \"stub\": true}}, \"_conflicts\": [\"conflicts\"], \"_deleted\": false, \"_deleted_conflicts\": [\"deletedConflicts\"], \"_id\": \"id\", \"_local_seq\": \"localSeq\", \"_rev\": \"rev\", \"_revisions\": {\"ids\": [\"ids\"], \"start\": 1}, \"_revs_info\": [{\"rev\": \"rev\", \"status\": \"available\"}]}}], \"id\": \"id\"}]}";
    String postBulkGetPath = "/testString/_bulk_get";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the BulkGetQueryDocument model
    BulkGetQueryDocument bulkGetQueryDocumentModel = new BulkGetQueryDocument.Builder().attsSince(new java.util.ArrayList<String>(java.util.Arrays.asList("1-99b02e08da151943c2dcb40090160bb8"))).id("order00067").rev("3-917fa2381192822767f010b95b45325b").build();
    // Construct an instance of the PostBulkGetOptions model
    PostBulkGetOptions postBulkGetOptionsModel = new PostBulkGetOptions.Builder().db("testString").docs(new java.util.ArrayList<BulkGetQueryDocument>(java.util.Arrays.asList(bulkGetQueryDocumentModel))).attachments(false).attEncodingInfo(false).latest(false).revs(false).build();
    // Invoke operation with valid options model (positive test)
    Response<BulkGetResult> response = cloudantService.postBulkGet(postBulkGetOptionsModel).execute();
    assertNotNull(response);
    BulkGetResult 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);
    assertNotNull(query);
    // Get query params
    assertEquals(Boolean.valueOf(query.get("attachments")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("att_encoding_info")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("latest")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("revs")), Boolean.valueOf(false));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, postBulkGetPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) BulkGetQueryDocument(com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument) PostBulkGetOptions(com.ibm.cloud.cloudant.v1.model.PostBulkGetOptions) ArrayList(java.util.ArrayList) BulkGetResult(com.ibm.cloud.cloudant.v1.model.BulkGetResult) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with BulkGetResult

use of com.ibm.cloud.cloudant.v1.model.BulkGetResult in project cloudant-java-sdk by IBM.

the class Cloudant method postBulkGet.

/**
 * Bulk query revision information for multiple documents.
 *
 * Fetch specific revisions or revision histories for multiple documents in bulk as replicators do.
 *
 * @param postBulkGetOptions the {@link PostBulkGetOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link BulkGetResult}
 */
public ServiceCall<BulkGetResult> postBulkGet(PostBulkGetOptions postBulkGetOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postBulkGetOptions, "postBulkGetOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postBulkGetOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_bulk_get", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postBulkGet");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (postBulkGetOptions.attachments() != null) {
        builder.query("attachments", String.valueOf(postBulkGetOptions.attachments()));
    }
    if (postBulkGetOptions.attEncodingInfo() != null) {
        builder.query("att_encoding_info", String.valueOf(postBulkGetOptions.attEncodingInfo()));
    }
    if (postBulkGetOptions.latest() != null) {
        builder.query("latest", String.valueOf(postBulkGetOptions.latest()));
    }
    if (postBulkGetOptions.revs() != null) {
        builder.query("revs", String.valueOf(postBulkGetOptions.revs()));
    }
    final JsonObject contentJson = new JsonObject();
    contentJson.add("docs", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postBulkGetOptions.docs()));
    builder.bodyJson(contentJson);
    ResponseConverter<BulkGetResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<BulkGetResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) BulkGetResult(com.ibm.cloud.cloudant.v1.model.BulkGetResult)

Aggregations

BulkGetResult (com.ibm.cloud.cloudant.v1.model.BulkGetResult)3 Test (org.testng.annotations.Test)2 JsonObject (com.google.gson.JsonObject)1 BulkGetQueryDocument (com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument)1 PostBulkGetOptions (com.ibm.cloud.cloudant.v1.model.PostBulkGetOptions)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1