Search in sources :

Example 1 with GetCoreMlModelOptions

use of com.ibm.watson.visual_recognition.v3.model.GetCoreMlModelOptions in project java-sdk by watson-developer-cloud.

the class VisualRecognitionTest method testGetCoreMlModel.

@Test
public void testGetCoreMlModel() throws IOException, InterruptedException {
    final File model = new File("src/test/resources/visual_recognition/custom_model.mlmodel");
    final Buffer buffer = new Buffer().write(Files.toByteArray(model));
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_OCTET_STREAM).setBody(buffer));
    String classifierId = "classifier_id";
    GetCoreMlModelOptions options = new GetCoreMlModelOptions.Builder().classifierId(classifierId).build();
    InputStream modelFile = service.getCoreMlModel(options).execute();
    RecordedRequest request = server.takeRequest();
    String path = String.format(PATH_CORE_ML, classifierId) + "?" + VERSION_DATE + "=2016-05-20&api_key=" + API_KEY;
    assertEquals(path, request.getPath());
    assertEquals("GET", request.getMethod());
    writeInputStreamToFile(modelFile, new File("build/model_result.mlmodel"));
}
Also used : Buffer(okio.Buffer) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) GetCoreMlModelOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetCoreMlModelOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 2 with GetCoreMlModelOptions

use of com.ibm.watson.visual_recognition.v3.model.GetCoreMlModelOptions 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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) InputStream(java.io.InputStream) GetCoreMlModelOptions(com.ibm.watson.visual_recognition.v3.model.GetCoreMlModelOptions) Test(org.testng.annotations.Test)

Example 3 with GetCoreMlModelOptions

use of com.ibm.watson.visual_recognition.v3.model.GetCoreMlModelOptions 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;
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ListClassifiersOptions(com.ibm.watson.visual_recognition.v3.model.ListClassifiersOptions) Classifier(com.ibm.watson.visual_recognition.v3.model.Classifier) GetCoreMlModelOptions(com.ibm.watson.visual_recognition.v3.model.GetCoreMlModelOptions) Ignore(org.junit.Ignore) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 4 with GetCoreMlModelOptions

use of com.ibm.watson.visual_recognition.v3.model.GetCoreMlModelOptions 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().getClassifiers();
    for (Classifier classifier : classifiers) {
        if (classifier.isCoreMlEnabled()) {
            GetCoreMlModelOptions getCoreMlModelOptions = new GetCoreMlModelOptions.Builder().classifierId(classifier.getClassifierId()).build();
            InputStream coreMlFile = service.getCoreMlModel(getCoreMlModelOptions).execute();
            assertNotNull(coreMlFile);
            break;
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ListClassifiersOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ListClassifiersOptions) Classifier(com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier) GetCoreMlModelOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetCoreMlModelOptions) Ignore(org.junit.Ignore) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)4 FileInputStream (java.io.FileInputStream)3 Test (org.junit.Test)3 GetCoreMlModelOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetCoreMlModelOptions)2 GetCoreMlModelOptions (com.ibm.watson.visual_recognition.v3.model.GetCoreMlModelOptions)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Ignore (org.junit.Ignore)2 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)1 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 Classifier (com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier)1 ListClassifiersOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ListClassifiersOptions)1 Classifier (com.ibm.watson.visual_recognition.v3.model.Classifier)1 ListClassifiersOptions (com.ibm.watson.visual_recognition.v3.model.ListClassifiersOptions)1 File (java.io.File)1 Buffer (okio.Buffer)1 Test (org.testng.annotations.Test)1