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")));
}
});
}
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);
}
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);
}
Aggregations