Search in sources :

Example 1 with DeleteAttachmentOptions

use of com.ibm.cloud.cloudant.v1.model.DeleteAttachmentOptions in project cloudant-java-sdk by IBM.

the class Cloudant method deleteAttachment.

/**
 * Delete an attachment.
 *
 * Deletes the attachment with the filename, `{attachment_name}`, from the specified doc. You must supply the `rev`
 * query parameter or `If-Match` header with the current revision to delete the attachment.
 *
 * @param deleteAttachmentOptions the {@link DeleteAttachmentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link DocumentResult}
 */
public ServiceCall<DocumentResult> deleteAttachment(DeleteAttachmentOptions deleteAttachmentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteAttachmentOptions, "deleteAttachmentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", deleteAttachmentOptions.db());
    pathParamsMap.put("doc_id", deleteAttachmentOptions.docId());
    pathParamsMap.put("attachment_name", deleteAttachmentOptions.attachmentName());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/{doc_id}/{attachment_name}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteAttachment");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (deleteAttachmentOptions.ifMatch() != null) {
        builder.header("If-Match", deleteAttachmentOptions.ifMatch());
    }
    if (deleteAttachmentOptions.rev() != null) {
        builder.query("rev", String.valueOf(deleteAttachmentOptions.rev()));
    }
    if (deleteAttachmentOptions.batch() != null) {
        builder.query("batch", String.valueOf(deleteAttachmentOptions.batch()));
    }
    ResponseConverter<DocumentResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DocumentResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult)

Example 2 with DeleteAttachmentOptions

use of com.ibm.cloud.cloudant.v1.model.DeleteAttachmentOptions 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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteAttachmentOptions(com.ibm.cloud.cloudant.v1.model.DeleteAttachmentOptions) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with DeleteAttachmentOptions

use of com.ibm.cloud.cloudant.v1.model.DeleteAttachmentOptions in project cloudant-java-sdk by IBM.

the class DeleteAttachmentOptionsTest method testDeleteAttachmentOptions.

@Test
public void testDeleteAttachmentOptions() throws Throwable {
    DeleteAttachmentOptions deleteAttachmentOptionsModel = new DeleteAttachmentOptions.Builder().db("testString").docId("testString").attachmentName("testString").ifMatch("testString").rev("testString").batch("ok").build();
    assertEquals(deleteAttachmentOptionsModel.db(), "testString");
    assertEquals(deleteAttachmentOptionsModel.docId(), "testString");
    assertEquals(deleteAttachmentOptionsModel.attachmentName(), "testString");
    assertEquals(deleteAttachmentOptionsModel.ifMatch(), "testString");
    assertEquals(deleteAttachmentOptionsModel.rev(), "testString");
    assertEquals(deleteAttachmentOptionsModel.batch(), "ok");
}
Also used : DeleteAttachmentOptions(com.ibm.cloud.cloudant.v1.model.DeleteAttachmentOptions) Test(org.testng.annotations.Test)

Aggregations

DeleteAttachmentOptions (com.ibm.cloud.cloudant.v1.model.DeleteAttachmentOptions)2 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)2 Test (org.testng.annotations.Test)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1