VisualRecognition extends BaseService { public ServiceCall<Classifier> createClassifier(CreateClassifierOptions createClassifierOptions) { com.ibm.cloud.sdk.core.util.Validator.notNull( createClassifierOptions, "createClassifierOptions cannot be null"); String[] pathSegments = {"v3/classifiers"}; RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getServiceUrl(), pathSegments)); builder.query("version", versionDate); Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v3", "createClassifier"); 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("name", createClassifierOptions.name()); for (Map.Entry<String, InputStream> entry : createClassifierOptions.positiveExamples().entrySet()) { String partName = String.format("%s_positive_examples", entry.getKey()); okhttp3.RequestBody part = RequestUtils.inputStreamBody(entry.getValue(), "application/octet-stream"); multipartBuilder.addFormDataPart(partName, entry.getKey() + ".zip", part); } if (createClassifierOptions.negativeExamples() != null) { okhttp3.RequestBody negativeExamplesBody = RequestUtils.inputStreamBody( createClassifierOptions.negativeExamples(), "application/octet-stream"); String negativeExamplesFilename = createClassifierOptions.negativeExamplesFilename(); if (!negativeExamplesFilename.contains(".")) { negativeExamplesFilename += ".zip"; } multipartBuilder.addFormDataPart( "negative_examples", negativeExamplesFilename, negativeExamplesBody); } builder.body(multipartBuilder.build()); ResponseConverter<Classifier> responseConverter = ResponseConverterUtils.getValue( new com.google.gson.reflect.TypeToken<Classifier>() {}.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 testCreateClassifier() throws IOException, InterruptedException { Classifier mockResponse = loadFixture(FIXTURE_CLASSIFIER, Classifier.class); server.enqueue(new MockResponse().setBody(mockResponse.toString())); File positiveImages = new File(IMAGE_FILE); File negativeImages = new File(IMAGE_FILE); String class1 = "class1"; CreateClassifierOptions options = new CreateClassifierOptions.Builder() .name(class1) .addPositiveExamples(class1, positiveImages) .negativeExamples(negativeImages) .build(); Classifier serviceResponse = service.createClassifier(options).execute().getResult(); RecordedRequest request = server.takeRequest(); String path = PATH_CLASSIFIERS + "?" + VERSION_KEY + "=" + VERSION; assertEquals(path, request.getPath()); assertEquals("POST", request.getMethod()); String body = request.getBody().readUtf8(); String contentDisposition = "Content-Disposition: form-data; name=\"class1_positive_examples\";"; assertTrue(body.contains(contentDisposition)); assertTrue(body.contains("Content-Disposition: form-data; name=\"name\"")); assertEquals(serviceResponse, mockResponse); }