Search in sources :

Example 1 with GetBatchOptions

use of com.ibm.watson.compare_comply.v1.model.GetBatchOptions in project java-sdk by watson-developer-cloud.

the class CompareComplyTest method testGetBatchWOptions.

@Test
public void testGetBatchWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"function\": \"element_classification\", \"input_bucket_location\": \"inputBucketLocation\", \"input_bucket_name\": \"inputBucketName\", \"output_bucket_location\": \"outputBucketLocation\", \"output_bucket_name\": \"outputBucketName\", \"batch_id\": \"batchId\", \"document_counts\": {\"total\": 5, \"pending\": 7, \"successful\": 10, \"failed\": 6}, \"status\": \"status\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}";
    String getBatchPath = "/v1/batches/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetBatchOptions model
    GetBatchOptions getBatchOptionsModel = new GetBatchOptions.Builder().batchId("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<BatchStatus> response = compareComplyService.getBatch(getBatchOptionsModel).execute();
    assertNotNull(response);
    BatchStatus 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(query.get("version"), "testString");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getBatchPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) BatchStatus(com.ibm.watson.compare_comply.v1.model.BatchStatus) GetBatchOptions(com.ibm.watson.compare_comply.v1.model.GetBatchOptions) Test(org.testng.annotations.Test)

Example 2 with GetBatchOptions

use of com.ibm.watson.compare_comply.v1.model.GetBatchOptions in project java-sdk by watson-developer-cloud.

the class CompareComply method getBatch.

/**
 * Get information about a specific batch-processing job.
 *
 * <p>Gets information about a batch-processing job with a specified ID.
 *
 * @param getBatchOptions the {@link GetBatchOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link BatchStatus}
 */
public ServiceCall<BatchStatus> getBatch(GetBatchOptions getBatchOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getBatchOptions, "getBatchOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("batch_id", getBatchOptions.batchId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/batches/{batch_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "getBatch");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    ResponseConverter<BatchStatus> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<BatchStatus>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) BatchStatus(com.ibm.watson.compare_comply.v1.model.BatchStatus)

Example 3 with GetBatchOptions

use of com.ibm.watson.compare_comply.v1.model.GetBatchOptions in project java-sdk by watson-developer-cloud.

the class CompareComplyServiceIT method testBatchOperations.

@Test
@Ignore
public void testBatchOperations() throws FileNotFoundException {
    String bucketLocation = "us-south";
    String inputBucketName = "compare-comply-integration-test-bucket-input";
    String outputBucketName = "compare-comply-integration-test-bucket-output";
    CreateBatchOptions createBatchOptions = new CreateBatchOptions.Builder().function(CreateBatchOptions.Function.ELEMENT_CLASSIFICATION).inputBucketLocation(bucketLocation).inputBucketName(inputBucketName).inputCredentialsFile(INPUT_CREDENTIALS_FILE).outputBucketLocation(bucketLocation).outputBucketName(outputBucketName).outputCredentialsFile(OUTPUT_CREDENTIALS_FILE).build();
    BatchStatus createBatchResponse = service.createBatch(createBatchOptions).execute().getResult();
    String batchId = createBatchResponse.getBatchId();
    GetBatchOptions getBatchOptions = new GetBatchOptions.Builder().batchId(batchId).build();
    BatchStatus getBatchResponse = service.getBatch(getBatchOptions).execute().getResult();
    assertNotNull(getBatchResponse);
    UpdateBatchOptions updateBatchOptions = new UpdateBatchOptions.Builder().batchId(batchId).action(UpdateBatchOptions.Action.RESCAN).build();
    BatchStatus updateBatchResponse = service.updateBatch(updateBatchOptions).execute().getResult();
    assertTrue(updateBatchResponse.getCreated().before(updateBatchResponse.getUpdated()));
    Batches listBatchesResponse = service.listBatches().execute().getResult();
    List<BatchStatus> batches = listBatchesResponse.getBatches();
    boolean batchFound = false;
    for (BatchStatus batch : batches) {
        if (batch.getBatchId().equals(batchId)) {
            batchFound = true;
            break;
        }
    }
    assertTrue(batchFound);
}
Also used : UpdateBatchOptions(com.ibm.watson.compare_comply.v1.model.UpdateBatchOptions) BatchStatus(com.ibm.watson.compare_comply.v1.model.BatchStatus) Batches(com.ibm.watson.compare_comply.v1.model.Batches) CreateBatchOptions(com.ibm.watson.compare_comply.v1.model.CreateBatchOptions) GetBatchOptions(com.ibm.watson.compare_comply.v1.model.GetBatchOptions) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

BatchStatus (com.ibm.watson.compare_comply.v1.model.BatchStatus)3 GetBatchOptions (com.ibm.watson.compare_comply.v1.model.GetBatchOptions)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 Batches (com.ibm.watson.compare_comply.v1.model.Batches)1 CreateBatchOptions (com.ibm.watson.compare_comply.v1.model.CreateBatchOptions)1 UpdateBatchOptions (com.ibm.watson.compare_comply.v1.model.UpdateBatchOptions)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 Test (org.testng.annotations.Test)1