Search in sources :

Example 1 with UpdateTrainingExampleOptions

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

the class DiscoveryTest method testUpdateTrainingExampleWOptions.

// Test the updateTrainingExample operation with a valid options model parameter
@Test
public void testUpdateTrainingExampleWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"document_id\": \"documentId\", \"cross_reference\": \"crossReference\", \"relevance\": 9}";
    String updateTrainingExamplePath = "/v1/environments/testString/collections/testString/training_data/testString/examples/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the UpdateTrainingExampleOptions model
    UpdateTrainingExampleOptions updateTrainingExampleOptionsModel = new UpdateTrainingExampleOptions.Builder().environmentId("testString").collectionId("testString").queryId("testString").exampleId("testString").crossReference("testString").relevance(Long.valueOf("26")).build();
    // Invoke updateTrainingExample() with a valid options model and verify the result
    Response<TrainingExample> response = discoveryService.updateTrainingExample(updateTrainingExampleOptionsModel).execute();
    assertNotNull(response);
    TrainingExample 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(), "PUT");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, updateTrainingExamplePath);
    // 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) UpdateTrainingExampleOptions(com.ibm.watson.discovery.v1.model.UpdateTrainingExampleOptions) TrainingExample(com.ibm.watson.discovery.v1.model.TrainingExample) Test(org.testng.annotations.Test)

Example 2 with UpdateTrainingExampleOptions

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

the class Discovery method updateTrainingExample.

/**
 * Change label or cross reference for example.
 *
 * <p>Changes the label or cross reference query for this training data example.
 *
 * @param updateTrainingExampleOptions the {@link UpdateTrainingExampleOptions} containing the
 *     options for the call
 * @return a {@link ServiceCall} with a result of type {@link TrainingExample}
 */
public ServiceCall<TrainingExample> updateTrainingExample(UpdateTrainingExampleOptions updateTrainingExampleOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateTrainingExampleOptions, "updateTrainingExampleOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", updateTrainingExampleOptions.environmentId());
    pathParamsMap.put("collection_id", updateTrainingExampleOptions.collectionId());
    pathParamsMap.put("query_id", updateTrainingExampleOptions.queryId());
    pathParamsMap.put("example_id", updateTrainingExampleOptions.exampleId());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/training_data/{query_id}/examples/{example_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "updateTrainingExample");
    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));
    final JsonObject contentJson = new JsonObject();
    if (updateTrainingExampleOptions.crossReference() != null) {
        contentJson.addProperty("cross_reference", updateTrainingExampleOptions.crossReference());
    }
    if (updateTrainingExampleOptions.relevance() != null) {
        contentJson.addProperty("relevance", updateTrainingExampleOptions.relevance());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<TrainingExample> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingExample>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) TrainingExample(com.ibm.watson.discovery.v1.model.TrainingExample) JsonObject(com.google.gson.JsonObject)

Aggregations

TrainingExample (com.ibm.watson.discovery.v1.model.TrainingExample)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 UpdateTrainingExampleOptions (com.ibm.watson.discovery.v1.model.UpdateTrainingExampleOptions)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1