Search in sources :

Example 1 with ListWorkspacesOptions

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

the class AssistantServiceIT method testListWorkspaces.

/**
 * Test listWorkspaces.
 */
@Test
public void testListWorkspaces() {
    ListWorkspacesOptions listOptions = new ListWorkspacesOptions.Builder().build();
    WorkspaceCollection response = service.listWorkspaces(listOptions).execute();
    assertNotNull(response);
    assertNotNull(response.getWorkspaces());
    assertTrue(response.getWorkspaces().size() > 0);
    assertNotNull(response.getPagination());
    assertNotNull(response.getPagination().getRefreshUrl());
    Workspace wResponse = null;
    for (Workspace resp : response.getWorkspaces()) {
        if (resp.getWorkspaceId().equals(workspaceId)) {
            wResponse = resp;
            break;
        }
    }
    assertNotNull(wResponse);
    assertNotNull(wResponse.getName());
}
Also used : ListWorkspacesOptions(com.ibm.watson.developer_cloud.assistant.v1.model.ListWorkspacesOptions) WorkspaceCollection(com.ibm.watson.developer_cloud.assistant.v1.model.WorkspaceCollection) Workspace(com.ibm.watson.developer_cloud.assistant.v1.model.Workspace) Test(org.junit.Test)

Example 2 with ListWorkspacesOptions

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

the class ConversationServiceIT method testListWorkspaces.

/**
 * Test listWorkspaces.
 */
@Test
public void testListWorkspaces() {
    ListWorkspacesOptions listOptions = new ListWorkspacesOptions.Builder().build();
    WorkspaceCollection response = service.listWorkspaces(listOptions).execute();
    assertNotNull(response);
    assertNotNull(response.getWorkspaces());
    assertTrue(response.getWorkspaces().size() > 0);
    assertNotNull(response.getPagination());
    assertNotNull(response.getPagination().getRefreshUrl());
    Workspace wResponse = null;
    for (Workspace resp : response.getWorkspaces()) {
        if (resp.getWorkspaceId().equals(workspaceId)) {
            wResponse = resp;
            break;
        }
    }
    assertNotNull(wResponse);
    assertNotNull(wResponse.getName());
}
Also used : ListWorkspacesOptions(com.ibm.watson.developer_cloud.conversation.v1.model.ListWorkspacesOptions) WorkspaceCollection(com.ibm.watson.developer_cloud.conversation.v1.model.WorkspaceCollection) Workspace(com.ibm.watson.developer_cloud.conversation.v1.model.Workspace) Test(org.junit.Test)

Example 3 with ListWorkspacesOptions

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

the class ConversationServiceIT method testListWorkspacesWithPaging.

/**
 * Test listWorkspaces with paging.
 */
@Test
public void testListWorkspacesWithPaging() {
    ListWorkspacesOptions listOptions = new ListWorkspacesOptions.Builder().pageLimit(1L).sort("-updated").build();
    WorkspaceCollection response = service.listWorkspaces(listOptions).execute();
    assertNotNull(response);
    assertNotNull(response.getPagination());
    assertNotNull(response.getPagination().getRefreshUrl());
    assertNotNull(response.getPagination().getNextUrl());
    assertNotNull(response.getPagination().getCursor());
    boolean found = false;
    while (true) {
        if (response.getPagination().getCursor() == null) {
            break;
        }
        assertNotNull(response.getWorkspaces());
        assertTrue(response.getWorkspaces().size() == 1);
        found |= response.getWorkspaces().get(0).getWorkspaceId().equals(workspaceId);
        String cursor = response.getPagination().getCursor();
        response = service.listWorkspaces(listOptions.newBuilder().cursor(cursor).build()).execute();
    }
    assertTrue(found);
}
Also used : ListWorkspacesOptions(com.ibm.watson.developer_cloud.conversation.v1.model.ListWorkspacesOptions) WorkspaceCollection(com.ibm.watson.developer_cloud.conversation.v1.model.WorkspaceCollection) Test(org.junit.Test)

Example 4 with ListWorkspacesOptions

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

the class AssistantTest method testListWorkspacesWOptions.

// Test the listWorkspaces operation with a valid options model parameter
@Test
public void testListWorkspacesWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"workspaces\": [{\"name\": \"name\", \"description\": \"description\", \"language\": \"language\", \"workspace_id\": \"workspaceId\", \"dialog_nodes\": [{\"dialog_node\": \"dialogNode\", \"description\": \"description\", \"conditions\": \"conditions\", \"parent\": \"parent\", \"previous_sibling\": \"previousSibling\", \"output\": {\"generic\": [{\"response_type\": \"video\", \"source\": \"source\", \"title\": \"title\", \"description\": \"description\", \"channels\": [{\"channel\": \"chat\"}], \"channel_options\": {\"mapKey\": \"anyValue\"}, \"alt_text\": \"altText\"}], \"integrations\": {\"mapKey\": {\"mapKey\": \"anyValue\"}}, \"modifiers\": {\"overwrite\": true}}, \"context\": {\"integrations\": {\"mapKey\": {\"mapKey\": \"anyValue\"}}}, \"metadata\": {\"mapKey\": \"anyValue\"}, \"next_step\": {\"behavior\": \"get_user_input\", \"dialog_node\": \"dialogNode\", \"selector\": \"condition\"}, \"title\": \"title\", \"type\": \"standard\", \"event_name\": \"focus\", \"variable\": \"variable\", \"actions\": [{\"name\": \"name\", \"type\": \"client\", \"parameters\": {\"mapKey\": \"anyValue\"}, \"result_variable\": \"resultVariable\", \"credentials\": \"credentials\"}], \"digress_in\": \"not_available\", \"digress_out\": \"allow_returning\", \"digress_out_slots\": \"not_allowed\", \"user_label\": \"userLabel\", \"disambiguation_opt_out\": false, \"disabled\": true, \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}], \"counterexamples\": [{\"text\": \"text\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"learning_opt_out\": false, \"system_settings\": {\"tooling\": {\"store_generic_responses\": false}, \"disambiguation\": {\"prompt\": \"prompt\", \"none_of_the_above_prompt\": \"noneOfTheAbovePrompt\", \"enabled\": false, \"sensitivity\": \"auto\", \"randomize\": false, \"max_suggestions\": 1, \"suggestion_text_policy\": \"suggestionTextPolicy\"}, \"human_agent_assist\": {\"mapKey\": \"anyValue\"}, \"spelling_suggestions\": false, \"spelling_auto_correct\": false, \"system_entities\": {\"enabled\": false}, \"off_topic\": {\"enabled\": false}}, \"status\": \"Non Existent\", \"webhooks\": [{\"url\": \"url\", \"name\": \"name\", \"headers\": [{\"name\": \"name\", \"value\": \"value\"}]}], \"intents\": [{\"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\"}]}], \"entities\": [{\"entity\": \"entity\", \"description\": \"description\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"fuzzy_match\": true, \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"values\": [{\"value\": \"value\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"type\": \"synonyms\", \"synonyms\": [\"synonym\"], \"patterns\": [\"pattern\"], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}]}]}], \"pagination\": {\"refresh_url\": \"refreshUrl\", \"next_url\": \"nextUrl\", \"total\": 5, \"matched\": 7, \"refresh_cursor\": \"refreshCursor\", \"next_cursor\": \"nextCursor\"}}";
    String listWorkspacesPath = "/v1/workspaces";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListWorkspacesOptions model
    ListWorkspacesOptions listWorkspacesOptionsModel = new ListWorkspacesOptions.Builder().pageLimit(Long.valueOf("26")).includeCount(false).sort("name").cursor("testString").includeAudit(false).build();
    // Invoke listWorkspaces() with a valid options model and verify the result
    Response<WorkspaceCollection> response = assistantService.listWorkspaces(listWorkspacesOptionsModel).execute();
    assertNotNull(response);
    WorkspaceCollection 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, listWorkspacesPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(Long.valueOf(query.get("page_limit")), Long.valueOf("26"));
    assertEquals(Boolean.valueOf(query.get("include_count")), Boolean.valueOf(false));
    assertEquals(query.get("sort"), "name");
    assertEquals(query.get("cursor"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListWorkspacesOptions(com.ibm.watson.assistant.v1.model.ListWorkspacesOptions) WorkspaceCollection(com.ibm.watson.assistant.v1.model.WorkspaceCollection) Test(org.testng.annotations.Test)

Example 5 with ListWorkspacesOptions

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

the class AssistantServiceIT method testListWorkspacesWithPaging.

/**
 * Test listWorkspaces with paging.
 */
@Test
public void testListWorkspacesWithPaging() {
    ListWorkspacesOptions listOptions = new ListWorkspacesOptions.Builder().pageLimit(1L).sort("-updated").build();
    WorkspaceCollection response = service.listWorkspaces(listOptions).execute();
    assertNotNull(response);
    assertNotNull(response.getPagination());
    assertNotNull(response.getPagination().getRefreshUrl());
    assertNotNull(response.getPagination().getNextUrl());
    assertNotNull(response.getPagination().getCursor());
    boolean found = false;
    while (true) {
        if (response.getPagination().getCursor() == null) {
            break;
        }
        assertNotNull(response.getWorkspaces());
        assertTrue(response.getWorkspaces().size() == 1);
        found |= response.getWorkspaces().get(0).getWorkspaceId().equals(workspaceId);
        String cursor = response.getPagination().getCursor();
        response = service.listWorkspaces(listOptions.newBuilder().cursor(cursor).build()).execute();
    }
    assertTrue(found);
}
Also used : ListWorkspacesOptions(com.ibm.watson.developer_cloud.assistant.v1.model.ListWorkspacesOptions) WorkspaceCollection(com.ibm.watson.developer_cloud.assistant.v1.model.WorkspaceCollection) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 WorkspaceCollection (com.ibm.watson.assistant.v1.model.WorkspaceCollection)2 ListWorkspacesOptions (com.ibm.watson.developer_cloud.assistant.v1.model.ListWorkspacesOptions)2 WorkspaceCollection (com.ibm.watson.developer_cloud.assistant.v1.model.WorkspaceCollection)2 ListWorkspacesOptions (com.ibm.watson.developer_cloud.conversation.v1.model.ListWorkspacesOptions)2 WorkspaceCollection (com.ibm.watson.developer_cloud.conversation.v1.model.WorkspaceCollection)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 ListWorkspacesOptions (com.ibm.watson.assistant.v1.model.ListWorkspacesOptions)1 Workspace (com.ibm.watson.developer_cloud.assistant.v1.model.Workspace)1 Workspace (com.ibm.watson.developer_cloud.conversation.v1.model.Workspace)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1