use of com.ibm.watson.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());
}
use of com.ibm.watson.speech_to_text.v1.model.CustomWord in project java-sdk by watson-developer-cloud.
the class SpeechToTextTest method testAddWordsWOptions.
// Test the addWords operation with a valid options model parameter
@Test
public void testAddWordsWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "";
String addWordsPath = "/v1/customizations/testString/words";
server.enqueue(new MockResponse().setResponseCode(201).setBody(mockResponseBody));
// Construct an instance of the CustomWord model
CustomWord customWordModel = new CustomWord.Builder().word("testString").soundsLike(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).displayAs("testString").build();
// Construct an instance of the AddWordsOptions model
AddWordsOptions addWordsOptionsModel = new AddWordsOptions.Builder().customizationId("testString").words(new java.util.ArrayList<CustomWord>(java.util.Arrays.asList(customWordModel))).build();
// Invoke addWords() with a valid options model and verify the result
Response<Void> response = speechToTextService.addWords(addWordsOptionsModel).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, addWordsPath);
// Verify that there is no query string
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
}
Aggregations