Search in sources :

Example 1 with DeleteJobOptions

use of com.ibm.watson.speech_to_text.v1.model.DeleteJobOptions in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testDeleteJob.

/**
 * Test delete job.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testDeleteJob() throws InterruptedException {
    String id = "foo";
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{}"));
    DeleteJobOptions deleteOptions = new DeleteJobOptions.Builder().id(id).build();
    service.deleteJob(deleteOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("DELETE", request.getMethod());
    assertEquals(String.format(PATH_RECOGNITION, id), request.getPath());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteJobOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteJobOptions) ByteString(okio.ByteString) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 2 with DeleteJobOptions

use of com.ibm.watson.speech_to_text.v1.model.DeleteJobOptions in project java-sdk by watson-developer-cloud.

the class SpeechToTextIT method testCreateJobWarning.

/**
 * Test create job with a warning message.
 *
 * <p>This test is currently being ignored as it has a very long runtime and causes Travis to
 * timeout. The ignore annotation can be removed to test this locally.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Ignore
@Test
public void testCreateJobWarning() throws InterruptedException, FileNotFoundException {
    File audio = new File(SAMPLE_WAV);
    CreateJobOptions createOptions = new CreateJobOptions.Builder().audio(audio).contentType(HttpMediaType.AUDIO_WAV).userToken("job").build();
    RecognitionJob job = service.createJob(createOptions).execute().getResult();
    try {
        assertNotNull(job.getId());
        assertNotNull(job.getWarnings());
        CheckJobOptions checkOptions = new CheckJobOptions.Builder().id(job.getId()).build();
        for (int x = 0; x < 30 && !Objects.equals(job.getStatus(), RecognitionJob.Status.COMPLETED); x++) {
            Thread.sleep(3000);
            job = service.checkJob(checkOptions).execute().getResult();
        }
        job = service.checkJob(checkOptions).execute().getResult();
        assertEquals(RecognitionJob.Status.COMPLETED, job.getStatus());
        assertNotNull(job.getResults());
    } finally {
        DeleteJobOptions deleteOptions = new DeleteJobOptions.Builder().id(job.getId()).build();
        service.deleteJob(deleteOptions).execute();
    }
}
Also used : RecognitionJob(com.ibm.watson.speech_to_text.v1.model.RecognitionJob) CheckJobOptions(com.ibm.watson.speech_to_text.v1.model.CheckJobOptions) CreateJobOptions(com.ibm.watson.speech_to_text.v1.model.CreateJobOptions) DeleteJobOptions(com.ibm.watson.speech_to_text.v1.model.DeleteJobOptions) File(java.io.File) Ignore(org.junit.Ignore) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 3 with DeleteJobOptions

use of com.ibm.watson.speech_to_text.v1.model.DeleteJobOptions in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testDeleteJobWOptions.

// Test the deleteJob operation with a valid options model parameter
@Test
public void testDeleteJobWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "";
    String deleteJobPath = "/v1/recognitions/testString";
    server.enqueue(new MockResponse().setResponseCode(204).setBody(mockResponseBody));
    // Construct an instance of the DeleteJobOptions model
    DeleteJobOptions deleteJobOptionsModel = new DeleteJobOptions.Builder().id("testString").build();
    // Invoke deleteJob() with a valid options model and verify the result
    Response<Void> response = speechToTextService.deleteJob(deleteJobOptionsModel).execute();
    assertNotNull(response);
    Void responseObj = response.getResult();
    assertNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "DELETE");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, deleteJobPath);
    // Verify that there is no query string
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteJobOptions(com.ibm.watson.speech_to_text.v1.model.DeleteJobOptions) Test(org.testng.annotations.Test)

Example 4 with DeleteJobOptions

use of com.ibm.watson.speech_to_text.v1.model.DeleteJobOptions in project java-sdk by watson-developer-cloud.

the class SpeechToTextIT method testCreateJobWarning.

/**
 * Test create job with a warning message.
 *
 * This test is currently being ignored as it has a very long runtime and causes Travis to timeout.
 * The ignore annotation can be removed to test this locally.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Ignore
@Test
public void testCreateJobWarning() throws InterruptedException, FileNotFoundException {
    File audio = new File(SAMPLE_WAV);
    CreateJobOptions createOptions = new CreateJobOptions.Builder().audio(audio).contentType(CreateJobOptions.ContentType.AUDIO_WAV).userToken("job").build();
    RecognitionJob job = service.createJob(createOptions).execute();
    try {
        assertNotNull(job.getId());
        assertNotNull(job.getWarnings());
        CheckJobOptions checkOptions = new CheckJobOptions.Builder().id(job.getId()).build();
        for (int x = 0; x < 30 && job.getStatus() != RecognitionJob.Status.COMPLETED; x++) {
            Thread.sleep(3000);
            job = service.checkJob(checkOptions).execute();
        }
        job = service.checkJob(checkOptions).execute();
        assertEquals(RecognitionJob.Status.COMPLETED, job.getStatus());
        assertNotNull(job.getResults());
    } finally {
        DeleteJobOptions deleteOptions = new DeleteJobOptions.Builder().id(job.getId()).build();
        service.deleteJob(deleteOptions).execute();
    }
}
Also used : RecognitionJob(com.ibm.watson.developer_cloud.speech_to_text.v1.model.RecognitionJob) CheckJobOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CheckJobOptions) CreateJobOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateJobOptions) DeleteJobOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteJobOptions) File(java.io.File) Ignore(org.junit.Ignore) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 5 with DeleteJobOptions

use of com.ibm.watson.speech_to_text.v1.model.DeleteJobOptions in project java-sdk by watson-developer-cloud.

the class SpeechToTextIT method testCreateJob.

/**
 * Test create job.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testCreateJob() throws InterruptedException, FileNotFoundException {
    File audio = new File(SAMPLE_WAV);
    Long maxAlternatives = 3L;
    Float wordAlternativesThreshold = 0.5f;
    CreateJobOptions createOptions = new CreateJobOptions.Builder().audio(audio).contentType(CreateJobOptions.ContentType.AUDIO_WAV).maxAlternatives(maxAlternatives).wordAlternativesThreshold(wordAlternativesThreshold).build();
    RecognitionJob job = service.createJob(createOptions).execute();
    try {
        assertNotNull(job.getId());
        CheckJobOptions checkOptions = new CheckJobOptions.Builder().id(job.getId()).build();
        for (int x = 0; x < 30 && !job.getStatus().equals(RecognitionJob.Status.COMPLETED); x++) {
            Thread.sleep(3000);
            job = service.checkJob(checkOptions).execute();
        }
        job = service.checkJob(checkOptions).execute();
        assertEquals(RecognitionJob.Status.COMPLETED, job.getStatus());
        assertNotNull(job.getResults());
        assertTrue(job.getResults().get(0).getResults().get(0).getAlternatives().size() <= maxAlternatives);
        List<WordAlternativeResults> wordAlternatives = job.getResults().get(0).getResults().get(0).getWordAlternatives();
        for (WordAlternativeResults alternativeResults : wordAlternatives) {
            assertTrue(alternativeResults.getAlternatives().get(0).getConfidence() >= wordAlternativesThreshold);
        }
    } finally {
        DeleteJobOptions deleteOptions = new DeleteJobOptions.Builder().id(job.getId()).build();
        service.deleteJob(deleteOptions).execute();
    }
}
Also used : RecognitionJob(com.ibm.watson.developer_cloud.speech_to_text.v1.model.RecognitionJob) CheckJobOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CheckJobOptions) CreateJobOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateJobOptions) DeleteJobOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteJobOptions) WordAlternativeResults(com.ibm.watson.developer_cloud.speech_to_text.v1.model.WordAlternativeResults) File(java.io.File) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 File (java.io.File)4 DeleteJobOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteJobOptions)3 DeleteJobOptions (com.ibm.watson.speech_to_text.v1.model.DeleteJobOptions)3 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 CheckJobOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.CheckJobOptions)2 CreateJobOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateJobOptions)2 RecognitionJob (com.ibm.watson.developer_cloud.speech_to_text.v1.model.RecognitionJob)2 CheckJobOptions (com.ibm.watson.speech_to_text.v1.model.CheckJobOptions)2 CreateJobOptions (com.ibm.watson.speech_to_text.v1.model.CreateJobOptions)2 RecognitionJob (com.ibm.watson.speech_to_text.v1.model.RecognitionJob)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Ignore (org.junit.Ignore)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 WordAlternativeResults (com.ibm.watson.developer_cloud.speech_to_text.v1.model.WordAlternativeResults)1 WordAlternativeResults (com.ibm.watson.speech_to_text.v1.model.WordAlternativeResults)1 ByteString (okio.ByteString)1 Test (org.testng.annotations.Test)1