Search in sources :

Example 1 with GetTrainingDataOptions

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

the class DiscoveryTest method testGetTrainingDataWOptions.

// Test the getTrainingData operation with a valid options model parameter
@Test
public void testGetTrainingDataWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"query_id\": \"queryId\", \"natural_language_query\": \"naturalLanguageQuery\", \"filter\": \"filter\", \"examples\": [{\"document_id\": \"documentId\", \"cross_reference\": \"crossReference\", \"relevance\": 9}]}";
    String getTrainingDataPath = "/v1/environments/testString/collections/testString/training_data/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetTrainingDataOptions model
    GetTrainingDataOptions getTrainingDataOptionsModel = new GetTrainingDataOptions.Builder().environmentId("testString").collectionId("testString").queryId("testString").build();
    // Invoke getTrainingData() with a valid options model and verify the result
    Response<TrainingQuery> response = discoveryService.getTrainingData(getTrainingDataOptionsModel).execute();
    assertNotNull(response);
    TrainingQuery 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, getTrainingDataPath);
    // 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) GetTrainingDataOptions(com.ibm.watson.discovery.v1.model.GetTrainingDataOptions) TrainingQuery(com.ibm.watson.discovery.v1.model.TrainingQuery) Test(org.testng.annotations.Test)

Example 2 with GetTrainingDataOptions

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

the class Discovery method getTrainingData.

/**
 * Get details about a query.
 *
 * <p>Gets details for a specific training data query, including the query string and all
 * examples.
 *
 * @param getTrainingDataOptions the {@link GetTrainingDataOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link TrainingQuery}
 */
public ServiceCall<TrainingQuery> getTrainingData(GetTrainingDataOptions getTrainingDataOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getTrainingDataOptions, "getTrainingDataOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", getTrainingDataOptions.environmentId());
    pathParamsMap.put("collection_id", getTrainingDataOptions.collectionId());
    pathParamsMap.put("query_id", getTrainingDataOptions.queryId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/training_data/{query_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getTrainingData");
    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<TrainingQuery> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingQuery>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) TrainingQuery(com.ibm.watson.discovery.v1.model.TrainingQuery)

Aggregations

TrainingQuery (com.ibm.watson.discovery.v1.model.TrainingQuery)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 GetTrainingDataOptions (com.ibm.watson.discovery.v1.model.GetTrainingDataOptions)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1