use of com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneChatOptions 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));
}
use of com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneChatOptions 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);
}
use of com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneChatOptions 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);
}
Aggregations