Search in sources :

Example 1 with ListTrainingDataOptions

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

the class DiscoveryServiceTest method listTrainingDataIsSuccessful.

@Test
public void listTrainingDataIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(listTrainingDataResp));
    ListTrainingDataOptions getRequest = new ListTrainingDataOptions.Builder(environmentId, collectionId).build();
    TrainingDataSet response = discoveryService.listTrainingData(getRequest).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(TRAINING1_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(listTrainingDataResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ListTrainingDataOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListTrainingDataOptions) TrainingDataSet(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingDataSet) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 2 with ListTrainingDataOptions

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

the class DiscoveryTest method testListTrainingDataWOptions.

// Test the listTrainingData operation with a valid options model parameter
@Test
public void testListTrainingDataWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"environment_id\": \"environmentId\", \"collection_id\": \"collectionId\", \"queries\": [{\"query_id\": \"queryId\", \"natural_language_query\": \"naturalLanguageQuery\", \"filter\": \"filter\", \"examples\": [{\"document_id\": \"documentId\", \"cross_reference\": \"crossReference\", \"relevance\": 9}]}]}";
    String listTrainingDataPath = "/v1/environments/testString/collections/testString/training_data";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListTrainingDataOptions model
    ListTrainingDataOptions listTrainingDataOptionsModel = new ListTrainingDataOptions.Builder().environmentId("testString").collectionId("testString").build();
    // Invoke listTrainingData() with a valid options model and verify the result
    Response<TrainingDataSet> response = discoveryService.listTrainingData(listTrainingDataOptionsModel).execute();
    assertNotNull(response);
    TrainingDataSet responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, listTrainingDataPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListTrainingDataOptions(com.ibm.watson.discovery.v1.model.ListTrainingDataOptions) TrainingDataSet(com.ibm.watson.discovery.v1.model.TrainingDataSet) Test(org.testng.annotations.Test)

Example 3 with ListTrainingDataOptions

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

the class DiscoveryServiceTest method listTrainingDataIsSuccessful.

/**
 * List training data is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void listTrainingDataIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(listTrainingDataResp));
    ListTrainingDataOptions getRequest = new ListTrainingDataOptions.Builder(environmentId, collectionId).build();
    TrainingDataSet response = discoveryService.listTrainingData(getRequest).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(TRAINING1_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(listTrainingDataResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ListTrainingDataOptions(com.ibm.watson.discovery.v1.model.ListTrainingDataOptions) TrainingDataSet(com.ibm.watson.discovery.v1.model.TrainingDataSet) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 4 with ListTrainingDataOptions

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

the class Discovery method listTrainingData.

/**
 * List training data.
 *
 * <p>Lists the training data for the specified collection.
 *
 * @param listTrainingDataOptions the {@link ListTrainingDataOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link TrainingDataSet}
 */
public ServiceCall<TrainingDataSet> listTrainingData(ListTrainingDataOptions listTrainingDataOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listTrainingDataOptions, "listTrainingDataOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", listTrainingDataOptions.environmentId());
    pathParamsMap.put("collection_id", listTrainingDataOptions.collectionId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/training_data", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "listTrainingData");
    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<TrainingDataSet> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingDataSet>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) TrainingDataSet(com.ibm.watson.discovery.v1.model.TrainingDataSet)

Aggregations

TrainingDataSet (com.ibm.watson.discovery.v1.model.TrainingDataSet)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 ListTrainingDataOptions (com.ibm.watson.discovery.v1.model.ListTrainingDataOptions)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 ListTrainingDataOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListTrainingDataOptions)1 TrainingDataSet (com.ibm.watson.developer_cloud.discovery.v1.model.TrainingDataSet)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.junit.Test)1 Test (org.testng.annotations.Test)1