Search in sources :

Example 6 with UpdateDialogNodeOptions

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

the class AssistantTest method testUpdateDialogNodeWOptions.

// Test the updateDialogNode operation with a valid options model parameter
@Test
public void testUpdateDialogNodeWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"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\"}";
    String updateDialogNodePath = "/v1/workspaces/testString/dialog_nodes/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ResponseGenericChannel model
    ResponseGenericChannel responseGenericChannelModel = new ResponseGenericChannel.Builder().channel("chat").build();
    // Construct an instance of the DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo model
    DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo dialogNodeOutputGenericModel = new DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo.Builder().responseType("video").source("testString").title("testString").description("testString").channels(new java.util.ArrayList<ResponseGenericChannel>(java.util.Arrays.asList(responseGenericChannelModel))).channelOptions(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).altText("testString").build();
    // Construct an instance of the DialogNodeOutputModifiers model
    DialogNodeOutputModifiers dialogNodeOutputModifiersModel = new DialogNodeOutputModifiers.Builder().overwrite(true).build();
    // Construct an instance of the DialogNodeOutput model
    DialogNodeOutput dialogNodeOutputModel = new DialogNodeOutput.Builder().generic(new java.util.ArrayList<DialogNodeOutputGeneric>(java.util.Arrays.asList(dialogNodeOutputGenericModel))).integrations(new java.util.HashMap<String, Map<String, Object>>() {

        {
            put("foo", new java.util.HashMap<String, Object>() {

                {
                    put("foo", "testString");
                }
            });
        }
    }).modifiers(dialogNodeOutputModifiersModel).add("foo", "testString").build();
    // Construct an instance of the DialogNodeContext model
    DialogNodeContext dialogNodeContextModel = new DialogNodeContext.Builder().integrations(new java.util.HashMap<String, Map<String, Object>>() {

        {
            put("foo", new java.util.HashMap<String, Object>() {

                {
                    put("foo", "testString");
                }
            });
        }
    }).add("foo", "testString").build();
    // Construct an instance of the DialogNodeNextStep model
    DialogNodeNextStep dialogNodeNextStepModel = new DialogNodeNextStep.Builder().behavior("get_user_input").dialogNode("testString").selector("condition").build();
    // Construct an instance of the DialogNodeAction model
    DialogNodeAction dialogNodeActionModel = new DialogNodeAction.Builder().name("testString").type("client").parameters(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).resultVariable("testString").credentials("testString").build();
    // Construct an instance of the UpdateDialogNodeOptions model
    UpdateDialogNodeOptions updateDialogNodeOptionsModel = new UpdateDialogNodeOptions.Builder().workspaceId("testString").dialogNode("testString").newDialogNode("testString").newDescription("testString").newConditions("testString").newParent("testString").newPreviousSibling("testString").newOutput(dialogNodeOutputModel).newContext(dialogNodeContextModel).newMetadata(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).newNextStep(dialogNodeNextStepModel).newTitle("testString").newType("standard").newEventName("focus").newVariable("testString").newActions(new java.util.ArrayList<DialogNodeAction>(java.util.Arrays.asList(dialogNodeActionModel))).newDigressIn("not_available").newDigressOut("allow_returning").newDigressOutSlots("not_allowed").newUserLabel("testString").newDisambiguationOptOut(false).includeAudit(false).build();
    // Invoke updateDialogNode() with a valid options model and verify the result
    Response<DialogNode> response = assistantService.updateDialogNode(updateDialogNodeOptionsModel).execute();
    assertNotNull(response);
    DialogNode 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, updateDialogNodePath);
    // 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 : DialogNodeOutputGeneric(com.ibm.watson.assistant.v1.model.DialogNodeOutputGeneric) HashMap(java.util.HashMap) ResponseGenericChannel(com.ibm.watson.assistant.v1.model.ResponseGenericChannel) DialogNode(com.ibm.watson.assistant.v1.model.DialogNode) DialogNodeOutput(com.ibm.watson.assistant.v1.model.DialogNodeOutput) DialogNodeNextStep(com.ibm.watson.assistant.v1.model.DialogNodeNextStep) DialogNodeOutputModifiers(com.ibm.watson.assistant.v1.model.DialogNodeOutputModifiers) DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo(com.ibm.watson.assistant.v1.model.DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DialogNodeAction(com.ibm.watson.assistant.v1.model.DialogNodeAction) DialogNodeContext(com.ibm.watson.assistant.v1.model.DialogNodeContext) Map(java.util.Map) HashMap(java.util.HashMap) UpdateDialogNodeOptions(com.ibm.watson.assistant.v1.model.UpdateDialogNodeOptions) Test(org.testng.annotations.Test)

Aggregations

Test (org.junit.Test)4 DialogNode (com.ibm.watson.assistant.v1.model.DialogNode)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 UpdateDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.UpdateDialogNodeOptions)2 UpdateDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.UpdateDialogNodeOptions)2 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)2 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)2 HashMap (java.util.HashMap)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 DialogNodeAction (com.ibm.watson.assistant.v1.model.DialogNodeAction)1 DialogNodeContext (com.ibm.watson.assistant.v1.model.DialogNodeContext)1 DialogNodeNextStep (com.ibm.watson.assistant.v1.model.DialogNodeNextStep)1 DialogNodeOutput (com.ibm.watson.assistant.v1.model.DialogNodeOutput)1 DialogNodeOutputGeneric (com.ibm.watson.assistant.v1.model.DialogNodeOutputGeneric)1 DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo (com.ibm.watson.assistant.v1.model.DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo)1 DialogNodeOutputModifiers (com.ibm.watson.assistant.v1.model.DialogNodeOutputModifiers)1 ResponseGenericChannel (com.ibm.watson.assistant.v1.model.ResponseGenericChannel)1 UpdateDialogNodeOptions (com.ibm.watson.assistant.v1.model.UpdateDialogNodeOptions)1 CreateDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNodeOptions)1