Search in sources :

Example 1 with CustomWord

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

the class SpeechToTextTest method testAddWords.

/**
 * Test add words.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testAddWords() throws InterruptedException, FileNotFoundException {
    String id = "foo";
    Word newWord = loadFixture("src/test/resources/speech_to_text/word.json", Word.class);
    Map<String, Object> wordsAsMap = new HashMap<String, Object>();
    wordsAsMap.put("words", new Word[] { newWord });
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{}"));
    CustomWord word = new CustomWord();
    word.setWord(newWord.getWord());
    word.setDisplayAs(newWord.getDisplayAs());
    word.setSoundsLike(newWord.getSoundsLike());
    AddWordsOptions addOptions = new AddWordsOptions.Builder().customizationId(id).addWords(word).build();
    service.addWords(addOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("POST", request.getMethod());
    assertEquals(String.format(PATH_WORDS, id), request.getPath());
    assertEquals(GSON.toJson(wordsAsMap), request.getBody().readUtf8());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CustomWord(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CustomWord) Word(com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word) AddWordsOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddWordsOptions) HashMap(java.util.HashMap) CustomWord(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CustomWord) JsonObject(com.google.gson.JsonObject) ByteString(okio.ByteString) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

JsonObject (com.google.gson.JsonObject)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 AddWordsOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddWordsOptions)1 CustomWord (com.ibm.watson.developer_cloud.speech_to_text.v1.model.CustomWord)1 Word (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 ByteString (okio.ByteString)1 Test (org.junit.Test)1