Search in sources :

Example 1 with BulkClassifyUtterance

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

the class AssistantTest method testBulkClassifyWOptions.

// Test the bulkClassify operation with a valid options model parameter
@Test
public void testBulkClassifyWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"output\": [{\"input\": {\"text\": \"text\"}, \"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\"}}], \"intents\": [{\"intent\": \"intent\", \"confidence\": 10}]}]}";
    String bulkClassifyPath = "/v2/skills/testString/workspace/bulk_classify";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the BulkClassifyUtterance model
    BulkClassifyUtterance bulkClassifyUtteranceModel = new BulkClassifyUtterance.Builder().text("testString").build();
    // Construct an instance of the BulkClassifyOptions model
    BulkClassifyOptions bulkClassifyOptionsModel = new BulkClassifyOptions.Builder().skillId("testString").input(new java.util.ArrayList<BulkClassifyUtterance>(java.util.Arrays.asList(bulkClassifyUtteranceModel))).build();
    // Invoke bulkClassify() with a valid options model and verify the result
    Response<BulkClassifyResponse> response = assistantService.bulkClassify(bulkClassifyOptionsModel).execute();
    assertNotNull(response);
    BulkClassifyResponse 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, bulkClassifyPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
}
Also used : BulkClassifyOptions(com.ibm.watson.assistant.v2.model.BulkClassifyOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) BulkClassifyResponse(com.ibm.watson.assistant.v2.model.BulkClassifyResponse) BulkClassifyUtterance(com.ibm.watson.assistant.v2.model.BulkClassifyUtterance) Test(org.testng.annotations.Test)

Example 2 with BulkClassifyUtterance

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

the class AssistantTest method testBulkClassifyWOptions.

// Test the bulkClassify operation with a valid options model parameter
@Test
public void testBulkClassifyWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"output\": [{\"input\": {\"text\": \"text\"}, \"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\"}}], \"intents\": [{\"intent\": \"intent\", \"confidence\": 10}]}]}";
    String bulkClassifyPath = "/v1/workspaces/testString/bulk_classify";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the BulkClassifyUtterance model
    BulkClassifyUtterance bulkClassifyUtteranceModel = new BulkClassifyUtterance.Builder().text("testString").build();
    // Construct an instance of the BulkClassifyOptions model
    BulkClassifyOptions bulkClassifyOptionsModel = new BulkClassifyOptions.Builder().workspaceId("testString").input(new java.util.ArrayList<BulkClassifyUtterance>(java.util.Arrays.asList(bulkClassifyUtteranceModel))).build();
    // Invoke bulkClassify() with a valid options model and verify the result
    Response<BulkClassifyResponse> response = assistantService.bulkClassify(bulkClassifyOptionsModel).execute();
    assertNotNull(response);
    BulkClassifyResponse 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, bulkClassifyPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
}
Also used : BulkClassifyOptions(com.ibm.watson.assistant.v1.model.BulkClassifyOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) BulkClassifyResponse(com.ibm.watson.assistant.v1.model.BulkClassifyResponse) BulkClassifyUtterance(com.ibm.watson.assistant.v1.model.BulkClassifyUtterance) Test(org.testng.annotations.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Test (org.testng.annotations.Test)2 BulkClassifyOptions (com.ibm.watson.assistant.v1.model.BulkClassifyOptions)1 BulkClassifyResponse (com.ibm.watson.assistant.v1.model.BulkClassifyResponse)1 BulkClassifyUtterance (com.ibm.watson.assistant.v1.model.BulkClassifyUtterance)1 BulkClassifyOptions (com.ibm.watson.assistant.v2.model.BulkClassifyOptions)1 BulkClassifyResponse (com.ibm.watson.assistant.v2.model.BulkClassifyResponse)1 BulkClassifyUtterance (com.ibm.watson.assistant.v2.model.BulkClassifyUtterance)1