Search in sources :

Example 1 with GetReplicationDocumentOptions

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

the class Cloudant method getReplicationDocument.

/**
 * Retrieve a replication document.
 *
 * Retrieves a replication document from the `_replicator` database to view the configuration of the replication. The
 * status of the replication is no longer recorded in the document but can be checked via the replication scheduler.
 *
 * @param getReplicationDocumentOptions the {@link GetReplicationDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ReplicationDocument}
 */
public ServiceCall<ReplicationDocument> getReplicationDocument(GetReplicationDocumentOptions getReplicationDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getReplicationDocumentOptions, "getReplicationDocumentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("doc_id", getReplicationDocumentOptions.docId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_replicator/{doc_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getReplicationDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (getReplicationDocumentOptions.ifNoneMatch() != null) {
        builder.header("If-None-Match", getReplicationDocumentOptions.ifNoneMatch());
    }
    if (getReplicationDocumentOptions.attachments() != null) {
        builder.query("attachments", String.valueOf(getReplicationDocumentOptions.attachments()));
    }
    if (getReplicationDocumentOptions.attEncodingInfo() != null) {
        builder.query("att_encoding_info", String.valueOf(getReplicationDocumentOptions.attEncodingInfo()));
    }
    if (getReplicationDocumentOptions.conflicts() != null) {
        builder.query("conflicts", String.valueOf(getReplicationDocumentOptions.conflicts()));
    }
    if (getReplicationDocumentOptions.deletedConflicts() != null) {
        builder.query("deleted_conflicts", String.valueOf(getReplicationDocumentOptions.deletedConflicts()));
    }
    if (getReplicationDocumentOptions.latest() != null) {
        builder.query("latest", String.valueOf(getReplicationDocumentOptions.latest()));
    }
    if (getReplicationDocumentOptions.localSeq() != null) {
        builder.query("local_seq", String.valueOf(getReplicationDocumentOptions.localSeq()));
    }
    if (getReplicationDocumentOptions.meta() != null) {
        builder.query("meta", String.valueOf(getReplicationDocumentOptions.meta()));
    }
    if (getReplicationDocumentOptions.rev() != null) {
        builder.query("rev", String.valueOf(getReplicationDocumentOptions.rev()));
    }
    if (getReplicationDocumentOptions.revs() != null) {
        builder.query("revs", String.valueOf(getReplicationDocumentOptions.revs()));
    }
    if (getReplicationDocumentOptions.revsInfo() != null) {
        builder.query("revs_info", String.valueOf(getReplicationDocumentOptions.revsInfo()));
    }
    ResponseConverter<ReplicationDocument> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ReplicationDocument>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument)

Example 2 with GetReplicationDocumentOptions

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

the class CloudantTest method testGetReplicationDocumentWOptions.

@Test
public void testGetReplicationDocumentWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"_attachments\": {\"mapKey\": {\"content_type\": \"contentType\", \"data\": \"VGhpcyBpcyBhbiBlbmNvZGVkIGJ5dGUgYXJyYXku\", \"digest\": \"digest\", \"encoded_length\": 0, \"encoding\": \"encoding\", \"follows\": false, \"length\": 0, \"revpos\": 1, \"stub\": true}}, \"_conflicts\": [\"conflicts\"], \"_deleted\": false, \"_deleted_conflicts\": [\"deletedConflicts\"], \"_id\": \"id\", \"_local_seq\": \"localSeq\", \"_rev\": \"rev\", \"_revisions\": {\"ids\": [\"ids\"], \"start\": 1}, \"_revs_info\": [{\"rev\": \"rev\", \"status\": \"available\"}], \"cancel\": true, \"checkpoint_interval\": 0, \"connection_timeout\": 0, \"continuous\": false, \"create_target\": false, \"create_target_params\": {\"n\": 1, \"partitioned\": false, \"q\": 1}, \"doc_ids\": [\"docIds\"], \"filter\": \"filter\", \"http_connections\": 1, \"query_params\": {\"mapKey\": \"inner\"}, \"retries_per_request\": 0, \"selector\": {\"mapKey\": \"anyValue\"}, \"since_seq\": \"sinceSeq\", \"socket_options\": \"socketOptions\", \"source\": {\"auth\": {\"basic\": {\"password\": \"password\", \"username\": \"username\"}, \"iam\": {\"api_key\": \"apiKey\"}}, \"headers\": {\"mapKey\": \"inner\"}, \"url\": \"url\"}, \"source_proxy\": \"sourceProxy\", \"target\": {\"auth\": {\"basic\": {\"password\": \"password\", \"username\": \"username\"}, \"iam\": {\"api_key\": \"apiKey\"}}, \"headers\": {\"mapKey\": \"inner\"}, \"url\": \"url\"}, \"target_proxy\": \"targetProxy\", \"use_checkpoints\": true, \"user_ctx\": {\"db\": \"db\", \"name\": \"name\", \"roles\": [\"_reader\"]}, \"worker_batch_size\": 1, \"worker_processes\": 1}";
    String getReplicationDocumentPath = "/_replicator/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetReplicationDocumentOptions model
    GetReplicationDocumentOptions getReplicationDocumentOptionsModel = new GetReplicationDocumentOptions.Builder().docId("testString").ifNoneMatch("testString").attachments(false).attEncodingInfo(false).conflicts(false).deletedConflicts(false).latest(false).localSeq(false).meta(false).rev("testString").revs(false).revsInfo(false).build();
    // Invoke operation with valid options model (positive test)
    Response<ReplicationDocument> response = cloudantService.getReplicationDocument(getReplicationDocumentOptionsModel).execute();
    assertNotNull(response);
    ReplicationDocument responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(Boolean.valueOf(query.get("attachments")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("att_encoding_info")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("conflicts")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("deleted_conflicts")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("latest")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("local_seq")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("meta")), Boolean.valueOf(false));
    assertEquals(query.get("rev"), "testString");
    assertEquals(Boolean.valueOf(query.get("revs")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("revs_info")), Boolean.valueOf(false));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getReplicationDocumentPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetReplicationDocumentOptions(com.ibm.cloud.cloudant.v1.model.GetReplicationDocumentOptions) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with GetReplicationDocumentOptions

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

the class GetReplicationDocumentOptionsTest method testGetReplicationDocumentOptions.

@Test
public void testGetReplicationDocumentOptions() throws Throwable {
    GetReplicationDocumentOptions getReplicationDocumentOptionsModel = new GetReplicationDocumentOptions.Builder().docId("testString").ifNoneMatch("testString").attachments(false).attEncodingInfo(false).conflicts(false).deletedConflicts(false).latest(false).localSeq(false).meta(false).rev("testString").revs(false).revsInfo(false).build();
    assertEquals(getReplicationDocumentOptionsModel.docId(), "testString");
    assertEquals(getReplicationDocumentOptionsModel.ifNoneMatch(), "testString");
    assertEquals(getReplicationDocumentOptionsModel.attachments(), Boolean.valueOf(false));
    assertEquals(getReplicationDocumentOptionsModel.attEncodingInfo(), Boolean.valueOf(false));
    assertEquals(getReplicationDocumentOptionsModel.conflicts(), Boolean.valueOf(false));
    assertEquals(getReplicationDocumentOptionsModel.deletedConflicts(), Boolean.valueOf(false));
    assertEquals(getReplicationDocumentOptionsModel.latest(), Boolean.valueOf(false));
    assertEquals(getReplicationDocumentOptionsModel.localSeq(), Boolean.valueOf(false));
    assertEquals(getReplicationDocumentOptionsModel.meta(), Boolean.valueOf(false));
    assertEquals(getReplicationDocumentOptionsModel.rev(), "testString");
    assertEquals(getReplicationDocumentOptionsModel.revs(), Boolean.valueOf(false));
    assertEquals(getReplicationDocumentOptionsModel.revsInfo(), Boolean.valueOf(false));
}
Also used : GetReplicationDocumentOptions(com.ibm.cloud.cloudant.v1.model.GetReplicationDocumentOptions) Test(org.testng.annotations.Test)

Aggregations

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