Search in sources :

Example 1 with DeleteReplicationDocumentOptions

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

the class CloudantTest method testDeleteReplicationDocumentWOptions.

@Test
public void testDeleteReplicationDocumentWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
    String deleteReplicationDocumentPath = "/_replicator/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the DeleteReplicationDocumentOptions model
    DeleteReplicationDocumentOptions deleteReplicationDocumentOptionsModel = new DeleteReplicationDocumentOptions.Builder().docId("testString").ifMatch("testString").batch("ok").rev("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<DocumentResult> response = cloudantService.deleteReplicationDocument(deleteReplicationDocumentOptionsModel).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, deleteReplicationDocumentPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteReplicationDocumentOptions(com.ibm.cloud.cloudant.v1.model.DeleteReplicationDocumentOptions) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with DeleteReplicationDocumentOptions

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

the class DeleteReplicationDocumentOptionsTest method testDeleteReplicationDocumentOptions.

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

Example 3 with DeleteReplicationDocumentOptions

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

the class Cloudant method deleteReplicationDocument.

/**
 * Cancel a replication.
 *
 * Cancels a replication by deleting the document that describes it from the `_replicator` database.
 *
 * @param deleteReplicationDocumentOptions the {@link DeleteReplicationDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link DocumentResult}
 */
public ServiceCall<DocumentResult> deleteReplicationDocument(DeleteReplicationDocumentOptions deleteReplicationDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteReplicationDocumentOptions, "deleteReplicationDocumentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("doc_id", deleteReplicationDocumentOptions.docId());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_replicator/{doc_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteReplicationDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (deleteReplicationDocumentOptions.ifMatch() != null) {
        builder.header("If-Match", deleteReplicationDocumentOptions.ifMatch());
    }
    if (deleteReplicationDocumentOptions.batch() != null) {
        builder.query("batch", String.valueOf(deleteReplicationDocumentOptions.batch()));
    }
    if (deleteReplicationDocumentOptions.rev() != null) {
        builder.query("rev", String.valueOf(deleteReplicationDocumentOptions.rev()));
    }
    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)

Aggregations

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