Search in sources :

Example 6 with DeleteDialogNodeOptions

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

the class ConversationServiceIT method testListDialogNodesWithPaging.

/**
 * Test listDialogNodes with pagination.
 */
@Test
public void testListDialogNodesWithPaging() {
    String dialogNodeName1 = "First" + UUID.randomUUID().toString();
    String dialogNodeName2 = "Second" + UUID.randomUUID().toString();
    CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName1).build();
    service.createDialogNode(createOptions).execute();
    service.createDialogNode(createOptions.newBuilder().dialogNode(dialogNodeName2).build()).execute();
    try {
        ListDialogNodesOptions listOptions = new ListDialogNodesOptions.Builder().workspaceId(workspaceId).pageLimit(1L).sort("dialog_node").build();
        DialogNodeCollection response = service.listDialogNodes(listOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getDialogNodes());
        assertNotNull(response.getPagination());
        assertNotNull(response.getPagination().getRefreshUrl());
        assertNotNull(response.getPagination().getNextUrl());
        assertNotNull(response.getPagination().getCursor());
        boolean found1 = false, found2 = false;
        while (true) {
            assertNotNull(response.getDialogNodes());
            assertTrue(response.getDialogNodes().size() == 1);
            found1 |= response.getDialogNodes().get(0).getDialogNodeId().equals(dialogNodeName1);
            found2 |= response.getDialogNodes().get(0).getDialogNodeId().equals(dialogNodeName2);
            // verify sort
            assertTrue(found1 || !found2);
            if (response.getPagination().getCursor() == null) {
                break;
            }
            String cursor = response.getPagination().getCursor();
            response = service.listDialogNodes(listOptions.newBuilder().cursor(cursor).build()).execute();
        }
        assertTrue(found1 && found2);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName1).build();
        service.deleteDialogNode(deleteOptions).execute();
        service.deleteDialogNode(deleteOptions.newBuilder().dialogNode(dialogNodeName2).build()).execute();
    }
}
Also used : DeleteDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteDialogNodeOptions) CreateDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNodeOptions) ListDialogNodesOptions(com.ibm.watson.developer_cloud.conversation.v1.model.ListDialogNodesOptions) DialogNodeCollection(com.ibm.watson.developer_cloud.conversation.v1.model.DialogNodeCollection) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 7 with DeleteDialogNodeOptions

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

the class AssistantServiceIT method testListDialogNodesWithPaging.

/**
 * Test listDialogNodes with pagination.
 */
@Test
public void testListDialogNodesWithPaging() {
    String dialogNodeName1 = "First" + UUID.randomUUID().toString();
    String dialogNodeName2 = "Second" + UUID.randomUUID().toString();
    CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName1).build();
    service.createDialogNode(createOptions).execute();
    service.createDialogNode(createOptions.newBuilder().dialogNode(dialogNodeName2).build()).execute();
    try {
        ListDialogNodesOptions listOptions = new ListDialogNodesOptions.Builder().workspaceId(workspaceId).pageLimit(1L).sort("dialog_node").build();
        DialogNodeCollection response = service.listDialogNodes(listOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getDialogNodes());
        assertNotNull(response.getPagination());
        assertNotNull(response.getPagination().getRefreshUrl());
        assertNotNull(response.getPagination().getNextUrl());
        assertNotNull(response.getPagination().getCursor());
        boolean found1 = false, found2 = false;
        while (true) {
            assertNotNull(response.getDialogNodes());
            assertTrue(response.getDialogNodes().size() == 1);
            found1 |= response.getDialogNodes().get(0).getDialogNodeId().equals(dialogNodeName1);
            found2 |= response.getDialogNodes().get(0).getDialogNodeId().equals(dialogNodeName2);
            // verify sort
            assertTrue(found1 || !found2);
            if (response.getPagination().getCursor() == null) {
                break;
            }
            String cursor = response.getPagination().getCursor();
            response = service.listDialogNodes(listOptions.newBuilder().cursor(cursor).build()).execute();
        }
        assertTrue(found1 && found2);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName1).build();
        service.deleteDialogNode(deleteOptions).execute();
        service.deleteDialogNode(deleteOptions.newBuilder().dialogNode(dialogNodeName2).build()).execute();
    }
}
Also used : DeleteDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteDialogNodeOptions) CreateDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNodeOptions) ListDialogNodesOptions(com.ibm.watson.developer_cloud.assistant.v1.model.ListDialogNodesOptions) DialogNodeCollection(com.ibm.watson.developer_cloud.assistant.v1.model.DialogNodeCollection) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 8 with DeleteDialogNodeOptions

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

the class AssistantServiceIT method testUpdateDialogNode.

/**
 * Test updateDialogNode.
 */
@Test
public void testUpdateDialogNode() {
    String dialogNodeName = "Test" + UUID.randomUUID().toString();
    String dialogNodeDescription = "Description of " + dialogNodeName;
    CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName).description(dialogNodeDescription).build();
    service.createDialogNode(createOptions).execute();
    String dialogNodeName2 = "Test2" + UUID.randomUUID().toString();
    try {
        String dialogNodeDescription2 = "Updated description of " + dialogNodeName;
        UpdateDialogNodeOptions updateOptions = new UpdateDialogNodeOptions.Builder().workspaceId(workspaceId).dialogNode(dialogNodeName).newDialogNode(dialogNodeName2).newDescription(dialogNodeDescription2).build();
        DialogNode response = service.updateDialogNode(updateOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getDialogNodeId());
        assertEquals(response.getDialogNodeId(), dialogNodeName2);
        assertNotNull(response.getDescription());
        assertEquals(response.getDescription(), dialogNodeDescription2);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName2).build();
        service.deleteDialogNode(deleteOptions).execute();
    }
}
Also used : DeleteDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteDialogNodeOptions) CreateDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNodeOptions) DialogNode(com.ibm.watson.developer_cloud.assistant.v1.model.DialogNode) UpdateDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.UpdateDialogNodeOptions) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 9 with DeleteDialogNodeOptions

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

the class AssistantServiceIT method testGetDialogNode.

/**
 * Test getDialogNode.
 */
@Test
public void testGetDialogNode() {
    String dialogNodeName = "Test" + UUID.randomUUID().toString();
    String dialogNodeDescription = "Description of " + dialogNodeName;
    Date start = new Date();
    CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName).description(dialogNodeDescription).build();
    service.createDialogNode(createOptions).execute();
    try {
        GetDialogNodeOptions getOptions = new GetDialogNodeOptions.Builder().workspaceId(workspaceId).dialogNode(dialogNodeName).includeAudit(true).build();
        DialogNode response = service.getDialogNode(getOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getDialogNodeId());
        assertEquals(response.getDialogNodeId(), dialogNodeName);
        assertNotNull(response.getDescription());
        assertEquals(response.getDescription(), dialogNodeDescription);
        assertNotNull(response.getCreated());
        assertNotNull(response.getUpdated());
        Date now = new Date();
        assertTrue(fuzzyBefore(response.getCreated(), now));
        assertTrue(fuzzyAfter(response.getCreated(), start));
        assertTrue(fuzzyBefore(response.getUpdated(), now));
        assertTrue(fuzzyAfter(response.getUpdated(), start));
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName).build();
        service.deleteDialogNode(deleteOptions).execute();
    }
}
Also used : DeleteDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteDialogNodeOptions) GetDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.GetDialogNodeOptions) CreateDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNodeOptions) DialogNode(com.ibm.watson.developer_cloud.assistant.v1.model.DialogNode) Date(java.util.Date) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 10 with DeleteDialogNodeOptions

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

the class ConversationServiceIT method testCreateDialogNode.

/**
 * Test createDialogNode.
 */
@Test
public void testCreateDialogNode() {
    String dialogNodeName = "Test" + UUID.randomUUID().toString();
    String dialogNodeDescription = "Description of " + dialogNodeName;
    CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName).description(dialogNodeDescription).build();
    DialogNode response = service.createDialogNode(createOptions).execute();
    try {
        assertNotNull(response);
        assertNotNull(response.getDialogNodeId());
        assertEquals(response.getDialogNodeId(), dialogNodeName);
        assertNotNull(response.getDescription());
        assertEquals(response.getDescription(), dialogNodeDescription);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName).build();
        service.deleteDialogNode(deleteOptions).execute();
    }
}
Also used : DeleteDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteDialogNodeOptions) CreateDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNodeOptions) DialogNode(com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Aggregations

NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)12 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)12 Test (org.junit.Test)12 CreateDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNodeOptions)6 DeleteDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteDialogNodeOptions)6 CreateDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNodeOptions)6 DeleteDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteDialogNodeOptions)6 DialogNode (com.ibm.watson.developer_cloud.assistant.v1.model.DialogNode)4 DialogNode (com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode)4 Date (java.util.Date)4 DialogNodeCollection (com.ibm.watson.developer_cloud.assistant.v1.model.DialogNodeCollection)2 GetDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.GetDialogNodeOptions)2 ListDialogNodesOptions (com.ibm.watson.developer_cloud.assistant.v1.model.ListDialogNodesOptions)2 DialogNodeCollection (com.ibm.watson.developer_cloud.conversation.v1.model.DialogNodeCollection)2 GetDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.GetDialogNodeOptions)2 ListDialogNodesOptions (com.ibm.watson.developer_cloud.conversation.v1.model.ListDialogNodesOptions)2 UpdateDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.UpdateDialogNodeOptions)1 UpdateDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.UpdateDialogNodeOptions)1