use of com.ibm.cloud.cloudant.v1.model.DeleteDesignDocumentOptions in project cloudant-java-sdk by IBM.
the class Cloudant method deleteDesignDocument.
/**
* Delete a design document.
*
* Marks the specified design document as deleted by adding a `_deleted` field with the value `true`. Documents with
* this field are not returned with requests but stay in the database. You must supply the current (latest) revision,
* either by using the `rev` parameter or by using the `If-Match` header to specify the revision.
*
* @param deleteDesignDocumentOptions the {@link DeleteDesignDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> deleteDesignDocument(DeleteDesignDocumentOptions deleteDesignDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteDesignDocumentOptions, "deleteDesignDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", deleteDesignDocumentOptions.db());
pathParamsMap.put("ddoc", deleteDesignDocumentOptions.ddoc());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteDesignDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (deleteDesignDocumentOptions.ifMatch() != null) {
builder.header("If-Match", deleteDesignDocumentOptions.ifMatch());
}
if (deleteDesignDocumentOptions.batch() != null) {
builder.query("batch", String.valueOf(deleteDesignDocumentOptions.batch()));
}
if (deleteDesignDocumentOptions.rev() != null) {
builder.query("rev", String.valueOf(deleteDesignDocumentOptions.rev()));
}
ResponseConverter<DocumentResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DocumentResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.DeleteDesignDocumentOptions in project cloudant-java-sdk by IBM.
the class CloudantTest method testDeleteDesignDocumentWOptions.
@Test
public void testDeleteDesignDocumentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
String deleteDesignDocumentPath = "/testString/_design/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the DeleteDesignDocumentOptions model
DeleteDesignDocumentOptions deleteDesignDocumentOptionsModel = new DeleteDesignDocumentOptions.Builder().db("testString").ddoc("testString").ifMatch("testString").batch("ok").rev("testString").build();
// Invoke operation with valid options model (positive test)
Response<DocumentResult> response = cloudantService.deleteDesignDocument(deleteDesignDocumentOptionsModel).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, deleteDesignDocumentPath);
}
use of com.ibm.cloud.cloudant.v1.model.DeleteDesignDocumentOptions in project cloudant-java-sdk by IBM.
the class DeleteDesignDocumentOptionsTest method testDeleteDesignDocumentOptions.
@Test
public void testDeleteDesignDocumentOptions() throws Throwable {
DeleteDesignDocumentOptions deleteDesignDocumentOptionsModel = new DeleteDesignDocumentOptions.Builder().db("testString").ddoc("testString").ifMatch("testString").batch("ok").rev("testString").build();
assertEquals(deleteDesignDocumentOptionsModel.db(), "testString");
assertEquals(deleteDesignDocumentOptionsModel.ddoc(), "testString");
assertEquals(deleteDesignDocumentOptionsModel.ifMatch(), "testString");
assertEquals(deleteDesignDocumentOptionsModel.batch(), "ok");
assertEquals(deleteDesignDocumentOptionsModel.rev(), "testString");
}
Aggregations