Search in sources :

Example 1 with ActiveTask

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

the class Cloudant method getActiveTasks.

/**
 * Retrieve list of running tasks.
 *
 * Lists running tasks, including the task type, name, status, and process ID. The result includes a JSON array of the
 * currently running tasks, with each task described as a single object. Depending on the operation type, the set of
 * response object fields might be different.
 *
 * @param getActiveTasksOptions the {@link GetActiveTasksOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link List}
 */
public ServiceCall<List<ActiveTask>> getActiveTasks(GetActiveTasksOptions getActiveTasksOptions) {
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_active_tasks"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getActiveTasks");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<List<ActiveTask>> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<List<ActiveTask>>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) List(java.util.List) ActiveTask(com.ibm.cloud.cloudant.v1.model.ActiveTask)

Example 2 with ActiveTask

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

the class CloudantTest method testGetActiveTasksWOptions.

@Test
public void testGetActiveTasksWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "[{\"changes_done\": 0, \"database\": \"database\", \"node\": \"node\", \"pid\": \"pid\", \"progress\": 0, \"started_on\": 0, \"status\": \"status\", \"task\": \"task\", \"total_changes\": 0, \"type\": \"type\", \"updated_on\": 0}]";
    String getActiveTasksPath = "/_active_tasks";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetActiveTasksOptions model
    GetActiveTasksOptions getActiveTasksOptionsModel = new GetActiveTasksOptions();
    // Invoke operation with valid options model (positive test)
    Response<List<ActiveTask>> response = cloudantService.getActiveTasks(getActiveTasksOptionsModel).execute();
    assertNotNull(response);
    List<ActiveTask> 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);
    assertNull(query);
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getActiveTasksPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetActiveTasksOptions(com.ibm.cloud.cloudant.v1.model.GetActiveTasksOptions) ArrayList(java.util.ArrayList) List(java.util.List) ActiveTask(com.ibm.cloud.cloudant.v1.model.ActiveTask) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with ActiveTask

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

the class ActiveTaskTest method testActiveTask.

@Test
public void testActiveTask() throws Throwable {
    ActiveTask activeTaskModel = new ActiveTask();
    assertNull(activeTaskModel.getChangesDone());
    assertNull(activeTaskModel.getDatabase());
    assertNull(activeTaskModel.getNode());
    assertNull(activeTaskModel.getPid());
    assertNull(activeTaskModel.getProgress());
    assertNull(activeTaskModel.getStartedOn());
    assertNull(activeTaskModel.getStatus());
    assertNull(activeTaskModel.getTask());
    assertNull(activeTaskModel.getTotalChanges());
    assertNull(activeTaskModel.getType());
    assertNull(activeTaskModel.getUpdatedOn());
}
Also used : ActiveTask(com.ibm.cloud.cloudant.v1.model.ActiveTask) Test(org.testng.annotations.Test)

Aggregations

ActiveTask (com.ibm.cloud.cloudant.v1.model.ActiveTask)3 List (java.util.List)2 Test (org.testng.annotations.Test)2 GetActiveTasksOptions (com.ibm.cloud.cloudant.v1.model.GetActiveTasksOptions)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