use of com.ibm.watson.natural_language_classifier.v1.model.ListClassifiersOptions in project java-sdk by watson-developer-cloud.
the class VisualRecognitionIT method testListClassifiers.
/**
* Test list all the classifiers.
*/
@Ignore
@Test
public void testListClassifiers() {
ListClassifiersOptions options = new ListClassifiersOptions.Builder().verbose(true).build();
List<Classifier> classifiers = service.listClassifiers(options).execute().getClassifiers();
assertNotNull(classifiers);
assertTrue(!classifiers.isEmpty());
Classifier classifier = classifiers.get(0);
assertNotNull(classifier.getClassifierId());
assertNotNull(classifier.getName());
assertNotNull(classifier.getOwner());
assertNotNull(classifier.getStatus());
assertNotNull(classifier.getClasses());
assertNotNull(classifier.getCreated());
}
use of com.ibm.watson.natural_language_classifier.v1.model.ListClassifiersOptions in project java-sdk by watson-developer-cloud.
the class VisualRecognitionTest method testGetClassifiers.
/**
* Test get classifiers.
*
* @throws InterruptedException the interrupted exception
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
public void testGetClassifiers() throws InterruptedException, IOException {
Classifier mockClassifier = loadFixture(FIXTURE_CLASSIFIER, Classifier.class);
List<Classifier> classifiers = new ArrayList<Classifier>();
classifiers.add(mockClassifier);
classifiers.add(mockClassifier);
classifiers.add(mockClassifier);
JsonObject mockResponse = new JsonObject();
mockResponse.add("classifiers", new Gson().toJsonTree(classifiers));
server.enqueue(new MockResponse().setBody(mockResponse.toString()));
ListClassifiersOptions options = new ListClassifiersOptions.Builder().verbose(true).build();
List<Classifier> serviceResponse = service.listClassifiers(options).execute().getClassifiers();
// first request
RecordedRequest request = server.takeRequest();
String path = PATH_CLASSIFIERS + "?" + VERSION_DATE + "=2016-05-20&verbose=true&api_key=" + API_KEY;
assertEquals(path, request.getPath());
assertEquals("GET", request.getMethod());
assertEquals(serviceResponse, classifiers);
}
use of com.ibm.watson.natural_language_classifier.v1.model.ListClassifiersOptions in project java-sdk by watson-developer-cloud.
the class NaturalLanguageClassifier method listClassifiers.
/**
* List classifiers.
*
* <p>Returns an empty array if no classifiers are available.
*
* @param listClassifiersOptions the {@link ListClassifiersOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link ClassifierList}
*/
public ServiceCall<ClassifierList> listClassifiers(ListClassifiersOptions listClassifiersOptions) {
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/classifiers"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("natural_language_classifier", "v1", "listClassifiers");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
ResponseConverter<ClassifierList> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ClassifierList>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.natural_language_classifier.v1.model.ListClassifiersOptions in project java-sdk by watson-developer-cloud.
the class VisualRecognitionIT method testListClassifiers.
/**
* Test list all the classifiers.
*/
@Ignore
@Test
public void testListClassifiers() {
ListClassifiersOptions options = new ListClassifiersOptions.Builder().verbose(true).build();
List<Classifier> classifiers = service.listClassifiers(options).execute().getResult().getClassifiers();
assertNotNull(classifiers);
assertTrue(!classifiers.isEmpty());
Classifier classifier = classifiers.get(0);
assertNotNull(classifier.getClassifierId());
assertNotNull(classifier.getName());
assertNotNull(classifier.getOwner());
assertNotNull(classifier.getStatus());
assertNotNull(classifier.getClasses());
assertNotNull(classifier.getCreated());
}
use of com.ibm.watson.natural_language_classifier.v1.model.ListClassifiersOptions in project java-sdk by watson-developer-cloud.
the class VisualRecognitionTest method testListClassifiersWOptions.
@Test
public void testListClassifiersWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"classifiers\": [{\"classifier_id\": \"classifierId\", \"name\": \"name\", \"owner\": \"owner\", \"status\": \"ready\", \"core_ml_enabled\": false, \"explanation\": \"explanation\", \"created\": \"2019-01-01T12:00:00.000Z\", \"classes\": [{\"class\": \"xClass\"}], \"retrained\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}]}";
String listClassifiersPath = "/v3/classifiers";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the ListClassifiersOptions model
ListClassifiersOptions listClassifiersOptionsModel = new ListClassifiersOptions.Builder().verbose(true).build();
// Invoke operation with valid options model (positive test)
Response<Classifiers> response = visualRecognitionService.listClassifiers(listClassifiersOptionsModel).execute();
assertNotNull(response);
Classifiers responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
assertEquals(Boolean.valueOf(query.get("verbose")), Boolean.valueOf(true));
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, listClassifiersPath);
}
Aggregations