Search in sources :

Example 1 with DeleteLocalDocumentOptions

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

the class CloudantTest method testDeleteLocalDocumentWOptions.

@Test
public void testDeleteLocalDocumentWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
    String deleteLocalDocumentPath = "/testString/_local/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the DeleteLocalDocumentOptions model
    DeleteLocalDocumentOptions deleteLocalDocumentOptionsModel = new DeleteLocalDocumentOptions.Builder().db("testString").docId("testString").batch("ok").build();
    // Invoke operation with valid options model (positive test)
    Response<DocumentResult> response = cloudantService.deleteLocalDocument(deleteLocalDocumentOptionsModel).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");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, deleteLocalDocumentPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult) DeleteLocalDocumentOptions(com.ibm.cloud.cloudant.v1.model.DeleteLocalDocumentOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with DeleteLocalDocumentOptions

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

the class Cloudant method deleteLocalDocument.

/**
 * Delete a local document.
 *
 * Deletes the specified local document. The semantics are identical to deleting a standard document in the specified
 * database, except that the document is not replicated.
 *
 * @param deleteLocalDocumentOptions the {@link DeleteLocalDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link DocumentResult}
 */
public ServiceCall<DocumentResult> deleteLocalDocument(DeleteLocalDocumentOptions deleteLocalDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteLocalDocumentOptions, "deleteLocalDocumentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", deleteLocalDocumentOptions.db());
    pathParamsMap.put("doc_id", deleteLocalDocumentOptions.docId());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_local/{doc_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteLocalDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (deleteLocalDocumentOptions.batch() != null) {
        builder.query("batch", String.valueOf(deleteLocalDocumentOptions.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 3 with DeleteLocalDocumentOptions

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

the class DeleteLocalDocumentOptionsTest method testDeleteLocalDocumentOptions.

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

Aggregations

DeleteLocalDocumentOptions (com.ibm.cloud.cloudant.v1.model.DeleteLocalDocumentOptions)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