VisualRecognition extends BaseService { public ServiceCall<AnalyzeResponse> analyze(AnalyzeOptions analyzeOptions) { com.ibm.cloud.sdk.core.util.Validator.notNull(analyzeOptions, "analyzeOptions cannot be null"); String[] pathSegments = {"v4/analyze"}; RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getServiceUrl(), pathSegments)); builder.query("version", versionDate); Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "analyze"); for (Entry<String, String> header : sdkHeaders.entrySet()) { builder.header(header.getKey(), header.getValue()); } builder.header("Accept", "application/json"); MultipartBody.Builder multipartBuilder = new MultipartBody.Builder(); multipartBuilder.setType(MultipartBody.FORM); multipartBuilder.addFormDataPart( "collection_ids", RequestUtils.join(analyzeOptions.collectionIds(), ",")); multipartBuilder.addFormDataPart("features", RequestUtils.join(analyzeOptions.features(), ",")); if (analyzeOptions.imagesFile() != null) { for (FileWithMetadata item : analyzeOptions.imagesFile()) { okhttp3.RequestBody itemBody = RequestUtils.inputStreamBody(item.data(), item.contentType()); multipartBuilder.addFormDataPart("images_file", item.filename(), itemBody); } } if (analyzeOptions.imageUrl() != null) { for (String item : analyzeOptions.imageUrl()) { multipartBuilder.addFormDataPart("image_url", item); } } if (analyzeOptions.threshold() != null) { multipartBuilder.addFormDataPart("threshold", String.valueOf(analyzeOptions.threshold())); } builder.body(multipartBuilder.build()); ResponseConverter<AnalyzeResponse> responseConverter = ResponseConverterUtils.getValue( new com.google.gson.reflect.TypeToken<AnalyzeResponse>() {}.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<AnalyzeResponse> analyze(AnalyzeOptions analyzeOptions); ServiceCall<Collection> createCollection(CreateCollectionOptions createCollectionOptions); ServiceCall<Collection> createCollection(); ServiceCall<CollectionsList> listCollections(
      ListCollectionsOptions listCollectionsOptions); ServiceCall<CollectionsList> listCollections(); ServiceCall<Collection> getCollection(GetCollectionOptions getCollectionOptions); ServiceCall<Collection> updateCollection(UpdateCollectionOptions updateCollectionOptions); ServiceCall<Void> deleteCollection(DeleteCollectionOptions deleteCollectionOptions); ServiceCall<InputStream> getModelFile(GetModelFileOptions getModelFileOptions); ServiceCall<ImageDetailsList> addImages(AddImagesOptions addImagesOptions); ServiceCall<ImageSummaryList> listImages(ListImagesOptions listImagesOptions); ServiceCall<ImageDetails> getImageDetails(GetImageDetailsOptions getImageDetailsOptions); ServiceCall<Void> deleteImage(DeleteImageOptions deleteImageOptions); ServiceCall<InputStream> getJpegImage(GetJpegImageOptions getJpegImageOptions); ServiceCall<ObjectMetadataList> listObjectMetadata(
      ListObjectMetadataOptions listObjectMetadataOptions); ServiceCall<UpdateObjectMetadata> updateObjectMetadata(
      UpdateObjectMetadataOptions updateObjectMetadataOptions); ServiceCall<ObjectMetadata> getObjectMetadata(
      GetObjectMetadataOptions getObjectMetadataOptions); ServiceCall<Void> deleteObject(DeleteObjectOptions deleteObjectOptions); ServiceCall<Collection> train(TrainOptions trainOptions); ServiceCall<TrainingDataObjects> addImageTrainingData(
      AddImageTrainingDataOptions addImageTrainingDataOptions); ServiceCall<TrainingEvents> getTrainingUsage(
      GetTrainingUsageOptions getTrainingUsageOptions); ServiceCall<TrainingEvents> getTrainingUsage(); ServiceCall<Void> deleteUserData(DeleteUserDataOptions deleteUserDataOptions);  }
@Test public void testAnalyze() { server.enqueue(jsonResponse(analyzeResponse)); AnalyzeOptions options = new AnalyzeOptions.Builder() .addCollectionIds(COLLECTION_ID) .addFeatures(AnalyzeOptions.Features.OBJECTS) .addImagesFile(fileWithMetadata) .addImageUrl(IMAGE_URL) .threshold(THRESHOLD) .build(); AnalyzeResponse response = service.analyze(options).execute().getResult(); assertEquals(IMAGE_TYPE, response.getImages().get(0).getSource().getType()); assertEquals(FILENAME, response.getImages().get(0).getSource().getFilename()); assertEquals(ARCHIVE_FILENAME, response.getImages().get(0).getSource().getArchiveFilename()); assertEquals(SOURCE_URL, response.getImages().get(0).getSource().getSourceUrl()); assertEquals(RESOLVED_URL, response.getImages().get(0).getSource().getResolvedUrl()); assertEquals(HEIGHT, response.getImages().get(0).getDimensions().getHeight()); assertEquals(WIDTH, response.getImages().get(0).getDimensions().getWidth()); assertEquals( COLLECTION_ID, response.getImages().get(0).getObjects().getCollections().get(0).getCollectionId()); assertEquals( OBJECT, response .getImages() .get(0) .getObjects() .getCollections() .get(0) .getObjects() .get(0) .getObject()); assertEquals( TOP, response .getImages() .get(0) .getObjects() .getCollections() .get(0) .getObjects() .get(0) .getLocation() .top()); assertEquals( LEFT, response .getImages() .get(0) .getObjects() .getCollections() .get(0) .getObjects() .get(0) .getLocation() .left()); assertEquals( WIDTH, response .getImages() .get(0) .getObjects() .getCollections() .get(0) .getObjects() .get(0) .getLocation() .width()); assertEquals( HEIGHT, response .getImages() .get(0) .getObjects() .getCollections() .get(0) .getObjects() .get(0) .getLocation() .height()); assertEquals( SCORE, response .getImages() .get(0) .getObjects() .getCollections() .get(0) .getObjects() .get(0) .getScore()); assertEquals(CODE, response.getImages().get(0).getErrors().get(0).getCode()); assertEquals(MESSAGE, response.getImages().get(0).getErrors().get(0).getMessage()); assertEquals(MORE_INFO, response.getImages().get(0).getErrors().get(0).getMoreInfo()); assertEquals(ERROR_TYPE, response.getImages().get(0).getErrors().get(0).getTarget().getType()); assertEquals(NAME, response.getImages().get(0).getErrors().get(0).getTarget().getName()); assertEquals(CODE, response.getWarnings().get(0).getCode()); assertEquals(MESSAGE, response.getWarnings().get(0).getMessage()); assertEquals(MORE_INFO, response.getWarnings().get(0).getMoreInfo()); assertEquals(TRACE, response.getTrace()); }