use of com.ibm.cloud.cloudant.v1.model.Revisions in project cloudant-java-sdk by IBM.
the class CloudantTest method testPutReplicationDocumentWOptions.
@Test
public void testPutReplicationDocumentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
String putReplicationDocumentPath = "/_replicator/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the Attachment model
Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
// Construct an instance of the Revisions model
Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
// Construct an instance of the DocumentRevisionStatus model
DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
// Construct an instance of the ReplicationCreateTargetParameters model
ReplicationCreateTargetParameters replicationCreateTargetParametersModel = new ReplicationCreateTargetParameters.Builder().n(Long.valueOf("1")).partitioned(false).q(Long.valueOf("26")).build();
// Construct an instance of the ReplicationDatabaseAuthBasic model
ReplicationDatabaseAuthBasic replicationDatabaseAuthBasicModel = new ReplicationDatabaseAuthBasic.Builder().password("testString").username("testString").build();
// Construct an instance of the ReplicationDatabaseAuthIam model
ReplicationDatabaseAuthIam replicationDatabaseAuthIamModel = new ReplicationDatabaseAuthIam.Builder().apiKey("testString").build();
// Construct an instance of the ReplicationDatabaseAuth model
ReplicationDatabaseAuth replicationDatabaseAuthModel = new ReplicationDatabaseAuth.Builder().basic(replicationDatabaseAuthBasicModel).iam(replicationDatabaseAuthIamModel).build();
// Construct an instance of the ReplicationDatabase model
ReplicationDatabase replicationDatabaseModel = new ReplicationDatabase.Builder().auth(replicationDatabaseAuthModel).headers(new java.util.HashMap<String, String>() {
{
put("foo", "testString");
}
}).url("testString").build();
// Construct an instance of the UserContext model
UserContext userContextModel = new UserContext.Builder().db("testString").name("testString").roles(new java.util.ArrayList<String>(java.util.Arrays.asList("_reader"))).build();
// Construct an instance of the ReplicationDocument model
ReplicationDocument replicationDocumentModel = new ReplicationDocument.Builder().attachments(new java.util.HashMap<String, Attachment>() {
{
put("foo", attachmentModel);
}
}).conflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).deleted(true).deletedConflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).id("testString").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).cancel(true).checkpointInterval(Long.valueOf("0")).connectionTimeout(Long.valueOf("0")).continuous(false).createTarget(false).createTargetParams(replicationCreateTargetParametersModel).docIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).filter("testString").httpConnections(Long.valueOf("1")).queryParams(new java.util.HashMap<String, String>() {
{
put("foo", "testString");
}
}).retriesPerRequest(Long.valueOf("0")).selector(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).sinceSeq("testString").socketOptions("testString").source(replicationDatabaseModel).sourceProxy("testString").target(replicationDatabaseModel).targetProxy("testString").useCheckpoints(true).userCtx(userContextModel).workerBatchSize(Long.valueOf("1")).workerProcesses(Long.valueOf("1")).add("foo", "testString").build();
// Construct an instance of the PutReplicationDocumentOptions model
PutReplicationDocumentOptions putReplicationDocumentOptionsModel = new PutReplicationDocumentOptions.Builder().docId("testString").replicationDocument(replicationDocumentModel).ifMatch("testString").batch("ok").newEdits(false).rev("testString").build();
// Invoke operation with valid options model (positive test)
Response<DocumentResult> response = cloudantService.putReplicationDocument(putReplicationDocumentOptionsModel).execute();
assertNotNull(response);
DocumentResult responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "PUT");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("batch"), "ok");
assertEquals(Boolean.valueOf(query.get("new_edits")), Boolean.valueOf(false));
assertEquals(query.get("rev"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, putReplicationDocumentPath);
}
use of com.ibm.cloud.cloudant.v1.model.Revisions 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);
}
use of com.ibm.cloud.cloudant.v1.model.Revisions in project cloudant-java-sdk by IBM.
the class BulkDocsTest method testBulkDocs.
@Test
public void testBulkDocs() throws Throwable {
Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
assertEquals(attachmentModel.contentType(), "testString");
assertEquals(attachmentModel.data(), TestUtilities.createMockByteArray("This is a mock byte array value."));
assertEquals(attachmentModel.digest(), "testString");
assertEquals(attachmentModel.encodedLength(), Long.valueOf("0"));
assertEquals(attachmentModel.encoding(), "testString");
assertEquals(attachmentModel.follows(), Boolean.valueOf(true));
assertEquals(attachmentModel.length(), Long.valueOf("0"));
assertEquals(attachmentModel.revpos(), Long.valueOf("1"));
assertEquals(attachmentModel.stub(), Boolean.valueOf(true));
Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
assertEquals(revisionsModel.ids(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(revisionsModel.start(), Long.valueOf("1"));
DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
assertEquals(documentRevisionStatusModel.rev(), "testString");
assertEquals(documentRevisionStatusModel.status(), "available");
Document documentModel = new Document.Builder().attachments(new java.util.HashMap<String, Attachment>() {
{
put("foo", attachmentModel);
}
}).conflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).deleted(true).deletedConflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).id("testString").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).add("foo", "testString").build();
assertEquals(documentModel.getAttachments(), new java.util.HashMap<String, Attachment>() {
{
put("foo", attachmentModel);
}
});
assertEquals(documentModel.getConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(documentModel.isDeleted(), Boolean.valueOf(true));
assertEquals(documentModel.getDeletedConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(documentModel.getId(), "testString");
assertEquals(documentModel.getLocalSeq(), "testString");
assertEquals(documentModel.getRev(), "testString");
assertEquals(documentModel.getRevisions(), revisionsModel);
assertEquals(documentModel.getRevsInfo(), new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel)));
assertEquals(documentModel.get("foo"), "testString");
BulkDocs bulkDocsModel = new BulkDocs.Builder().docs(new java.util.ArrayList<Document>(java.util.Arrays.asList(documentModel))).newEdits(true).build();
assertEquals(bulkDocsModel.docs(), new java.util.ArrayList<Document>(java.util.Arrays.asList(documentModel)));
assertEquals(bulkDocsModel.newEdits(), Boolean.valueOf(true));
String json = TestUtilities.serialize(bulkDocsModel);
BulkDocs bulkDocsModelNew = TestUtilities.deserialize(json, BulkDocs.class);
assertTrue(bulkDocsModelNew instanceof BulkDocs);
assertEquals(bulkDocsModelNew.newEdits(), Boolean.valueOf(true));
}
use of com.ibm.cloud.cloudant.v1.model.Revisions 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