use of com.ibm.cloud.cloudant.v1.model.GetDocumentOptions in project cloudant-java-sdk by IBM.
the class GetDocumentOptionsTest method testGetDocumentOptions.
@Test
public void testGetDocumentOptions() throws Throwable {
GetDocumentOptions getDocumentOptionsModel = new GetDocumentOptions.Builder().db("testString").docId("testString").ifNoneMatch("testString").attachments(false).attEncodingInfo(false).conflicts(false).deletedConflicts(false).latest(false).localSeq(false).meta(false).rev("testString").revs(false).revsInfo(false).build();
assertEquals(getDocumentOptionsModel.db(), "testString");
assertEquals(getDocumentOptionsModel.docId(), "testString");
assertEquals(getDocumentOptionsModel.ifNoneMatch(), "testString");
assertEquals(getDocumentOptionsModel.attachments(), Boolean.valueOf(false));
assertEquals(getDocumentOptionsModel.attEncodingInfo(), Boolean.valueOf(false));
assertEquals(getDocumentOptionsModel.conflicts(), Boolean.valueOf(false));
assertEquals(getDocumentOptionsModel.deletedConflicts(), Boolean.valueOf(false));
assertEquals(getDocumentOptionsModel.latest(), Boolean.valueOf(false));
assertEquals(getDocumentOptionsModel.localSeq(), Boolean.valueOf(false));
assertEquals(getDocumentOptionsModel.meta(), Boolean.valueOf(false));
assertEquals(getDocumentOptionsModel.rev(), "testString");
assertEquals(getDocumentOptionsModel.revs(), Boolean.valueOf(false));
assertEquals(getDocumentOptionsModel.revsInfo(), Boolean.valueOf(false));
}
use of com.ibm.cloud.cloudant.v1.model.GetDocumentOptions in project cloudant-java-sdk by IBM.
the class DeleteDoc method main.
public static void main(String[] args) {
// 1. Create a client with `CLOUDANT` default service name ============
Cloudant client = Cloudant.newInstance();
// 2. Delete the document =============================================
// Set the options to get the document out of the database if it exists
String exampleDbName = "orders";
String exampleDocId = "example";
GetDocumentOptions documentInfoOptions = new GetDocumentOptions.Builder().db(exampleDbName).docId(exampleDocId).build();
try {
// Try to get the document if it previously existed in the database
Document document = client.getDocument(documentInfoOptions).execute().getResult();
// Delete the document from the database
DeleteDocumentOptions deleteDocumentOptions = new DeleteDocumentOptions.Builder().db(exampleDbName).docId(// docId is required for DELETE
exampleDocId).rev(// rev is required for DELETE
document.getRev()).build();
DocumentResult deleteDocumentResponse = client.deleteDocument(deleteDocumentOptions).execute().getResult();
if (deleteDocumentResponse.isOk()) {
System.out.println("You have deleted the document.");
}
} catch (NotFoundException nfe) {
System.out.println("Cannot delete document because " + "either \"orders\" database or the \"example\" " + "document was not found.");
}
}
use of com.ibm.cloud.cloudant.v1.model.GetDocumentOptions in project cloudant-java-sdk by IBM.
the class CloudantTest method testGetDocumentWOptions.
@Test
public void testGetDocumentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"_attachments\": {\"mapKey\": {\"content_type\": \"contentType\", \"data\": \"VGhpcyBpcyBhbiBlbmNvZGVkIGJ5dGUgYXJyYXku\", \"digest\": \"digest\", \"encoded_length\": 0, \"encoding\": \"encoding\", \"follows\": false, \"length\": 0, \"revpos\": 1, \"stub\": true}}, \"_conflicts\": [\"conflicts\"], \"_deleted\": false, \"_deleted_conflicts\": [\"deletedConflicts\"], \"_id\": \"id\", \"_local_seq\": \"localSeq\", \"_rev\": \"rev\", \"_revisions\": {\"ids\": [\"ids\"], \"start\": 1}, \"_revs_info\": [{\"rev\": \"rev\", \"status\": \"available\"}]}";
String getDocumentPath = "/testString/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetDocumentOptions model
GetDocumentOptions getDocumentOptionsModel = new GetDocumentOptions.Builder().db("testString").docId("testString").ifNoneMatch("testString").attachments(false).attEncodingInfo(false).conflicts(false).deletedConflicts(false).latest(false).localSeq(false).meta(false).rev("testString").revs(false).revsInfo(false).build();
// Invoke operation with valid options model (positive test)
Response<Document> response = cloudantService.getDocument(getDocumentOptionsModel).execute();
assertNotNull(response);
Document responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(Boolean.valueOf(query.get("attachments")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("att_encoding_info")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("conflicts")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("deleted_conflicts")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("latest")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("local_seq")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("meta")), Boolean.valueOf(false));
assertEquals(query.get("rev"), "testString");
assertEquals(Boolean.valueOf(query.get("revs")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("revs_info")), Boolean.valueOf(false));
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getDocumentPath);
}
use of com.ibm.cloud.cloudant.v1.model.GetDocumentOptions in project cloudant-java-sdk by IBM.
the class CloudantTest method testGetDocumentAsMixedWOptions.
@Test
public void testGetDocumentAsMixedWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "This is a mock binary response.";
String getDocumentAsMixedPath = "/testString/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "multipart/mixed").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetDocumentOptions model
GetDocumentOptions getDocumentOptionsModel = new GetDocumentOptions.Builder().db("testString").docId("testString").ifNoneMatch("testString").attachments(false).attEncodingInfo(false).conflicts(false).deletedConflicts(false).latest(false).localSeq(false).meta(false).rev("testString").revs(false).revsInfo(false).build();
// Invoke operation with valid options model (positive test)
Response<InputStream> response = cloudantService.getDocumentAsMixed(getDocumentOptionsModel).execute();
assertNotNull(response);
InputStream responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(Boolean.valueOf(query.get("attachments")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("att_encoding_info")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("conflicts")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("deleted_conflicts")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("latest")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("local_seq")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("meta")), Boolean.valueOf(false));
assertEquals(query.get("rev"), "testString");
assertEquals(Boolean.valueOf(query.get("revs")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("revs_info")), Boolean.valueOf(false));
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getDocumentAsMixedPath);
}
Aggregations