use of com.ibm.watson.discovery.v1.model.GetTrainingExampleOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testGetTrainingExampleWOptions.
// Test the getTrainingExample operation with a valid options model parameter
@Test
public void testGetTrainingExampleWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"document_id\": \"documentId\", \"cross_reference\": \"crossReference\", \"relevance\": 9}";
String getTrainingExamplePath = "/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 GetTrainingExampleOptions model
GetTrainingExampleOptions getTrainingExampleOptionsModel = new GetTrainingExampleOptions.Builder().environmentId("testString").collectionId("testString").queryId("testString").exampleId("testString").build();
// Invoke getTrainingExample() with a valid options model and verify the result
Response<TrainingExample> response = discoveryService.getTrainingExample(getTrainingExampleOptionsModel).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(), "GET");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getTrainingExamplePath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
}
use of com.ibm.watson.discovery.v1.model.GetTrainingExampleOptions in project java-sdk by watson-developer-cloud.
the class Discovery method getTrainingExample.
/**
* Get details for training data example.
*
* <p>Gets the details for this training example.
*
* @param getTrainingExampleOptions the {@link GetTrainingExampleOptions} containing the options
* for the call
* @return a {@link ServiceCall} with a result of type {@link TrainingExample}
*/
public ServiceCall<TrainingExample> getTrainingExample(GetTrainingExampleOptions getTrainingExampleOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getTrainingExampleOptions, "getTrainingExampleOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", getTrainingExampleOptions.environmentId());
pathParamsMap.put("collection_id", getTrainingExampleOptions.collectionId());
pathParamsMap.put("query_id", getTrainingExampleOptions.queryId());
pathParamsMap.put("example_id", getTrainingExampleOptions.exampleId());
RequestBuilder builder = RequestBuilder.get(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", "getTrainingExample");
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<TrainingExample> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingExample>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations