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");
}
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);
}
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);
}
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));
}
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);
}
Aggregations