Search in sources :

Example 1 with TrainingExampleList

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

the class DiscoveryTest method testListTrainingExamplesWOptions.

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

Example 2 with TrainingExampleList

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

the class Discovery method listTrainingExamples.

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

Example 3 with TrainingExampleList

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

the class DiscoveryServiceTest method listTrainingExamplesIsSuccessful.

@Test
public void listTrainingExamplesIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(listTrainingExamplesResp));
    ListTrainingExamplesOptions.Builder builder = new ListTrainingExamplesOptions.Builder(environmentId, collectionId, queryId);
    TrainingExampleList response = discoveryService.listTrainingExamples(builder.build()).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(TRAINING2_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(listTrainingExamplesResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) TrainingExampleList(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExampleList) ListTrainingExamplesOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListTrainingExamplesOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 4 with TrainingExampleList

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

the class Discovery method listTrainingExamples.

/**
 * List all examples for this training data query.
 *
 * @param listTrainingExamplesOptions the {@link ListTrainingExamplesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link TrainingExampleList}
 */
public ServiceCall<TrainingExampleList> listTrainingExamples(ListTrainingExamplesOptions listTrainingExamplesOptions) {
    Validator.notNull(listTrainingExamplesOptions, "listTrainingExamplesOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections", "training_data", "examples" };
    String[] pathParameters = { listTrainingExamplesOptions.environmentId(), listTrainingExamplesOptions.collectionId(), listTrainingExamplesOptions.queryId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TrainingExampleList.class));
}
Also used : TrainingExampleList(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExampleList) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder)

Example 5 with TrainingExampleList

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

the class DiscoveryServiceTest method listTrainingExamplesIsSuccessful.

/**
 * List training examples is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void listTrainingExamplesIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(listTrainingExamplesResp));
    ListTrainingExamplesOptions.Builder builder = new ListTrainingExamplesOptions.Builder(environmentId, collectionId, queryId);
    TrainingExampleList response = discoveryService.listTrainingExamples(builder.build()).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(TRAINING2_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(listTrainingExamplesResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) TrainingExampleList(com.ibm.watson.discovery.v1.model.TrainingExampleList) ListTrainingExamplesOptions(com.ibm.watson.discovery.v1.model.ListTrainingExamplesOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Aggregations

TrainingExampleList (com.ibm.watson.discovery.v1.model.TrainingExampleList)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 TrainingExampleList (com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExampleList)2 ListTrainingExamplesOptions (com.ibm.watson.discovery.v1.model.ListTrainingExamplesOptions)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 ListTrainingExamplesOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListTrainingExamplesOptions)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.junit.Test)1 Test (org.testng.annotations.Test)1