Search in sources :

Example 1 with RevsDiff

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

the class RevsDiffTest method testRevsDiff.

@Test
public void testRevsDiff() throws Throwable {
    RevsDiff revsDiffModel = new RevsDiff();
    assertNull(revsDiffModel.getMissing());
    assertNull(revsDiffModel.getPossibleAncestors());
}
Also used : RevsDiff(com.ibm.cloud.cloudant.v1.model.RevsDiff) Test(org.testng.annotations.Test)

Example 2 with RevsDiff

use of com.ibm.cloud.cloudant.v1.model.RevsDiff 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 RevsDiff

use of com.ibm.cloud.cloudant.v1.model.RevsDiff 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

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