Search in sources :

Example 6 with ListClassifiersOptions

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());
}
Also used : ListClassifiersOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ListClassifiersOptions) Classifier(com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier) Ignore(org.junit.Ignore) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 7 with ListClassifiersOptions

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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) ListClassifiersOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ListClassifiersOptions) Classifier(com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 8 with ListClassifiersOptions

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) ClassifierList(com.ibm.watson.natural_language_classifier.v1.model.ClassifierList)

Example 9 with ListClassifiersOptions

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());
}
Also used : ListClassifiersOptions(com.ibm.watson.visual_recognition.v3.model.ListClassifiersOptions) Classifier(com.ibm.watson.visual_recognition.v3.model.Classifier) Ignore(org.junit.Ignore) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 10 with ListClassifiersOptions

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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Classifiers(com.ibm.watson.visual_recognition.v3.model.Classifiers) ListClassifiersOptions(com.ibm.watson.visual_recognition.v3.model.ListClassifiersOptions) Test(org.testng.annotations.Test)

Aggregations

Test (org.junit.Test)7 Ignore (org.junit.Ignore)4 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)3 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)3 Classifier (com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier)3 ListClassifiersOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ListClassifiersOptions)3 ClassifierList (com.ibm.watson.natural_language_classifier.v1.model.ClassifierList)3 ListClassifiersOptions (com.ibm.watson.visual_recognition.v3.model.ListClassifiersOptions)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 ListClassifiersOptions (com.ibm.watson.natural_language_classifier.v1.model.ListClassifiersOptions)2 Classifier (com.ibm.watson.visual_recognition.v3.model.Classifier)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Test (org.testng.annotations.Test)2 Gson (com.google.gson.Gson)1 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 ClassifierList (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifierList)1