Search in sources :

Example 1 with DialogNode

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

the class ConversationServiceIT method testListDialogNodes.

/**
 * Test listDialogNodes.
 */
@Test
public void testListDialogNodes() {
    String dialogNodeName = "Test" + UUID.randomUUID().toString();
    try {
        ListDialogNodesOptions listOptions = new ListDialogNodesOptions.Builder(workspaceId).build();
        DialogNodeCollection response = service.listDialogNodes(listOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getDialogNodes());
        assertNotNull(response.getPagination());
        assertNotNull(response.getPagination().getRefreshUrl());
        // nextUrl may be null
        // Now add a dialog node and make sure we get it back
        String dialogNodeDescription = "Description of " + dialogNodeName;
        Date start = new Date();
        CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName).description(dialogNodeDescription).build();
        service.createDialogNode(createOptions).execute();
        long count = response.getDialogNodes().size();
        ListDialogNodesOptions listOptions2 = new ListDialogNodesOptions.Builder(workspaceId).pageLimit(count + 1).includeAudit(true).build();
        DialogNodeCollection response2 = service.listDialogNodes(listOptions2).execute();
        assertNotNull(response2);
        assertNotNull(response2.getDialogNodes());
        List<DialogNode> dialogNodes = response2.getDialogNodes();
        assertTrue(dialogNodes.size() > count);
        DialogNode dialogResponse = null;
        for (DialogNode node : dialogNodes) {
            if (node.getDialogNodeId().equals(dialogNodeName)) {
                dialogResponse = node;
                break;
            }
        }
        assertNotNull(dialogResponse);
        assertNotNull(dialogResponse.getDescription());
        assertEquals(dialogResponse.getDescription(), dialogNodeDescription);
        Date now = new Date();
        assertTrue(fuzzyBefore(dialogResponse.getCreated(), now));
        assertTrue(fuzzyAfter(dialogResponse.getCreated(), start));
        assertTrue(fuzzyBefore(dialogResponse.getUpdated(), now));
        assertTrue(fuzzyAfter(dialogResponse.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 : 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) DialogNode(com.ibm.watson.developer_cloud.conversation.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) DeleteDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteDialogNodeOptions) Test(org.junit.Test)

Example 2 with DialogNode

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

the class ConversationServiceIT 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.conversation.v1.model.DeleteDialogNodeOptions) CreateDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNodeOptions) DialogNode(com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode) UpdateDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.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 3 with DialogNode

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

the class Conversation method getDialogNode.

/**
 * Get dialog node.
 *
 * Get information about a dialog node.
 *
 * @param getDialogNodeOptions the {@link GetDialogNodeOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link DialogNode}
 */
public ServiceCall<DialogNode> getDialogNode(GetDialogNodeOptions getDialogNodeOptions) {
    Validator.notNull(getDialogNodeOptions, "getDialogNodeOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "dialog_nodes" };
    String[] pathParameters = { getDialogNodeOptions.workspaceId(), getDialogNodeOptions.dialogNode() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    if (getDialogNodeOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(getDialogNodeOptions.includeAudit()));
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DialogNode.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) DialogNode(com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode)

Example 4 with DialogNode

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

the class AssistantServiceIT 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.assistant.v1.model.DeleteDialogNodeOptions) CreateDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNodeOptions) DialogNode(com.ibm.watson.developer_cloud.assistant.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)

Example 5 with DialogNode

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

the class AssistantServiceIT method testListDialogNodes.

/**
 * Test listDialogNodes.
 */
@Test
public void testListDialogNodes() {
    String dialogNodeName = "Test" + UUID.randomUUID().toString();
    try {
        ListDialogNodesOptions listOptions = new ListDialogNodesOptions.Builder(workspaceId).build();
        DialogNodeCollection response = service.listDialogNodes(listOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getDialogNodes());
        assertNotNull(response.getPagination());
        assertNotNull(response.getPagination().getRefreshUrl());
        // nextUrl may be null
        // Now add a dialog node and make sure we get it back
        String dialogNodeDescription = "Description of " + dialogNodeName;
        Date start = new Date();
        CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName).description(dialogNodeDescription).build();
        service.createDialogNode(createOptions).execute();
        long count = response.getDialogNodes().size();
        ListDialogNodesOptions listOptions2 = new ListDialogNodesOptions.Builder(workspaceId).pageLimit(count + 1).includeAudit(true).build();
        DialogNodeCollection response2 = service.listDialogNodes(listOptions2).execute();
        assertNotNull(response2);
        assertNotNull(response2.getDialogNodes());
        List<DialogNode> dialogNodes = response2.getDialogNodes();
        assertTrue(dialogNodes.size() > count);
        DialogNode dialogResponse = null;
        for (DialogNode node : dialogNodes) {
            if (node.getDialogNodeId().equals(dialogNodeName)) {
                dialogResponse = node;
                break;
            }
        }
        assertNotNull(dialogResponse);
        assertNotNull(dialogResponse.getDescription());
        assertEquals(dialogResponse.getDescription(), dialogNodeDescription);
        Date now = new Date();
        assertTrue(fuzzyBefore(dialogResponse.getCreated(), now));
        assertTrue(fuzzyAfter(dialogResponse.getCreated(), start));
        assertTrue(fuzzyBefore(dialogResponse.getUpdated(), now));
        assertTrue(fuzzyAfter(dialogResponse.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 : 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) 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) DeleteDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteDialogNodeOptions) Test(org.junit.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)13 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)13 Test (org.testng.annotations.Test)13 DialogNode (com.ibm.watson.assistant.v1.model.DialogNode)10 HashMap (java.util.HashMap)10 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)8 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)8 Test (org.junit.Test)8 DialogNode (com.ibm.watson.developer_cloud.assistant.v1.model.DialogNode)7 DialogNode (com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode)7 JsonObject (com.google.gson.JsonObject)6 DialogNodeContext (com.ibm.watson.assistant.v1.model.DialogNodeContext)6 DialogNodeAction (com.ibm.watson.assistant.v1.model.DialogNodeAction)5 DialogNodeNextStep (com.ibm.watson.assistant.v1.model.DialogNodeNextStep)5 DialogNodeOutput (com.ibm.watson.assistant.v1.model.DialogNodeOutput)5 DialogNodeOutputGeneric (com.ibm.watson.assistant.v1.model.DialogNodeOutputGeneric)5 DialogNodeOutputModifiers (com.ibm.watson.assistant.v1.model.DialogNodeOutputModifiers)5 ResponseGenericChannel (com.ibm.watson.assistant.v1.model.ResponseGenericChannel)5 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)5 Map (java.util.Map)5