use of com.ibm.watson.visual_recognition.v3.model.Classifiers in project java-sdk by watson-developer-cloud.
the class VisualRecognitionTest method testDeleteClassifierWOptions.
@Test
public void testDeleteClassifierWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "";
String deleteClassifierPath = "/v3/classifiers/testString";
server.enqueue(new MockResponse().setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the DeleteClassifierOptions model
DeleteClassifierOptions deleteClassifierOptionsModel = new DeleteClassifierOptions.Builder().classifierId("testString").build();
// Invoke operation with valid options model (positive test)
Response<Void> response = visualRecognitionService.deleteClassifier(deleteClassifierOptionsModel).execute();
assertNotNull(response);
Void responseObj = response.getResult();
// Response does not have a return type. Check that the result is null.
assertNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "DELETE");
// 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, deleteClassifierPath);
}
use of com.ibm.watson.visual_recognition.v3.model.Classifiers in project java-sdk by watson-developer-cloud.
the class VisualRecognitionTest method testUpdateClassifierWOptions.
@Test
public void testUpdateClassifierWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"classifier_id\": \"classifierId\", \"name\": \"name\", \"owner\": \"owner\", \"status\": \"ready\", \"core_ml_enabled\": false, \"explanation\": \"explanation\", \"created\": \"2019-01-01T12:00:00.000Z\", \"classes\": [{\"class\": \"xClass\"}], \"retrained\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}";
String updateClassifierPath = "/v3/classifiers/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the UpdateClassifierOptions model
UpdateClassifierOptions updateClassifierOptionsModel = new UpdateClassifierOptions.Builder().classifierId("testString").positiveExamples(mockStreamMap).negativeExamples(TestUtilities.createMockStream("This is a mock file.")).negativeExamplesFilename("testString").build();
// Invoke operation with valid options model (positive test)
Response<Classifier> response = visualRecognitionService.updateClassifier(updateClassifierOptionsModel).execute();
assertNotNull(response);
Classifier 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, updateClassifierPath);
}
use of com.ibm.watson.visual_recognition.v3.model.Classifiers 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.Classifiers in project java-sdk by watson-developer-cloud.
the class VisualRecognitionTest method testGetCoreMlModelWOptions.
@Test
public void testGetCoreMlModelWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "This is a mock binary response.";
String getCoreMlModelPath = "/v3/classifiers/testString/core_ml_model";
server.enqueue(new MockResponse().setHeader("Content-type", "application/octet-stream").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetCoreMlModelOptions model
GetCoreMlModelOptions getCoreMlModelOptionsModel = new GetCoreMlModelOptions.Builder().classifierId("testString").build();
// Invoke operation with valid options model (positive test)
Response<InputStream> response = visualRecognitionService.getCoreMlModel(getCoreMlModelOptionsModel).execute();
assertNotNull(response);
InputStream responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// 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, getCoreMlModelPath);
}
use of com.ibm.watson.visual_recognition.v3.model.Classifiers in project java-sdk by watson-developer-cloud.
the class VisualRecognitionIT method testGetCoreMlModel.
/**
* Test getting the Core ML file for a classifier.
*/
@Ignore
@Test
public void testGetCoreMlModel() {
ListClassifiersOptions options = new ListClassifiersOptions.Builder().verbose(true).build();
List<Classifier> classifiers = service.listClassifiers(options).execute().getResult().getClassifiers();
for (Classifier classifier : classifiers) {
if (classifier.isCoreMlEnabled()) {
GetCoreMlModelOptions getCoreMlModelOptions = new GetCoreMlModelOptions.Builder().classifierId(classifier.getClassifierId()).build();
InputStream coreMlFile = service.getCoreMlModel(getCoreMlModelOptions).execute().getResult();
assertNotNull(coreMlFile);
break;
}
}
}
Aggregations