VisualRecognition extends BaseService { public ServiceCall<ClassifiedImages> classify(ClassifyOptions classifyOptions) { com.ibm.cloud.sdk.core.util.Validator.notNull( classifyOptions, "classifyOptions cannot be null"); com.ibm.cloud.sdk.core.util.Validator.isTrue( (classifyOptions.imagesFile() != null) || (classifyOptions.url() != null) || (classifyOptions.threshold() != null) || (classifyOptions.owners() != null) || (classifyOptions.classifierIds() != null), "At least one of imagesFile, url, threshold, owners, or classifierIds must be supplied."); String[] pathSegments = {"v3/classify"}; RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getServiceUrl(), pathSegments)); builder.query("version", versionDate); Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v3", "classify"); for (Entry<String, String> header : sdkHeaders.entrySet()) { builder.header(header.getKey(), header.getValue()); } builder.header("Accept", "application/json"); if (classifyOptions.acceptLanguage() != null) { builder.header("Accept-Language", classifyOptions.acceptLanguage()); } MultipartBody.Builder multipartBuilder = new MultipartBody.Builder(); multipartBuilder.setType(MultipartBody.FORM); if (classifyOptions.imagesFile() != null) { okhttp3.RequestBody imagesFileBody = RequestUtils.inputStreamBody( classifyOptions.imagesFile(), classifyOptions.imagesFileContentType()); multipartBuilder.addFormDataPart( "images_file", classifyOptions.imagesFilename(), imagesFileBody); } if (classifyOptions.url() != null) { multipartBuilder.addFormDataPart("url", classifyOptions.url()); } if (classifyOptions.threshold() != null) { multipartBuilder.addFormDataPart("threshold", String.valueOf(classifyOptions.threshold())); } if (classifyOptions.owners() != null) { multipartBuilder.addFormDataPart("owners", RequestUtils.join(classifyOptions.owners(), ",")); } if (classifyOptions.classifierIds() != null) { multipartBuilder.addFormDataPart( "classifier_ids", RequestUtils.join(classifyOptions.classifierIds(), ",")); } builder.body(multipartBuilder.build()); ResponseConverter<ClassifiedImages> responseConverter = ResponseConverterUtils.getValue( new com.google.gson.reflect.TypeToken<ClassifiedImages>() {}.getType()); return createServiceCall(builder.build(), responseConverter); } VisualRecognition(String versionDate);  VisualRecognition(String versionDate, Authenticator authenticator);  VisualRecognition(String versionDate, String serviceName);  VisualRecognition(String versionDate, String serviceName, Authenticator authenticator); ServiceCall<ClassifiedImages> classify(ClassifyOptions classifyOptions); ServiceCall<ClassifiedImages> classify(); ServiceCall<Classifier> createClassifier(CreateClassifierOptions createClassifierOptions); ServiceCall<Classifiers> listClassifiers(ListClassifiersOptions listClassifiersOptions); ServiceCall<Classifiers> listClassifiers(); ServiceCall<Classifier> getClassifier(GetClassifierOptions getClassifierOptions); ServiceCall<Classifier> updateClassifier(UpdateClassifierOptions updateClassifierOptions); ServiceCall<Void> deleteClassifier(DeleteClassifierOptions deleteClassifierOptions); ServiceCall<InputStream> getCoreMlModel(GetCoreMlModelOptions getCoreMlModelOptions); ServiceCall<Void> deleteUserData(DeleteUserDataOptions deleteUserDataOptions);  }
@Test public void testClassifyWithFile() throws IOException, InterruptedException { ClassifiedImages mockResponse = loadFixture(FIXTURE_CLASSIFICATION, ClassifiedImages.class); server.enqueue(new MockResponse().setBody(mockResponse.toString())); File images = new File(IMAGE_FILE); ClassifyOptions options = new ClassifyOptions.Builder() .imagesFile(images) .classifierIds(Collections.singletonList("car")) .build(); ClassifiedImages serviceResponse = service.classify(options).execute().getResult(); RecordedRequest request = server.takeRequest(); String path = PATH_CLASSIFY + "?" + VERSION_KEY + "=" + VERSION; assertEquals(path, request.getPath()); assertEquals("POST", request.getMethod()); assertEquals(serviceResponse, mockResponse); }
@Test public void testClassifyWithBytes() throws IOException, InterruptedException { ClassifiedImages mockResponse = loadFixture(FIXTURE_CLASSIFICATION, ClassifiedImages.class); server.enqueue(new MockResponse().setBody(mockResponse.toString())); File images = new File(SINGLE_IMAGE_FILE); InputStream fileStream = new FileInputStream(images); ClassifyOptions options = new ClassifyOptions.Builder() .imagesFile(fileStream) .imagesFilename(FILENAME) .classifierIds(Collections.singletonList("car")) .build(); ClassifiedImages serviceResponse = service.classify(options).execute().getResult(); RecordedRequest request = server.takeRequest(); String path = PATH_CLASSIFY + "?" + VERSION_KEY + "=" + VERSION; assertEquals(path, request.getPath()); assertEquals("POST", request.getMethod()); assertEquals(serviceResponse, mockResponse); }