Search in sources :

Example 1 with PostRevsDiffOptions

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

the class PostRevsDiffOptionsTest method testPostRevsDiffOptions.

@Test
public void testPostRevsDiffOptions() throws Throwable {
    PostRevsDiffOptions postRevsDiffOptionsModel = new PostRevsDiffOptions.Builder().db("testString").documentRevisions(new java.util.HashMap<String, List<String>>() {

        {
            put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
        }
    }).build();
    assertEquals(postRevsDiffOptionsModel.db(), "testString");
    assertEquals(postRevsDiffOptionsModel.documentRevisions(), new java.util.HashMap<String, List<String>>() {

        {
            put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
        }
    });
}
Also used : PostRevsDiffOptions(com.ibm.cloud.cloudant.v1.model.PostRevsDiffOptions) HashMap(java.util.HashMap) List(java.util.List) Test(org.testng.annotations.Test)

Example 2 with PostRevsDiffOptions

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

the class CloudantTest method testPostRevsDiffWOptions.

@Test
public void testPostRevsDiffWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"mapKey\": {\"missing\": [\"missing\"], \"possible_ancestors\": [\"possibleAncestors\"]}}";
    String postRevsDiffPath = "/testString/_revs_diff";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the PostRevsDiffOptions model
    PostRevsDiffOptions postRevsDiffOptionsModel = new PostRevsDiffOptions.Builder().db("testString").documentRevisions(new java.util.HashMap<String, List<String>>() {

        {
            put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
        }
    }).build();
    // Invoke operation with valid options model (positive test)
    Response<Map<String, RevsDiff>> response = cloudantService.postRevsDiff(postRevsDiffOptionsModel).execute();
    assertNotNull(response);
    Map<String, RevsDiff> 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, postRevsDiffPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) HashMap(java.util.HashMap) PostRevsDiffOptions(com.ibm.cloud.cloudant.v1.model.PostRevsDiffOptions) RevsDiff(com.ibm.cloud.cloudant.v1.model.RevsDiff) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with PostRevsDiffOptions

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

the class Cloudant method postRevsDiff.

/**
 * Query the document revisions and possible ancestors missing from the database.
 *
 * The replicator is the primary user of this operation. After receiving a set of new revision IDs from the source
 * database, the replicator sends this set to the destination database's `_revs_diff` to find out which of them
 * already exists there. It can then avoid fetching and sending already-known document bodies.
 *
 * @param postRevsDiffOptions the {@link PostRevsDiffOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Map}
 */
public ServiceCall<Map<String, RevsDiff>> postRevsDiff(PostRevsDiffOptions postRevsDiffOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postRevsDiffOptions, "postRevsDiffOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postRevsDiffOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_revs_diff", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postRevsDiff");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.bodyContent(com.ibm.cloud.sdk.core.util.GsonSingleton.getGsonWithoutPrettyPrinting().toJson(postRevsDiffOptions.documentRevisions()), "application/json");
    ResponseConverter<Map<String, RevsDiff>> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Map<String, RevsDiff>>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RevsDiff(com.ibm.cloud.cloudant.v1.model.RevsDiff) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)3 PostRevsDiffOptions (com.ibm.cloud.cloudant.v1.model.PostRevsDiffOptions)2 RevsDiff (com.ibm.cloud.cloudant.v1.model.RevsDiff)2 Map (java.util.Map)2 Test (org.testng.annotations.Test)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 List (java.util.List)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1