Search in sources :

Example 6 with Utterance

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

the class ToneAnalyzerTest method testGetChatTones.

/**
 * Test to get Chat tones.
 *
 * @throws InterruptedException the interrupted exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void testGetChatTones() throws IOException, InterruptedException {
    String[] users = { "customer", "agent", "customer", "agent" };
    String[] texts = { "My charger isn't working.", "Thanks for reaching out. Can you give me some more detail about the issue?", "I put my charger in my tablet to charge it up last night and it keeps saying it isn't" + " charging. The charging icon comes on, but it stays on even when I take the charger out. " + "Which is ridiculous, it's brand new.", "I'm sorry you're having issues with charging. What kind of charger are you using?" };
    List<Utterance> utterances = new ArrayList<>();
    for (int i = 0; i < texts.length; i++) {
        Utterance utterance = new Utterance.Builder().text(texts[i]).user(users[i]).build();
        utterances.add(utterance);
    }
    ToneChatOptions toneChatOptions = new ToneChatOptions.Builder().utterances(utterances).build();
    UtteranceAnalyses mockResponse = loadFixture(CHAT_FIXTURE, UtteranceAnalyses.class);
    server.enqueue(jsonResponse(mockResponse));
    server.enqueue(jsonResponse(mockResponse));
    server.enqueue(jsonResponse(mockResponse));
    // execute request
    UtteranceAnalyses serviceResponse = service.toneChat(toneChatOptions).execute();
    // first request
    RecordedRequest request = server.takeRequest();
    String path = StringUtils.join(CHAT_TONE_PATH, "?", VERSION_DATE, "=", VERSION_DATE_VALUE);
    assertEquals(path, request.getPath());
    assertNotNull(request.getHeader(HttpHeaders.AUTHORIZATION));
    assertEquals(serviceResponse, mockResponse);
    assertEquals(HttpMediaType.APPLICATION_JSON, request.getHeader(HttpHeaders.ACCEPT));
}
Also used : Utterance(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.Utterance) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ToneChatOptions(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneChatOptions) ArrayList(java.util.ArrayList) UtteranceAnalyses(com.ibm.watson.developer_cloud.tone_analyzer.v3.model.UtteranceAnalyses) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 7 with Utterance

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

the class ToneAnalyzerTest method testToneChatWOptions.

@Test
public void testToneChatWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"utterances_tone\": [{\"utterance_id\": 11, \"utterance_text\": \"utteranceText\", \"tones\": [{\"score\": 5, \"tone_id\": \"excited\", \"tone_name\": \"toneName\"}], \"error\": \"error\"}], \"warning\": \"warning\"}";
    String toneChatPath = "/v3/tone_chat";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the Utterance model
    Utterance utteranceModel = new Utterance.Builder().text("testString").user("testString").build();
    // Construct an instance of the ToneChatOptions model
    ToneChatOptions toneChatOptionsModel = new ToneChatOptions.Builder().utterances(new java.util.ArrayList<Utterance>(java.util.Arrays.asList(utteranceModel))).contentLanguage("en").acceptLanguage("en").build();
    // Invoke operation with valid options model (positive test)
    Response<UtteranceAnalyses> response = toneAnalyzerService.toneChat(toneChatOptionsModel).execute();
    assertNotNull(response);
    UtteranceAnalyses 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");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, toneChatPath);
}
Also used : Utterance(com.ibm.watson.tone_analyzer.v3.model.Utterance) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ToneChatOptions(com.ibm.watson.tone_analyzer.v3.model.ToneChatOptions) UtteranceAnalyses(com.ibm.watson.tone_analyzer.v3.model.UtteranceAnalyses) Test(org.testng.annotations.Test)

Example 8 with Utterance

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

the class ToneAnalyzerIT method testChatExample.

/**
 * Test ChatExample.
 */
@Test
public void testChatExample() {
    String[] texts = { "My charger isn't working.", "Thanks for reaching out. Can you give me some more detail about the issue?", "I put my charger in my tablet to charge it up last night and it keeps saying it isn't" + " charging. The charging icon comes on, but it stays on even when I take the charger out. " + "Which is ridiculous, it's brand new.", "I'm sorry you're having issues with charging. What kind of charger are you using?" };
    List<Utterance> utterances = new ArrayList<>();
    for (int i = 0; i < texts.length; i++) {
        Utterance utterance = new Utterance.Builder().text(texts[i]).user(users[i]).build();
        utterances.add(utterance);
    }
    ToneChatOptions toneChatOptions = new ToneChatOptions.Builder().utterances(utterances).build();
    // Call the service
    UtteranceAnalyses utterancesTone = service.toneChat(toneChatOptions).execute().getResult();
    Assert.assertNotNull(utterancesTone);
// System.out.println(utterancesTone);
}
Also used : Utterance(com.ibm.watson.tone_analyzer.v3.model.Utterance) ToneChatOptions(com.ibm.watson.tone_analyzer.v3.model.ToneChatOptions) ArrayList(java.util.ArrayList) UtteranceAnalyses(com.ibm.watson.tone_analyzer.v3.model.UtteranceAnalyses) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)6 UtteranceAnalyses (com.ibm.watson.tone_analyzer.v3.model.UtteranceAnalyses)5 Test (org.junit.Test)5 ToneChatOptions (com.ibm.watson.tone_analyzer.v3.model.ToneChatOptions)4 Utterance (com.ibm.watson.tone_analyzer.v3.model.Utterance)4 ToneChatOptions (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneChatOptions)3 Utterance (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.Utterance)3 UtteranceAnalyses (com.ibm.watson.developer_cloud.tone_analyzer.v3.model.UtteranceAnalyses)3 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)1 IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.testng.annotations.Test)1