Search in sources :

Example 16 with Classifier

use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier 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 17 with Classifier

use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier in project java-sdk by watson-developer-cloud.

the class VisualRecognitionTest method testCreateClassifier.

/**
 * Test create classifier.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testCreateClassifier() throws IOException, InterruptedException {
    Classifier mockResponse = loadFixture(FIXTURE_CLASSIFIER, Classifier.class);
    server.enqueue(new MockResponse().setBody(mockResponse.toString()));
    // execute request
    File positiveImages = new File(IMAGE_FILE);
    File negativeImages = new File(IMAGE_FILE);
    String class1 = "class1";
    CreateClassifierOptions options = new CreateClassifierOptions.Builder().name(class1).addClass(class1, positiveImages).negativeExamples(negativeImages).build();
    Classifier serviceResponse = service.createClassifier(options).execute();
    // first request
    RecordedRequest request = server.takeRequest();
    String path = PATH_CLASSIFIERS + "?" + VERSION_DATE + "=2016-05-20&api_key=" + API_KEY;
    assertEquals(path, request.getPath());
    assertEquals("POST", request.getMethod());
    String body = request.getBody().readUtf8();
    String contentDisposition = "Content-Disposition: form-data; name=\"class1_positive_examples\"; filename=\"test.zip\"";
    assertTrue(body.contains(contentDisposition));
    assertTrue(body.contains("Content-Disposition: form-data; name=\"name\""));
    assertEquals(serviceResponse, mockResponse);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CreateClassifierOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.CreateClassifierOptions) Classifier(com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier) File(java.io.File) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 18 with Classifier

use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier 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 19 with Classifier

use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier in project java-sdk by watson-developer-cloud.

the class VisualRecognitionTest method testDeleteClassifier.

/**
 * Test delete classifier.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testDeleteClassifier() throws IOException, InterruptedException {
    server.enqueue(new MockResponse().setBody(""));
    String class1 = "class1";
    DeleteClassifierOptions options = new DeleteClassifierOptions.Builder(class1).build();
    service.deleteClassifier(options).execute();
    // first request
    RecordedRequest request = server.takeRequest();
    String path = String.format(PATH_CLASSIFIER + "?" + VERSION_DATE + "=2016-05-20&api_key=" + API_KEY, class1);
    assertEquals(path, request.getPath());
    assertEquals("DELETE", request.getMethod());
}
Also used : DeleteClassifierOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.DeleteClassifierOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 20 with Classifier

use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier in project java-sdk by watson-developer-cloud.

the class VisualRecognitionTest method testGetClassifier.

/**
 * Test get classifier.
 *
 * @throws InterruptedException the interrupted exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void testGetClassifier() throws InterruptedException, IOException {
    try {
        Classifier mockResponse = loadFixture(FIXTURE_CLASSIFIER, Classifier.class);
        server.enqueue(new MockResponse().setBody(mockResponse.toString()));
        // execute request
        String class1 = "class1";
        GetClassifierOptions getOptions = new GetClassifierOptions.Builder(class1).build();
        Classifier serviceResponse = service.getClassifier(getOptions).execute();
        // first request
        RecordedRequest request = server.takeRequest();
        String path = String.format(PATH_CLASSIFIER + "?" + VERSION_DATE + "=2016-05-20&api_key=" + API_KEY, class1);
        assertEquals(path, request.getPath());
        assertEquals("GET", request.getMethod());
        assertEquals(serviceResponse, mockResponse);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetClassifierOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetClassifierOptions) Classifier(com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier) IOException(java.io.IOException) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 Classifier (com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier)13 File (java.io.File)9 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)8 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)7 Classifier (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier)7 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)5 MockResponse (okhttp3.mockwebserver.MockResponse)5 Ignore (org.junit.Ignore)5 CreateClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.CreateClassifierOptions)4 DeleteClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.DeleteClassifierOptions)4 GetClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetClassifierOptions)3 ListClassifiersOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ListClassifiersOptions)3 MultipartBody (okhttp3.MultipartBody)3 RequestBody (okhttp3.RequestBody)3 CreateClassifierOptions (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.CreateClassifierOptions)2 GetClassifierOptions (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.GetClassifierOptions)2 ClassifiedImages (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifiedImages)2 ClassifyOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifyOptions)2