use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.
the class PostDocumentOptionsTest method testPostDocumentOptions.
@Test
public void testPostDocumentOptions() 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");
PostDocumentOptions postDocumentOptionsModel = new PostDocumentOptions.Builder().db("testString").document(documentModel).body(TestUtilities.createMockStream("This is a mock file.")).contentType("application/json").batch("ok").build();
assertEquals(postDocumentOptionsModel.db(), "testString");
assertEquals(postDocumentOptionsModel.document(), documentModel);
assertEquals(IOUtils.toString(postDocumentOptionsModel.body()), IOUtils.toString(TestUtilities.createMockStream("This is a mock file.")));
assertEquals(postDocumentOptionsModel.contentType(), "application/json");
assertEquals(postDocumentOptionsModel.batch(), "ok");
}
use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.
the class PostPartitionSearchOptionsTest method testPostPartitionSearchOptions.
@Test
public void testPostPartitionSearchOptions() throws Throwable {
PostPartitionSearchOptions postPartitionSearchOptionsModel = new PostPartitionSearchOptions.Builder().db("testString").partitionKey("testString").ddoc("testString").index("testString").query("testString").bookmark("testString").highlightFields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).highlightNumber(Long.valueOf("1")).highlightPostTag("</em>").highlightPreTag("<em>").highlightSize(Long.valueOf("1")).includeDocs(false).includeFields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).limit(Long.valueOf("0")).sort(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).stale("ok").build();
assertEquals(postPartitionSearchOptionsModel.db(), "testString");
assertEquals(postPartitionSearchOptionsModel.partitionKey(), "testString");
assertEquals(postPartitionSearchOptionsModel.ddoc(), "testString");
assertEquals(postPartitionSearchOptionsModel.index(), "testString");
assertEquals(postPartitionSearchOptionsModel.query(), "testString");
assertEquals(postPartitionSearchOptionsModel.bookmark(), "testString");
assertEquals(postPartitionSearchOptionsModel.highlightFields(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(postPartitionSearchOptionsModel.highlightNumber(), Long.valueOf("1"));
assertEquals(postPartitionSearchOptionsModel.highlightPostTag(), "</em>");
assertEquals(postPartitionSearchOptionsModel.highlightPreTag(), "<em>");
assertEquals(postPartitionSearchOptionsModel.highlightSize(), Long.valueOf("1"));
assertEquals(postPartitionSearchOptionsModel.includeDocs(), Boolean.valueOf(false));
assertEquals(postPartitionSearchOptionsModel.includeFields(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(postPartitionSearchOptionsModel.limit(), Long.valueOf("0"));
assertEquals(postPartitionSearchOptionsModel.sort(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(postPartitionSearchOptionsModel.stale(), "ok");
}
use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.
the class GetGeoOptionsTest method testGetGeoOptions.
@Test
public void testGetGeoOptions() throws Throwable {
GetGeoOptions getGeoOptionsModel = new GetGeoOptions.Builder().db("testString").ddoc("testString").index("testString").bbox("testString").bookmark("testString").format("view").g("testString").includeDocs(false).lat(Double.valueOf("-90")).limit(Long.valueOf("0")).lon(Double.valueOf("-180")).nearest(false).radius(Double.valueOf("0")).rangex(Double.valueOf("0")).rangey(Double.valueOf("0")).relation("intersects").skip(Long.valueOf("0")).stale("ok").build();
assertEquals(getGeoOptionsModel.db(), "testString");
assertEquals(getGeoOptionsModel.ddoc(), "testString");
assertEquals(getGeoOptionsModel.index(), "testString");
assertEquals(getGeoOptionsModel.bbox(), "testString");
assertEquals(getGeoOptionsModel.bookmark(), "testString");
assertEquals(getGeoOptionsModel.format(), "view");
assertEquals(getGeoOptionsModel.g(), "testString");
assertEquals(getGeoOptionsModel.includeDocs(), Boolean.valueOf(false));
assertEquals(getGeoOptionsModel.lat(), Double.valueOf("-90"));
assertEquals(getGeoOptionsModel.limit(), Long.valueOf("0"));
assertEquals(getGeoOptionsModel.lon(), Double.valueOf("-180"));
assertEquals(getGeoOptionsModel.nearest(), Boolean.valueOf(false));
assertEquals(getGeoOptionsModel.radius(), Double.valueOf("0"));
assertEquals(getGeoOptionsModel.rangex(), Double.valueOf("0"));
assertEquals(getGeoOptionsModel.rangey(), Double.valueOf("0"));
assertEquals(getGeoOptionsModel.relation(), "intersects");
assertEquals(getGeoOptionsModel.skip(), Long.valueOf("0"));
assertEquals(getGeoOptionsModel.stale(), "ok");
}
use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.
the class CreateDbAndDoc method main.
public static void main(String[] args) {
// 1. Create a client with `CLOUDANT` default service name ============
Cloudant client = Cloudant.newInstance();
// 2. Create a database ===============================================
// Create a database object with "orders" id
String exampleDbName = "orders";
PutDatabaseOptions putDbOptions = new PutDatabaseOptions.Builder().db(exampleDbName).build();
// Try to create database if it doesn't exist
try {
Ok putDatabaseResult = client.putDatabase(putDbOptions).execute().getResult();
if (putDatabaseResult.isOk()) {
System.out.println("\"" + exampleDbName + "\" database created.");
}
} catch (ServiceResponseException sre) {
if (sre.getStatusCode() == 412)
System.out.println("Cannot create \"" + exampleDbName + "\" database, it already exists.");
}
// 3. Create a document ===============================================
// Create a document object with "example" id
String exampleDocId = "example";
Document exampleDocument = new Document();
// Setting id for the document is optional when "postDocument" method is used for CREATE.
// When id is not provided the server will generate one for your document.
exampleDocument.setId(exampleDocId);
// Add "name" and "joined" fields to the document
exampleDocument.put("name", "Bob Smith");
exampleDocument.put("joined", "2019-01-24T10:42:59.000Z");
// Save the document in the database with "postDocument" method
PostDocumentOptions createDocumentOptions = new PostDocumentOptions.Builder().db(exampleDbName).document(exampleDocument).build();
DocumentResult createDocumentResponse = client.postDocument(createDocumentOptions).execute().getResult();
// ====================================================================
// Note: saving the document can also be done with the "putDocument"
// method. In this case `docId` is required for a CREATE operation:
/*
PutDocumentOptions createDocumentOptions =
new PutDocumentOptions.Builder()
.db(exampleDbName)
.docId(exampleDocId)
.document(exampleDocument)
.build();
DocumentResult createDocumentResponse = client
.putDocument(createDocumentOptions)
.execute()
.getResult();
*/
// ====================================================================
// Keeping track of the revision number of the document object
// is necessary for further UPDATE/DELETE operations:
exampleDocument.setRev(createDocumentResponse.getRev());
System.out.println("You have created the document:\n" + exampleDocument);
}
use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.
the class CloudantTest method testDeleteAttachmentWOptions.
@Test
public void testDeleteAttachmentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
String deleteAttachmentPath = "/testString/testString/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the DeleteAttachmentOptions model
DeleteAttachmentOptions deleteAttachmentOptionsModel = new DeleteAttachmentOptions.Builder().db("testString").docId("testString").attachmentName("testString").ifMatch("testString").rev("testString").batch("ok").build();
// Invoke operation with valid options model (positive test)
Response<DocumentResult> response = cloudantService.deleteAttachment(deleteAttachmentOptionsModel).execute();
assertNotNull(response);
DocumentResult responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "DELETE");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("rev"), "testString");
assertEquals(query.get("batch"), "ok");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, deleteAttachmentPath);
}
Aggregations