use of com.ibm.cloud.cloudant.v1.model.DeleteDocumentOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method deleteDocumentIsSuccessful.
/**
* Delete document is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void deleteDocumentIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(deleteDocResp));
DeleteDocumentOptions deleteRequest = new DeleteDocumentOptions.Builder(environmentId, collectionId, documentId).build();
DeleteDocumentResponse response = discoveryService.deleteDocument(deleteRequest).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(DOCS2_PATH, request.getPath());
assertEquals(DELETE, request.getMethod());
assertEquals(deleteDocResp.getDocumentId(), response.getDocumentId());
assertEquals(deleteDocResp.getStatus(), response.getStatus());
}
use of com.ibm.cloud.cloudant.v1.model.DeleteDocumentOptions in project knative-eventing-java-app by IBM.
the class CloudEventStoreCloudant method removeAllEvents.
@Override
public void removeAllEvents() throws Exception {
try {
PostAllDocsOptions docsOptions = new PostAllDocsOptions.Builder().db(this.dbName).includeDocs(true).build();
AllDocsResult allDocResults = this.client.postAllDocs(docsOptions).execute().getResult();
for (DocsResultRow docResult : allDocResults.getRows()) {
Document document = docResult.getDoc();
DeleteDocumentOptions deleteDocumentOptions = new DeleteDocumentOptions.Builder().db(this.dbName).docId(document.getId()).rev(document.getRev()).build();
DocumentResult deleteDocumentResponse = client.deleteDocument(deleteDocumentOptions).execute().getResult();
if (!deleteDocumentResponse.isOk()) {
logger.info("Could not delete a document.");
}
}
} catch (NotFoundException e) {
String errMsg = "Unable to retrieve all documents from Cloudant";
logger.error(errMsg, e);
throw new Exception(errMsg, e);
}
}
use of com.ibm.cloud.cloudant.v1.model.DeleteDocumentOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method deleteDocumentIsSuccessful.
@Test
public void deleteDocumentIsSuccessful() {
Collection collection = createTestCollection();
String collectionId = collection.getCollectionId();
DocumentAccepted documentAccepted = createTestDocument("test_document", collectionId);
DeleteDocumentOptions deleteOptions = new DeleteDocumentOptions.Builder(environmentId, collectionId, documentAccepted.getDocumentId()).build();
discovery.deleteDocument(deleteOptions).execute();
}
use of com.ibm.cloud.cloudant.v1.model.DeleteDocumentOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testDeleteDocumentWOptions.
@Test
public void testDeleteDocumentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"document_id\": \"documentId\", \"status\": \"deleted\"}";
String deleteDocumentPath = "/v2/projects/testString/collections/testString/documents/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the DeleteDocumentOptions model
DeleteDocumentOptions deleteDocumentOptionsModel = new DeleteDocumentOptions.Builder().projectId("testString").collectionId("testString").documentId("testString").xWatsonDiscoveryForce(false).build();
// Invoke operation with valid options model (positive test)
Response<DeleteDocumentResponse> response = discoveryService.deleteDocument(deleteDocumentOptionsModel).execute();
assertNotNull(response);
DeleteDocumentResponse 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("version"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, deleteDocumentPath);
}
use of com.ibm.cloud.cloudant.v1.model.DeleteDocumentOptions in project java-sdk by watson-developer-cloud.
the class LanguageTranslatorTest method testDeleteDocumentWOptions.
// Test the deleteDocument operation with a valid options model parameter
@Test
public void testDeleteDocumentWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "";
String deleteDocumentPath = "/v3/documents/testString";
server.enqueue(new MockResponse().setResponseCode(204).setBody(mockResponseBody));
// Construct an instance of the DeleteDocumentOptions model
DeleteDocumentOptions deleteDocumentOptionsModel = new DeleteDocumentOptions.Builder().documentId("testString").build();
// Invoke deleteDocument() with a valid options model and verify the result
Response<Void> response = languageTranslatorService.deleteDocument(deleteDocumentOptionsModel).execute();
assertNotNull(response);
Void responseObj = response.getResult();
assertNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "DELETE");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, deleteDocumentPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "2018-05-01");
}
Aggregations