Search in sources :

Example 11 with TranslationResult

use of com.ibm.watson.language_translator.v3.model.TranslationResult in project java-sdk by watson-developer-cloud.

the class LanguageTranslatorTest method testTranslateWOptions.

// Test the translate operation with a valid options model parameter
@Test
public void testTranslateWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"word_count\": 9, \"character_count\": 14, \"detected_language\": \"detectedLanguage\", \"detected_language_confidence\": 0, \"translations\": [{\"translation\": \"translation\"}]}";
    String translatePath = "/v3/translate";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the TranslateOptions model
    TranslateOptions translateOptionsModel = new TranslateOptions.Builder().text(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).modelId("testString").source("testString").target("testString").build();
    // Invoke translate() with a valid options model and verify the result
    Response<TranslationResult> response = languageTranslatorService.translate(translateOptionsModel).execute();
    assertNotNull(response);
    TranslationResult 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, translatePath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "2018-05-01");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) TranslateOptions(com.ibm.watson.language_translator.v3.model.TranslateOptions) TranslationResult(com.ibm.watson.language_translator.v3.model.TranslationResult) Test(org.testng.annotations.Test)

Aggregations

TranslateOptions (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions)6 TranslationResult (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationResult)6 TranslationResult (com.ibm.watson.language_translator.v3.model.TranslationResult)4 Test (org.junit.Test)4 TranslateOptions (com.ibm.watson.language_translator.v3.model.TranslateOptions)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 JsonObject (com.google.gson.JsonObject)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 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 File (java.io.File)2 InputStream (java.io.InputStream)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 TranslationResult (com.ibm.watson.developer_cloud.language_translation.v2.model.TranslationResult)1 LanguageTranslator (com.ibm.watson.developer_cloud.language_translator.v2.LanguageTranslator)1 SynthesizeOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.SynthesizeOptions)1 LanguageTranslator (com.ibm.watson.language_translator.v3.LanguageTranslator)1 SynthesizeOptions (com.ibm.watson.text_to_speech.v1.model.SynthesizeOptions)1