Search in sources :

Example 1 with SchedulerDocsResult

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

the class CloudantTest method testGetSchedulerDocsWOptions.

@Test
public void testGetSchedulerDocsWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"total_rows\": 0, \"docs\": [{\"database\": \"database\", \"doc_id\": \"docId\", \"error_count\": 0, \"id\": \"id\", \"info\": {\"changes_pending\": 0, \"checkpointed_source_seq\": \"checkpointedSourceSeq\", \"doc_write_failures\": 0, \"docs_read\": 0, \"docs_written\": 0, \"error\": \"error\", \"missing_revisions_found\": 0, \"revisions_checked\": 0, \"source_seq\": \"sourceSeq\", \"through_seq\": \"throughSeq\"}, \"last_updated\": \"2019-01-01T12:00:00.000Z\", \"node\": \"node\", \"source\": \"source\", \"source_proxy\": \"sourceProxy\", \"start_time\": \"2019-01-01T12:00:00.000Z\", \"state\": \"initializing\", \"target\": \"target\", \"target_proxy\": \"targetProxy\"}]}";
    String getSchedulerDocsPath = "/_scheduler/docs";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetSchedulerDocsOptions model
    GetSchedulerDocsOptions getSchedulerDocsOptionsModel = new GetSchedulerDocsOptions.Builder().limit(Long.valueOf("0")).skip(Long.valueOf("0")).states(new java.util.ArrayList<String>(java.util.Arrays.asList("initializing"))).build();
    // Invoke operation with valid options model (positive test)
    Response<SchedulerDocsResult> response = cloudantService.getSchedulerDocs(getSchedulerDocsOptionsModel).execute();
    assertNotNull(response);
    SchedulerDocsResult 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(Long.valueOf(query.get("limit")), Long.valueOf("0"));
    assertEquals(Long.valueOf(query.get("skip")), Long.valueOf("0"));
    assertEquals(query.get("states"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("initializing")), ","));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getSchedulerDocsPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetSchedulerDocsOptions(com.ibm.cloud.cloudant.v1.model.GetSchedulerDocsOptions) ArrayList(java.util.ArrayList) SchedulerDocsResult(com.ibm.cloud.cloudant.v1.model.SchedulerDocsResult) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with SchedulerDocsResult

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

the class SchedulerDocsResultTest method testSchedulerDocsResult.

@Test
public void testSchedulerDocsResult() throws Throwable {
    SchedulerDocsResult schedulerDocsResultModel = new SchedulerDocsResult();
    assertNull(schedulerDocsResultModel.getTotalRows());
    assertNull(schedulerDocsResultModel.getDocs());
}
Also used : SchedulerDocsResult(com.ibm.cloud.cloudant.v1.model.SchedulerDocsResult) Test(org.testng.annotations.Test)

Example 3 with SchedulerDocsResult

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

the class Cloudant method getSchedulerDocs.

/**
 * Retrieve replication scheduler documents.
 *
 * Lists replication documents, including information about all documents, even the ones in a completed or failed
 * state. For each document, the endpoint returns the document ID, database, replication ID, source and target, and
 * other information.
 *
 * @param getSchedulerDocsOptions the {@link GetSchedulerDocsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link SchedulerDocsResult}
 */
public ServiceCall<SchedulerDocsResult> getSchedulerDocs(GetSchedulerDocsOptions getSchedulerDocsOptions) {
    if (getSchedulerDocsOptions == null) {
        getSchedulerDocsOptions = new GetSchedulerDocsOptions.Builder().build();
    }
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_scheduler/docs"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getSchedulerDocs");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (getSchedulerDocsOptions.limit() != null) {
        builder.query("limit", String.valueOf(getSchedulerDocsOptions.limit()));
    }
    if (getSchedulerDocsOptions.skip() != null) {
        builder.query("skip", String.valueOf(getSchedulerDocsOptions.skip()));
    }
    if (getSchedulerDocsOptions.states() != null) {
        builder.query("states", RequestUtils.join(getSchedulerDocsOptions.states(), ","));
    }
    ResponseConverter<SchedulerDocsResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SchedulerDocsResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) SchedulerDocsResult(com.ibm.cloud.cloudant.v1.model.SchedulerDocsResult)

Aggregations

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