Search in sources :

Example 11 with Intent

use of com.ibm.watson.assistant.v1.model.Intent in project java-sdk by watson-developer-cloud.

the class AssistantTest method testUpdateExampleWOptions.

// Test the updateExample operation with a valid options model parameter
@Test
public void testUpdateExampleWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"text\": \"text\", \"mentions\": [{\"entity\": \"entity\", \"location\": [8]}], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}";
    String updateExamplePath = "/v1/workspaces/testString/intents/testString/examples/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the Mention model
    Mention mentionModel = new Mention.Builder().entity("testString").location(new java.util.ArrayList<Long>(java.util.Arrays.asList(Long.valueOf("26")))).build();
    // Construct an instance of the UpdateExampleOptions model
    UpdateExampleOptions updateExampleOptionsModel = new UpdateExampleOptions.Builder().workspaceId("testString").intent("testString").text("testString").newText("testString").newMentions(new java.util.ArrayList<Mention>(java.util.Arrays.asList(mentionModel))).includeAudit(false).build();
    // Invoke updateExample() with a valid options model and verify the result
    Response<Example> response = assistantService.updateExample(updateExampleOptionsModel).execute();
    assertNotNull(response);
    Example 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, updateExamplePath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Mention(com.ibm.watson.assistant.v1.model.Mention) Example(com.ibm.watson.assistant.v1.model.Example) UpdateExampleOptions(com.ibm.watson.assistant.v1.model.UpdateExampleOptions) Test(org.testng.annotations.Test)

Example 12 with Intent

use of com.ibm.watson.assistant.v1.model.Intent in project java-sdk by watson-developer-cloud.

the class AssistantTest method testCreateIntentWOptions.

// Test the createIntent operation with a valid options model parameter
@Test
public void testCreateIntentWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"intent\": \"intent\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"examples\": [{\"text\": \"text\", \"mentions\": [{\"entity\": \"entity\", \"location\": [8]}], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}]}";
    String createIntentPath = "/v1/workspaces/testString/intents";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    // Construct an instance of the Mention model
    Mention mentionModel = new Mention.Builder().entity("testString").location(new java.util.ArrayList<Long>(java.util.Arrays.asList(Long.valueOf("26")))).build();
    // Construct an instance of the Example model
    Example exampleModel = new Example.Builder().text("testString").mentions(new java.util.ArrayList<Mention>(java.util.Arrays.asList(mentionModel))).build();
    // Construct an instance of the CreateIntentOptions model
    CreateIntentOptions createIntentOptionsModel = new CreateIntentOptions.Builder().workspaceId("testString").intent("testString").description("testString").examples(new java.util.ArrayList<Example>(java.util.Arrays.asList(exampleModel))).includeAudit(false).build();
    // Invoke createIntent() with a valid options model and verify the result
    Response<Intent> response = assistantService.createIntent(createIntentOptionsModel).execute();
    assertNotNull(response);
    Intent 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, createIntentPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CreateIntentOptions(com.ibm.watson.assistant.v1.model.CreateIntentOptions) Intent(com.ibm.watson.assistant.v1.model.Intent) RuntimeIntent(com.ibm.watson.assistant.v1.model.RuntimeIntent) CreateIntent(com.ibm.watson.assistant.v1.model.CreateIntent) Mention(com.ibm.watson.assistant.v1.model.Mention) Example(com.ibm.watson.assistant.v1.model.Example) Test(org.testng.annotations.Test)

Example 13 with Intent

use of com.ibm.watson.assistant.v1.model.Intent in project java-sdk by watson-developer-cloud.

the class AssistantTest method testGetExampleWOptions.

// Test the getExample operation with a valid options model parameter
@Test
public void testGetExampleWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"text\": \"text\", \"mentions\": [{\"entity\": \"entity\", \"location\": [8]}], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}";
    String getExamplePath = "/v1/workspaces/testString/intents/testString/examples/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetExampleOptions model
    GetExampleOptions getExampleOptionsModel = new GetExampleOptions.Builder().workspaceId("testString").intent("testString").text("testString").includeAudit(false).build();
    // Invoke getExample() with a valid options model and verify the result
    Response<Example> response = assistantService.getExample(getExampleOptionsModel).execute();
    assertNotNull(response);
    Example 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(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getExamplePath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetExampleOptions(com.ibm.watson.assistant.v1.model.GetExampleOptions) Example(com.ibm.watson.assistant.v1.model.Example) Test(org.testng.annotations.Test)

Example 14 with Intent

use of com.ibm.watson.assistant.v1.model.Intent in project java-sdk by watson-developer-cloud.

the class AssistantTest method testUpdateIntentWOptions.

// Test the updateIntent operation with a valid options model parameter
@Test
public void testUpdateIntentWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"intent\": \"intent\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"examples\": [{\"text\": \"text\", \"mentions\": [{\"entity\": \"entity\", \"location\": [8]}], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}]}";
    String updateIntentPath = "/v1/workspaces/testString/intents/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the Mention model
    Mention mentionModel = new Mention.Builder().entity("testString").location(new java.util.ArrayList<Long>(java.util.Arrays.asList(Long.valueOf("26")))).build();
    // Construct an instance of the Example model
    Example exampleModel = new Example.Builder().text("testString").mentions(new java.util.ArrayList<Mention>(java.util.Arrays.asList(mentionModel))).build();
    // Construct an instance of the UpdateIntentOptions model
    UpdateIntentOptions updateIntentOptionsModel = new UpdateIntentOptions.Builder().workspaceId("testString").intent("testString").newIntent("testString").newDescription("testString").newExamples(new java.util.ArrayList<Example>(java.util.Arrays.asList(exampleModel))).append(false).includeAudit(false).build();
    // Invoke updateIntent() with a valid options model and verify the result
    Response<Intent> response = assistantService.updateIntent(updateIntentOptionsModel).execute();
    assertNotNull(response);
    Intent 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, updateIntentPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("append")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Intent(com.ibm.watson.assistant.v1.model.Intent) RuntimeIntent(com.ibm.watson.assistant.v1.model.RuntimeIntent) CreateIntent(com.ibm.watson.assistant.v1.model.CreateIntent) UpdateIntentOptions(com.ibm.watson.assistant.v1.model.UpdateIntentOptions) Mention(com.ibm.watson.assistant.v1.model.Mention) Example(com.ibm.watson.assistant.v1.model.Example) Test(org.testng.annotations.Test)

Example 15 with Intent

use of com.ibm.watson.assistant.v1.model.Intent in project java-sdk by watson-developer-cloud.

the class AssistantTest method testListLogsWOptions.

// Test the listLogs operation with a valid options model parameter
@Test
public void testListLogsWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"logs\": [{\"request\": {\"input\": {\"text\": \"text\", \"spelling_suggestions\": false, \"spelling_auto_correct\": false, \"suggested_text\": \"suggestedText\", \"original_text\": \"originalText\"}, \"intents\": [{\"intent\": \"intent\", \"confidence\": 10}], \"entities\": [{\"entity\": \"entity\", \"location\": [8], \"value\": \"value\", \"confidence\": 10, \"groups\": [{\"group\": \"group\", \"location\": [8]}], \"interpretation\": {\"calendar_type\": \"calendarType\", \"datetime_link\": \"datetimeLink\", \"festival\": \"festival\", \"granularity\": \"day\", \"range_link\": \"rangeLink\", \"range_modifier\": \"rangeModifier\", \"relative_day\": 11, \"relative_month\": 13, \"relative_week\": 12, \"relative_weekend\": 15, \"relative_year\": 12, \"specific_day\": 11, \"specific_day_of_week\": \"specificDayOfWeek\", \"specific_month\": 13, \"specific_quarter\": 15, \"specific_year\": 12, \"numeric_value\": 12, \"subtype\": \"subtype\", \"part_of_day\": \"partOfDay\", \"relative_hour\": 12, \"relative_minute\": 14, \"relative_second\": 14, \"specific_hour\": 12, \"specific_minute\": 14, \"specific_second\": 14, \"timezone\": \"timezone\"}, \"alternatives\": [{\"value\": \"value\", \"confidence\": 10}], \"role\": {\"type\": \"date_from\"}}], \"alternate_intents\": false, \"context\": {\"conversation_id\": \"conversationId\", \"system\": {\"mapKey\": \"anyValue\"}, \"metadata\": {\"deployment\": \"deployment\", \"user_id\": \"userId\"}}, \"output\": {\"nodes_visited\": [\"nodesVisited\"], \"nodes_visited_details\": [{\"dialog_node\": \"dialogNode\", \"title\": \"title\", \"conditions\": \"conditions\"}], \"log_messages\": [{\"level\": \"info\", \"msg\": \"msg\", \"code\": \"code\", \"source\": {\"type\": \"dialog_node\", \"dialog_node\": \"dialogNode\"}}], \"generic\": [{\"response_type\": \"option\", \"title\": \"title\", \"description\": \"description\", \"preference\": \"dropdown\", \"options\": [{\"label\": \"label\", \"value\": {\"input\": {\"text\": \"text\", \"spelling_suggestions\": false, \"spelling_auto_correct\": false, \"suggested_text\": \"suggestedText\", \"original_text\": \"originalText\"}, \"intents\": [{\"intent\": \"intent\", \"confidence\": 10}], \"entities\": [{\"entity\": \"entity\", \"location\": [8], \"value\": \"value\", \"confidence\": 10, \"groups\": [{\"group\": \"group\", \"location\": [8]}], \"interpretation\": {\"calendar_type\": \"calendarType\", \"datetime_link\": \"datetimeLink\", \"festival\": \"festival\", \"granularity\": \"day\", \"range_link\": \"rangeLink\", \"range_modifier\": \"rangeModifier\", \"relative_day\": 11, \"relative_month\": 13, \"relative_week\": 12, \"relative_weekend\": 15, \"relative_year\": 12, \"specific_day\": 11, \"specific_day_of_week\": \"specificDayOfWeek\", \"specific_month\": 13, \"specific_quarter\": 15, \"specific_year\": 12, \"numeric_value\": 12, \"subtype\": \"subtype\", \"part_of_day\": \"partOfDay\", \"relative_hour\": 12, \"relative_minute\": 14, \"relative_second\": 14, \"specific_hour\": 12, \"specific_minute\": 14, \"specific_second\": 14, \"timezone\": \"timezone\"}, \"alternatives\": [{\"value\": \"value\", \"confidence\": 10}], \"role\": {\"type\": \"date_from\"}}]}}], \"channels\": [{\"channel\": \"chat\"}]}]}, \"actions\": [{\"name\": \"name\", \"type\": \"client\", \"parameters\": {\"mapKey\": \"anyValue\"}, \"result_variable\": \"resultVariable\", \"credentials\": \"credentials\"}], \"user_id\": \"userId\"}, \"response\": {\"input\": {\"text\": \"text\", \"spelling_suggestions\": false, \"spelling_auto_correct\": false, \"suggested_text\": \"suggestedText\", \"original_text\": \"originalText\"}, \"intents\": [{\"intent\": \"intent\", \"confidence\": 10}], \"entities\": [{\"entity\": \"entity\", \"location\": [8], \"value\": \"value\", \"confidence\": 10, \"groups\": [{\"group\": \"group\", \"location\": [8]}], \"interpretation\": {\"calendar_type\": \"calendarType\", \"datetime_link\": \"datetimeLink\", \"festival\": \"festival\", \"granularity\": \"day\", \"range_link\": \"rangeLink\", \"range_modifier\": \"rangeModifier\", \"relative_day\": 11, \"relative_month\": 13, \"relative_week\": 12, \"relative_weekend\": 15, \"relative_year\": 12, \"specific_day\": 11, \"specific_day_of_week\": \"specificDayOfWeek\", \"specific_month\": 13, \"specific_quarter\": 15, \"specific_year\": 12, \"numeric_value\": 12, \"subtype\": \"subtype\", \"part_of_day\": \"partOfDay\", \"relative_hour\": 12, \"relative_minute\": 14, \"relative_second\": 14, \"specific_hour\": 12, \"specific_minute\": 14, \"specific_second\": 14, \"timezone\": \"timezone\"}, \"alternatives\": [{\"value\": \"value\", \"confidence\": 10}], \"role\": {\"type\": \"date_from\"}}], \"alternate_intents\": false, \"context\": {\"conversation_id\": \"conversationId\", \"system\": {\"mapKey\": \"anyValue\"}, \"metadata\": {\"deployment\": \"deployment\", \"user_id\": \"userId\"}}, \"output\": {\"nodes_visited\": [\"nodesVisited\"], \"nodes_visited_details\": [{\"dialog_node\": \"dialogNode\", \"title\": \"title\", \"conditions\": \"conditions\"}], \"log_messages\": [{\"level\": \"info\", \"msg\": \"msg\", \"code\": \"code\", \"source\": {\"type\": \"dialog_node\", \"dialog_node\": \"dialogNode\"}}], \"generic\": [{\"response_type\": \"option\", \"title\": \"title\", \"description\": \"description\", \"preference\": \"dropdown\", \"options\": [{\"label\": \"label\", \"value\": {\"input\": {\"text\": \"text\", \"spelling_suggestions\": false, \"spelling_auto_correct\": false, \"suggested_text\": \"suggestedText\", \"original_text\": \"originalText\"}, \"intents\": [{\"intent\": \"intent\", \"confidence\": 10}], \"entities\": [{\"entity\": \"entity\", \"location\": [8], \"value\": \"value\", \"confidence\": 10, \"groups\": [{\"group\": \"group\", \"location\": [8]}], \"interpretation\": {\"calendar_type\": \"calendarType\", \"datetime_link\": \"datetimeLink\", \"festival\": \"festival\", \"granularity\": \"day\", \"range_link\": \"rangeLink\", \"range_modifier\": \"rangeModifier\", \"relative_day\": 11, \"relative_month\": 13, \"relative_week\": 12, \"relative_weekend\": 15, \"relative_year\": 12, \"specific_day\": 11, \"specific_day_of_week\": \"specificDayOfWeek\", \"specific_month\": 13, \"specific_quarter\": 15, \"specific_year\": 12, \"numeric_value\": 12, \"subtype\": \"subtype\", \"part_of_day\": \"partOfDay\", \"relative_hour\": 12, \"relative_minute\": 14, \"relative_second\": 14, \"specific_hour\": 12, \"specific_minute\": 14, \"specific_second\": 14, \"timezone\": \"timezone\"}, \"alternatives\": [{\"value\": \"value\", \"confidence\": 10}], \"role\": {\"type\": \"date_from\"}}]}}], \"channels\": [{\"channel\": \"chat\"}]}]}, \"actions\": [{\"name\": \"name\", \"type\": \"client\", \"parameters\": {\"mapKey\": \"anyValue\"}, \"result_variable\": \"resultVariable\", \"credentials\": \"credentials\"}], \"user_id\": \"userId\"}, \"log_id\": \"logId\", \"request_timestamp\": \"requestTimestamp\", \"response_timestamp\": \"responseTimestamp\", \"workspace_id\": \"workspaceId\", \"language\": \"language\"}], \"pagination\": {\"next_url\": \"nextUrl\", \"matched\": 7, \"next_cursor\": \"nextCursor\"}}";
    String listLogsPath = "/v1/workspaces/testString/logs";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListLogsOptions model
    ListLogsOptions listLogsOptionsModel = new ListLogsOptions.Builder().workspaceId("testString").sort("testString").filter("testString").pageLimit(Long.valueOf("26")).cursor("testString").build();
    // Invoke listLogs() with a valid options model and verify the result
    Response<LogCollection> response = assistantService.listLogs(listLogsOptionsModel).execute();
    assertNotNull(response);
    LogCollection 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(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, listLogsPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(query.get("sort"), "testString");
    assertEquals(query.get("filter"), "testString");
    assertEquals(Long.valueOf(query.get("page_limit")), Long.valueOf("26"));
    assertEquals(query.get("cursor"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListLogsOptions(com.ibm.watson.assistant.v1.model.ListLogsOptions) LogCollection(com.ibm.watson.assistant.v1.model.LogCollection) Test(org.testng.annotations.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)19 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)19 Test (org.testng.annotations.Test)19 HashMap (java.util.HashMap)11 Example (com.ibm.watson.assistant.v1.model.Example)10 JsonObject (com.google.gson.JsonObject)8 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)8 Intent (com.ibm.watson.assistant.v1.model.Intent)6 Mention (com.ibm.watson.assistant.v1.model.Mention)6 CreateIntent (com.ibm.watson.assistant.v1.model.CreateIntent)5 Intent (com.ibm.watson.developer_cloud.conversation.v1.model.Intent)4 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)4 DialogNodeContext (com.ibm.watson.assistant.v1.model.DialogNodeContext)3 RuntimeIntent (com.ibm.watson.assistant.v1.model.RuntimeIntent)3 Intent (com.ibm.watson.developer_cloud.assistant.v1.model.Intent)3 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)3 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Test (org.junit.Test)3