use of com.ibm.watson.assistant.v2.model.MessageOptions in project java-sdk by watson-developer-cloud.
the class ConversationTest method testSendMessage.
/**
* Test send message.
*
* @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
@Test
public void testSendMessage() throws IOException, InterruptedException {
String text = "I'd like to get insurance to for my home";
MessageResponse mockResponse = loadFixture(FIXTURE, MessageResponse.class);
server.enqueue(jsonResponse(mockResponse));
InputData input = new InputData.Builder(text).build();
RuntimeIntent intent = new RuntimeIntent();
intent.setIntent("turn_off");
intent.setConfidence(0.0);
RuntimeEntity entity = new RuntimeEntity();
entity.setEntity("car");
entity.setValue("ford");
MessageOptions options = new MessageOptions.Builder(WORKSPACE_ID).input(input).addIntent(intent).addEntity(entity).alternateIntents(true).build();
// execute first request
MessageResponse serviceResponse = service.message(options).execute();
// first request
RecordedRequest request = server.takeRequest();
String path = StringUtils.join(PATH_MESSAGE, "?", VERSION, "=2018-02-16");
assertEquals(path, request.getPath());
assertArrayEquals(new String[] { "Do you want to get a quote?" }, serviceResponse.getOutput().getText().toArray(new String[0]));
assertEquals(request.getMethod(), "POST");
assertNotNull(request.getHeader(HttpHeaders.AUTHORIZATION));
String expected = "{" + "\"input\":{\"text\":\"I'd like to get insurance to for my home\"}," + "\"intents\":[{\"confidence\":0.0,\"intent\":\"turn_off\"}]," + "\"entities\":[{\"value\":\"ford\",\"entity\":\"car\"}]," + "\"alternate_intents\":true" + "}";
JsonParser parser = new JsonParser();
JsonObject expectedObj = parser.parse(expected).getAsJsonObject();
JsonObject actualObj = parser.parse(request.getBody().readUtf8()).getAsJsonObject();
assertTrue(expectedObj.equals(actualObj));
assertEquals(serviceResponse, mockResponse);
}
use of com.ibm.watson.assistant.v2.model.MessageOptions in project java-sdk by watson-developer-cloud.
the class ConversationTest method testSendMessageWithNullWorkspaceId.
/**
* Negative - Test message with null workspace id.
*
* @throws InterruptedException the interrupted exception
*/
@Test(expected = IllegalArgumentException.class)
public void testSendMessageWithNullWorkspaceId() throws InterruptedException {
String text = "I'd like to get insurance to for my home";
InputData input = new InputData.Builder(text).build();
MessageOptions options = new MessageOptions.Builder().input(input).alternateIntents(true).build();
service.message(options).execute();
}
use of com.ibm.watson.assistant.v2.model.MessageOptions in project java-sdk by watson-developer-cloud.
the class ConversationTest method testSendMessageWithAlternateIntents.
/**
* Test send message. use some different MessageOptions options like context and other public methods
*
* @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
@Test
public void testSendMessageWithAlternateIntents() throws IOException, InterruptedException {
MessageResponse mockResponse = loadFixture(FIXTURE, MessageResponse.class);
server.enqueue(jsonResponse(mockResponse));
Context contextTemp = new Context();
contextTemp.put("name", "Myname");
InputData inputTemp = new InputData.Builder("My text").build();
MessageOptions options = new MessageOptions.Builder(WORKSPACE_ID).input(inputTemp).alternateIntents(false).context(contextTemp).entities(null).intents(null).build();
// execute first request
MessageResponse serviceResponse = service.message(options).execute();
// first request
RecordedRequest request = server.takeRequest();
String path = StringUtils.join(PATH_MESSAGE, "?", VERSION, "=2018-02-16");
assertEquals(path, request.getPath());
assertArrayEquals(new String[] { "Do you want to get a quote?" }, serviceResponse.getOutput().getText().toArray(new String[0]));
assertEquals(request.getMethod(), "POST");
assertNotNull(request.getHeader(HttpHeaders.AUTHORIZATION));
assertEquals("{\"input\":{\"text\":\"My text\"},\"alternate_intents\":false," + "\"context\":{\"name\":\"Myname\"}}", request.getBody().readUtf8());
assertEquals(serviceResponse, mockResponse);
}
use of com.ibm.watson.assistant.v2.model.MessageOptions in project java-sdk by watson-developer-cloud.
the class AssistantServiceIT method pingBadCredentialsThrowsException.
@Test(expected = UnauthorizedException.class)
public void pingBadCredentialsThrowsException() {
Assistant badService = new Assistant("2018-02-16", "foo", "bar");
MessageOptions options = new MessageOptions.Builder(workspaceId).build();
badService.message(options).execute();
}
use of com.ibm.watson.assistant.v2.model.MessageOptions in project java-sdk by watson-developer-cloud.
the class AssistantServiceIT method testStartAConversationWithoutMessage.
/**
* Test start a conversation without message.
*/
@Test()
public void testStartAConversationWithoutMessage() {
MessageOptions options = new MessageOptions.Builder(workspaceId).build();
service.message(options).execute();
}
Aggregations