Search in sources :

Example 6 with AddCorpusOptions

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

the class SpeechToTextTest method testAddCorpus.

/**
 * Test add corpus.
 *
 * @throws InterruptedException the interrupted exception
 * @throws IOException the IO exception
 */
@Test
public void testAddCorpus() throws InterruptedException, IOException {
    String id = "foo";
    String corpusName = "cName";
    File corpusFile = new File("src/test/resources/speech_to_text/corpus-text.txt");
    String corpusFileText = new String(Files.readAllBytes(Paths.get(corpusFile.toURI())));
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{}"));
    AddCorpusOptions addOptions = new AddCorpusOptions.Builder().customizationId(id).corpusName(corpusName).corpusFile(corpusFile).corpusFileContentType(HttpMediaType.TEXT_PLAIN).allowOverwrite(true).build();
    service.addCorpus(addOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("POST", request.getMethod());
    assertEquals(String.format(PATH_CORPUS, id, corpusName) + "?allow_overwrite=true", request.getPath());
    assertTrue(request.getBody().readUtf8().contains(corpusFileText));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ByteString(okio.ByteString) AddCorpusOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddCorpusOptions) File(java.io.File) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 7 with AddCorpusOptions

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

the class SpeechToTextIT method testAddCorpusFail.

/**
 * Test add corpus with expected failure.
 */
@Test(expected = IllegalArgumentException.class)
public void testAddCorpusFail() {
    AddCorpusOptions addOptions = new AddCorpusOptions.Builder().corpusName("foo3").customizationId(customizationId).build();
    service.addCorpus(addOptions).execute().getResult();
}
Also used : AddCorpusOptions(com.ibm.watson.speech_to_text.v1.model.AddCorpusOptions) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 8 with AddCorpusOptions

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

the class SpeechToTextTest method testAddCorpusWOptions.

// Test the addCorpus operation with a valid options model parameter
@Test
public void testAddCorpusWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "";
    String addCorpusPath = "/v1/customizations/testString/corpora/testString";
    server.enqueue(new MockResponse().setResponseCode(201).setBody(mockResponseBody));
    // Construct an instance of the AddCorpusOptions model
    AddCorpusOptions addCorpusOptionsModel = new AddCorpusOptions.Builder().customizationId("testString").corpusName("testString").corpusFile(TestUtilities.createMockStream("This is a mock file.")).allowOverwrite(false).build();
    // Invoke addCorpus() with a valid options model and verify the result
    Response<Void> response = speechToTextService.addCorpus(addCorpusOptionsModel).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(), "POST");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, addCorpusPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(Boolean.valueOf(query.get("allow_overwrite")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) AddCorpusOptions(com.ibm.watson.speech_to_text.v1.model.AddCorpusOptions) Test(org.testng.annotations.Test)

Aggregations

File (java.io.File)5 Test (org.junit.Test)5 AddCorpusOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddCorpusOptions)4 AddCorpusOptions (com.ibm.watson.speech_to_text.v1.model.AddCorpusOptions)4 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 AddWordOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddWordOptions)2 Corpora (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Corpora)2 CreateLanguageModelOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateLanguageModelOptions)2 DeleteLanguageModelOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteLanguageModelOptions)2 GetCorpusOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetCorpusOptions)2 LanguageModel (com.ibm.watson.developer_cloud.speech_to_text.v1.model.LanguageModel)2 ListCorporaOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListCorporaOptions)2 ListWordsOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListWordsOptions)2 Words (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Words)2 AddWordOptions (com.ibm.watson.speech_to_text.v1.model.AddWordOptions)2 Corpora (com.ibm.watson.speech_to_text.v1.model.Corpora)2 CreateLanguageModelOptions (com.ibm.watson.speech_to_text.v1.model.CreateLanguageModelOptions)2 DeleteLanguageModelOptions (com.ibm.watson.speech_to_text.v1.model.DeleteLanguageModelOptions)2 GetCorpusOptions (com.ibm.watson.speech_to_text.v1.model.GetCorpusOptions)2