use of com.ibm.cloud.cloudant.v1.model.BulkDocs in project cloudant-java-sdk by IBM.
the class CloudantTest method testPostBulkDocsWOptions.
@Test
public void testPostBulkDocsWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "[{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}]";
String postBulkDocsPath = "/testString/_bulk_docs";
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 Document model
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();
// Construct an instance of the BulkDocs model
BulkDocs bulkDocsModel = new BulkDocs.Builder().docs(new java.util.ArrayList<Document>(java.util.Arrays.asList(documentModel))).newEdits(true).build();
// Construct an instance of the PostBulkDocsOptions model
PostBulkDocsOptions postBulkDocsOptionsModel = new PostBulkDocsOptions.Builder().db("testString").bulkDocs(bulkDocsModel).build();
// Invoke operation with valid options model (positive test)
Response<List<DocumentResult>> response = cloudantService.postBulkDocs(postBulkDocsOptionsModel).execute();
assertNotNull(response);
List<DocumentResult> 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, postBulkDocsPath);
}
use of com.ibm.cloud.cloudant.v1.model.BulkDocs in project cloudant-java-sdk by IBM.
the class PostBulkDocsOptionsTest method testPostBulkDocsOptions.
@Test
public void testPostBulkDocsOptions() 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));
PostBulkDocsOptions postBulkDocsOptionsModel = new PostBulkDocsOptions.Builder().db("testString").bulkDocs(bulkDocsModel).body(TestUtilities.createMockStream("This is a mock file.")).build();
assertEquals(postBulkDocsOptionsModel.db(), "testString");
assertEquals(postBulkDocsOptionsModel.bulkDocs(), bulkDocsModel);
assertEquals(IOUtils.toString(postBulkDocsOptionsModel.body()), IOUtils.toString(TestUtilities.createMockStream("This is a mock file.")));
}
use of com.ibm.cloud.cloudant.v1.model.BulkDocs 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));
}
Aggregations