use of com.ibm.watson.discovery.v1.model.ListTrainingDataOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method listTrainingDataIsSuccessful.
@Test
public void listTrainingDataIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(listTrainingDataResp));
ListTrainingDataOptions getRequest = new ListTrainingDataOptions.Builder(environmentId, collectionId).build();
TrainingDataSet response = discoveryService.listTrainingData(getRequest).execute();
RecordedRequest request = server.takeRequest();
assertEquals(TRAINING1_PATH, request.getPath());
assertEquals(GET, request.getMethod());
assertEquals(listTrainingDataResp, response);
}
use of com.ibm.watson.discovery.v1.model.ListTrainingDataOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testListTrainingDataWOptions.
// Test the listTrainingData operation with a valid options model parameter
@Test
public void testListTrainingDataWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"environment_id\": \"environmentId\", \"collection_id\": \"collectionId\", \"queries\": [{\"query_id\": \"queryId\", \"natural_language_query\": \"naturalLanguageQuery\", \"filter\": \"filter\", \"examples\": [{\"document_id\": \"documentId\", \"cross_reference\": \"crossReference\", \"relevance\": 9}]}]}";
String listTrainingDataPath = "/v1/environments/testString/collections/testString/training_data";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the ListTrainingDataOptions model
ListTrainingDataOptions listTrainingDataOptionsModel = new ListTrainingDataOptions.Builder().environmentId("testString").collectionId("testString").build();
// Invoke listTrainingData() with a valid options model and verify the result
Response<TrainingDataSet> response = discoveryService.listTrainingData(listTrainingDataOptionsModel).execute();
assertNotNull(response);
TrainingDataSet 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, listTrainingDataPath);
// 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.ListTrainingDataOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method listTrainingDataIsSuccessful.
/**
* List training data is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void listTrainingDataIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(listTrainingDataResp));
ListTrainingDataOptions getRequest = new ListTrainingDataOptions.Builder(environmentId, collectionId).build();
TrainingDataSet response = discoveryService.listTrainingData(getRequest).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(TRAINING1_PATH, request.getPath());
assertEquals(GET, request.getMethod());
assertEquals(listTrainingDataResp, response);
}
use of com.ibm.watson.discovery.v1.model.ListTrainingDataOptions in project java-sdk by watson-developer-cloud.
the class Discovery method listTrainingData.
/**
* List training data.
*
* <p>Lists the training data for the specified collection.
*
* @param listTrainingDataOptions the {@link ListTrainingDataOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link TrainingDataSet}
*/
public ServiceCall<TrainingDataSet> listTrainingData(ListTrainingDataOptions listTrainingDataOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(listTrainingDataOptions, "listTrainingDataOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", listTrainingDataOptions.environmentId());
pathParamsMap.put("collection_id", listTrainingDataOptions.collectionId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/training_data", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "listTrainingData");
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<TrainingDataSet> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingDataSet>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations