Search in sources :

Example 6 with ClassifiedImages

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

the class VisualRecognitionTest method testClassifyWOptions.

@Test
public void testClassifyWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"custom_classes\": 13, \"images_processed\": 15, \"images\": [{\"source_url\": \"sourceUrl\", \"resolved_url\": \"resolvedUrl\", \"image\": \"image\", \"error\": {\"code\": 4, \"description\": \"description\", \"error_id\": \"errorId\"}, \"classifiers\": [{\"name\": \"name\", \"classifier_id\": \"classifierId\", \"classes\": [{\"class\": \"xClass\", \"score\": 0, \"type_hierarchy\": \"typeHierarchy\"}]}]}], \"warnings\": [{\"warning_id\": \"warningId\", \"description\": \"description\"}]}";
    String classifyPath = "/v3/classify";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the ClassifyOptions model
    ClassifyOptions classifyOptionsModel = new ClassifyOptions.Builder().imagesFile(TestUtilities.createMockStream("This is a mock file.")).imagesFilename("testString").imagesFileContentType("testString").url("testString").threshold(Float.valueOf("36.0")).owners(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).classifierIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).acceptLanguage("en").build();
    // Invoke operation with valid options model (positive test)
    Response<ClassifiedImages> response = visualRecognitionService.classify(classifyOptionsModel).execute();
    assertNotNull(response);
    ClassifiedImages responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, classifyPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ClassifyOptions(com.ibm.watson.visual_recognition.v3.model.ClassifyOptions) ClassifiedImages(com.ibm.watson.visual_recognition.v3.model.ClassifiedImages) Test(org.testng.annotations.Test)

Example 7 with ClassifiedImages

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

the class VisualRecognitionIT method testClassifyImagesFromBytes.

/**
 * Test classify a single jpg image.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void testClassifyImagesFromBytes() throws IOException {
    InputStream imagesStream = new FileInputStream(SINGLE_IMAGE_FILE);
    ClassifyOptions options = new ClassifyOptions.Builder().imagesFile(imagesStream).imagesFilename("car.png").build();
    ClassifiedImages result = service.classify(options).execute().getResult();
    assertClassifyImage(result, options);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClassifyOptions(com.ibm.watson.visual_recognition.v3.model.ClassifyOptions) ClassifiedImages(com.ibm.watson.visual_recognition.v3.model.ClassifiedImages) FileInputStream(java.io.FileInputStream) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 8 with ClassifiedImages

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

the class VisualRecognitionIT method testClassifyImagesFromUrl.

/**
 * Test classify images from url.
 */
@Test
public void testClassifyImagesFromUrl() {
    ClassifyOptions options = new ClassifyOptions.Builder().url(IMAGE_URL).build();
    ClassifiedImages result = service.classify(options).execute().getResult();
    assertClassifyImage(result, options);
}
Also used : ClassifyOptions(com.ibm.watson.visual_recognition.v3.model.ClassifyOptions) ClassifiedImages(com.ibm.watson.visual_recognition.v3.model.ClassifiedImages) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 9 with ClassifiedImages

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

the class VisualRecognitionIT method testClassifyImagesFromUrl.

/**
 * Test classify images from url.
 */
@Test
public void testClassifyImagesFromUrl() {
    ClassifyOptions options = new ClassifyOptions.Builder().url(IMAGE_URL).build();
    ClassifiedImages result = service.classify(options).execute();
    assertClassifyImage(result, options);
}
Also used : ClassifyOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifyOptions) ClassifiedImages(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifiedImages) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 10 with ClassifiedImages

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

the class VisualRecognitionIT method testClassifyImagesFromFile.

/**
 * Test classify images from zip file.
 */
@Test
public void testClassifyImagesFromFile() throws FileNotFoundException {
    File images = new File(IMAGE_FILE);
    ClassifyOptions options = new ClassifyOptions.Builder().imagesFile(images).build();
    ClassifiedImages result = service.classify(options).execute();
    assertClassifyImage(result, options);
}
Also used : ClassifyOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifyOptions) ClassifiedImages(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifiedImages) File(java.io.File) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 ClassifiedImages (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifiedImages)9 ClassifyOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifyOptions)8 File (java.io.File)7 ClassifiedImages (com.ibm.watson.visual_recognition.v3.model.ClassifiedImages)6 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)5 ClassifyOptions (com.ibm.watson.visual_recognition.v3.model.ClassifyOptions)5 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)4 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 Classifier (com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier)2 CreateClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.CreateClassifierOptions)2 MultipartBody (okhttp3.MultipartBody)2 Ignore (org.junit.Ignore)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 DeleteClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.DeleteClassifierOptions)1