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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations