Search in sources :

Example 16 with Translation

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

the class TextToSpeechTest method testListVoicesWOptions.

// Test the listVoices operation with a valid options model parameter
@Test
public void testListVoicesWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"voices\": [{\"url\": \"url\", \"gender\": \"gender\", \"name\": \"name\", \"language\": \"language\", \"description\": \"description\", \"customizable\": true, \"supported_features\": {\"custom_pronunciation\": false, \"voice_transformation\": false}, \"customization\": {\"customization_id\": \"customizationId\", \"name\": \"name\", \"language\": \"language\", \"owner\": \"owner\", \"created\": \"created\", \"last_modified\": \"lastModified\", \"description\": \"description\", \"words\": [{\"word\": \"word\", \"translation\": \"translation\", \"part_of_speech\": \"Dosi\"}], \"prompts\": [{\"prompt\": \"prompt\", \"prompt_id\": \"promptId\", \"status\": \"status\", \"error\": \"error\", \"speaker_id\": \"speakerId\"}]}}]}";
    String listVoicesPath = "/v1/voices";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListVoicesOptions model
    ListVoicesOptions listVoicesOptionsModel = new ListVoicesOptions();
    // Invoke listVoices() with a valid options model and verify the result
    Response<Voices> response = textToSpeechService.listVoices(listVoicesOptionsModel).execute();
    assertNotNull(response);
    Voices responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, listVoicesPath);
    // 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) ListVoicesOptions(com.ibm.watson.text_to_speech.v1.model.ListVoicesOptions) Voices(com.ibm.watson.text_to_speech.v1.model.Voices) Test(org.testng.annotations.Test)

Example 17 with Translation

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

the class TextToSpeechTest method testCreateCustomModelWOptions.

// Test the createCustomModel operation with a valid options model parameter
@Test
public void testCreateCustomModelWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"customization_id\": \"customizationId\", \"name\": \"name\", \"language\": \"language\", \"owner\": \"owner\", \"created\": \"created\", \"last_modified\": \"lastModified\", \"description\": \"description\", \"words\": [{\"word\": \"word\", \"translation\": \"translation\", \"part_of_speech\": \"Dosi\"}], \"prompts\": [{\"prompt\": \"prompt\", \"prompt_id\": \"promptId\", \"status\": \"status\", \"error\": \"error\", \"speaker_id\": \"speakerId\"}]}";
    String createCustomModelPath = "/v1/customizations";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    // Construct an instance of the CreateCustomModelOptions model
    CreateCustomModelOptions createCustomModelOptionsModel = new CreateCustomModelOptions.Builder().name("testString").language("en-US").description("testString").build();
    // Invoke createCustomModel() with a valid options model and verify the result
    Response<CustomModel> response = textToSpeechService.createCustomModel(createCustomModelOptionsModel).execute();
    assertNotNull(response);
    CustomModel responseObj = response.getResult();
    assertNotNull(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, createCustomModelPath);
    // 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) CreateCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions) CustomModel(com.ibm.watson.text_to_speech.v1.model.CustomModel) Test(org.testng.annotations.Test)

Example 18 with Translation

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

the class TextToSpeechTest method testUpdateCustomModelWOptions.

// Test the updateCustomModel operation with a valid options model parameter
@Test
public void testUpdateCustomModelWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "";
    String updateCustomModelPath = "/v1/customizations/testString";
    server.enqueue(new MockResponse().setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the Word model
    Word wordModel = new Word.Builder().word("testString").translation("testString").partOfSpeech("Dosi").build();
    // Construct an instance of the UpdateCustomModelOptions model
    UpdateCustomModelOptions updateCustomModelOptionsModel = new UpdateCustomModelOptions.Builder().customizationId("testString").name("testString").description("testString").words(new java.util.ArrayList<Word>(java.util.Arrays.asList(wordModel))).build();
    // Invoke updateCustomModel() with a valid options model and verify the result
    Response<Void> response = textToSpeechService.updateCustomModel(updateCustomModelOptionsModel).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, updateCustomModelPath);
    // 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) Word(com.ibm.watson.text_to_speech.v1.model.Word) UpdateCustomModelOptions(com.ibm.watson.text_to_speech.v1.model.UpdateCustomModelOptions) Test(org.testng.annotations.Test)

Example 19 with Translation

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

the class TextToSpeechTest method testGetWordWOptions.

// Test the getWord operation with a valid options model parameter
@Test
public void testGetWordWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"translation\": \"translation\", \"part_of_speech\": \"Dosi\"}";
    String getWordPath = "/v1/customizations/testString/words/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetWordOptions model
    GetWordOptions getWordOptionsModel = new GetWordOptions.Builder().customizationId("testString").word("testString").build();
    // Invoke getWord() with a valid options model and verify the result
    Response<Translation> response = textToSpeechService.getWord(getWordOptionsModel).execute();
    assertNotNull(response);
    Translation responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getWordPath);
    // 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) Translation(com.ibm.watson.text_to_speech.v1.model.Translation) GetWordOptions(com.ibm.watson.text_to_speech.v1.model.GetWordOptions) Test(org.testng.annotations.Test)

Aggregations

RecordedRequest (okhttp3.mockwebserver.RecordedRequest)11 MockResponse (okhttp3.mockwebserver.MockResponse)10 Test (org.testng.annotations.Test)10 Translation (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Translation)5 GetWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetWordOptions)4 Word (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word)4 AddWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordsOptions)3 CustomModel (com.ibm.watson.text_to_speech.v1.model.CustomModel)3 Translation (com.ibm.watson.text_to_speech.v1.model.Translation)3 Word (com.ibm.watson.text_to_speech.v1.model.Word)3 File (java.io.File)3 InputStream (java.io.InputStream)3 Test (org.junit.Test)3 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)2 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)2 IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 AddWordOptions (com.ibm.watson.text_to_speech.v1.model.AddWordOptions)2 AddWordsOptions (com.ibm.watson.text_to_speech.v1.model.AddWordsOptions)2 CreateCustomModelOptions (com.ibm.watson.text_to_speech.v1.model.CreateCustomModelOptions)2