use of com.ibm.watson.discovery.v2.model.DeleteDocumentOptions in project cloudant-java-sdk by IBM.
the class CloudantTest method testDeleteDocumentWOptions.
@Test
public void testDeleteDocumentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
String deleteDocumentPath = "/testString/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().db("testString").docId("testString").ifMatch("testString").batch("ok").rev("testString").build();
// Invoke operation with valid options model (positive test)
Response<DocumentResult> response = cloudantService.deleteDocument(deleteDocumentOptionsModel).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("batch"), "ok");
assertEquals(query.get("rev"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, deleteDocumentPath);
}
use of com.ibm.watson.discovery.v2.model.DeleteDocumentOptions in project cloudant-java-sdk by IBM.
the class DeleteDocumentOptionsTest method testDeleteDocumentOptions.
@Test
public void testDeleteDocumentOptions() throws Throwable {
DeleteDocumentOptions deleteDocumentOptionsModel = new DeleteDocumentOptions.Builder().db("testString").docId("testString").ifMatch("testString").batch("ok").rev("testString").build();
assertEquals(deleteDocumentOptionsModel.db(), "testString");
assertEquals(deleteDocumentOptionsModel.docId(), "testString");
assertEquals(deleteDocumentOptionsModel.ifMatch(), "testString");
assertEquals(deleteDocumentOptionsModel.batch(), "ok");
assertEquals(deleteDocumentOptionsModel.rev(), "testString");
}
use of com.ibm.watson.discovery.v2.model.DeleteDocumentOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method deleteDocumentIsSuccessful.
@Test
public void deleteDocumentIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(deleteDocResp));
DeleteDocumentOptions deleteRequest = new DeleteDocumentOptions.Builder(environmentId, collectionId, documentId).build();
discoveryService.deleteDocument(deleteRequest).execute();
RecordedRequest request = server.takeRequest();
assertEquals(DOCS2_PATH, request.getPath());
assertEquals(DELETE, request.getMethod());
}
use of com.ibm.watson.discovery.v2.model.DeleteDocumentOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryV2Example method main.
public static void main(String[] args) throws IOException {
Authenticator authenticator = new BearerTokenAuthenticator("{bearer_token}");
Discovery service = new Discovery("2019-11-22", authenticator);
service.setServiceUrl("{url}");
// This example assumes you have a project and collection set up which can accept documents.
// Paste those
// IDs below.
String projectId = "";
String collectionId = "";
// Add a new document to our collection. Fill in the file path with the file you want to send.
InputStream file = new FileInputStream("");
AddDocumentOptions addDocumentOptions = new AddDocumentOptions.Builder().projectId(projectId).collectionId(collectionId).file(file).filename("example-file").build();
DocumentAccepted addResponse = service.addDocument(addDocumentOptions).execute().getResult();
String documentId = addResponse.getDocumentId();
// Query your collection with the new document inside.
QueryOptions queryOptions = new QueryOptions.Builder().projectId(projectId).addCollectionIds(collectionId).naturalLanguageQuery(// Feel free to replace this to query something different.
"Watson").build();
QueryResponse queryResponse = service.query(queryOptions).execute().getResult();
System.out.println(queryResponse.getMatchingResults() + " results were returned by the query!");
// See if the added document got returned by the query.
for (QueryResult result : queryResponse.getResults()) {
if (result.getDocumentId().equals(documentId)) {
System.out.println("Our new document matched the query!");
}
}
// Delete our uploaded document from the collection.
DeleteDocumentOptions deleteDocumentOptions = new DeleteDocumentOptions.Builder().projectId(projectId).collectionId(collectionId).documentId(documentId).build();
service.deleteDocument(deleteDocumentOptions).execute();
}
use of com.ibm.watson.discovery.v2.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());
}
Aggregations