Search in sources :

Example 1 with ToneInput

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

the class ToneAnalyzerTest method testToneWOptions.

@Test
public void testToneWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"document_tone\": {\"tones\": [{\"score\": 5, \"tone_id\": \"toneId\", \"tone_name\": \"toneName\"}], \"tone_categories\": [{\"tones\": [{\"score\": 5, \"tone_id\": \"toneId\", \"tone_name\": \"toneName\"}], \"category_id\": \"categoryId\", \"category_name\": \"categoryName\"}], \"warning\": \"warning\"}, \"sentences_tone\": [{\"sentence_id\": 10, \"text\": \"text\", \"tones\": [{\"score\": 5, \"tone_id\": \"toneId\", \"tone_name\": \"toneName\"}], \"tone_categories\": [{\"tones\": [{\"score\": 5, \"tone_id\": \"toneId\", \"tone_name\": \"toneName\"}], \"category_id\": \"categoryId\", \"category_name\": \"categoryName\"}], \"input_from\": 9, \"input_to\": 7}]}";
    String tonePath = "/v3/tone";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the ToneInput model
    ToneInput toneInputModel = new ToneInput.Builder().text("testString").build();
    // Construct an instance of the ToneOptions model
    ToneOptions toneOptionsModel = new ToneOptions.Builder().toneInput(toneInputModel).sentences(true).tones(new java.util.ArrayList<String>(java.util.Arrays.asList("emotion"))).contentLanguage("en").acceptLanguage("en").build();
    // Invoke operation with valid options model (positive test)
    Response<ToneAnalysis> response = toneAnalyzerService.tone(toneOptionsModel).execute();
    assertNotNull(response);
    ToneAnalysis responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("sentences")), Boolean.valueOf(true));
    assertEquals(query.get("tones"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("emotion")), ","));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, tonePath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ToneAnalysis(com.ibm.watson.tone_analyzer.v3.model.ToneAnalysis) ToneOptions(com.ibm.watson.tone_analyzer.v3.model.ToneOptions) ToneInput(com.ibm.watson.tone_analyzer.v3.model.ToneInput) Test(org.testng.annotations.Test)

Aggregations

ToneAnalysis (com.ibm.watson.tone_analyzer.v3.model.ToneAnalysis)1 ToneInput (com.ibm.watson.tone_analyzer.v3.model.ToneInput)1 ToneOptions (com.ibm.watson.tone_analyzer.v3.model.ToneOptions)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1