Search in sources :

Example 1 with UpdateDialogNodeNullableOptions

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

the class AssistantTest method testUpdateDialogNodeNullableWOptions.

@Test
public void testUpdateDialogNodeNullableWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"dialog_node\": \"dialogNode\", \"description\": \"description\", \"conditions\": \"conditions\", \"parent\": \"parent\", \"previous_sibling\": \"previousSibling\", \"output\": {\"generic\": [{\"response_type\": \"search_skill\", \"query\": \"query\", \"query_type\": \"natural_language\", \"filter\": \"filter\", \"discovery_version\": \"discoveryVersion\", \"channels\": [{\"channel\": \"chat\"}]}], \"integrations\": {\"mapKey\": {\"mapKey\": \"anyValue\"}}, \"modifiers\": {\"overwrite\": false}}, \"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\": true, \"disabled\": true, \"created\": \"2019-01-01T12:00:00\", \"updated\": \"2019-01-01T12:00:00\"}";
    String updateDialogNodeNullablePath = "/v1/workspaces/testString/dialog_nodes/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill
    // model
    DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill dialogNodeOutputGenericModel = new DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill.Builder().responseType("search_skill").query("testString").queryType("natural_language").filter("testString").discoveryVersion("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 UpdateDialogNode model
    UpdateDialogNode updateDialogNodeModel = new UpdateDialogNode.Builder().dialogNode("testString").description("testString").conditions("testString").parent("testString").previousSibling("testString").output(dialogNodeOutputModel).context(dialogNodeContextModel).metadata(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).nextStep(dialogNodeNextStepModel).title("testString").type("standard").eventName("focus").variable("testString").actions(new java.util.ArrayList<DialogNodeAction>(java.util.Arrays.asList(dialogNodeActionModel))).digressIn("not_available").digressOut("allow_returning").digressOutSlots("not_allowed").userLabel("testString").disambiguationOptOut(true).build();
    Map<String, Object> updateDialogNodeModelAsPatch = updateDialogNodeModel.asPatch();
    // Construct an instance of the UpdateDialogNodeNullableOptions model
    UpdateDialogNodeNullableOptions updateDialogNodeNullableOptionsModel = new UpdateDialogNodeNullableOptions.Builder().workspaceId("testString").dialogNode("testString").body(updateDialogNodeModelAsPatch).includeAudit(true).build();
    // Invoke operation with valid options model (positive test)
    Response<DialogNode> response = assistantService.updateDialogNodeNullable(updateDialogNodeNullableOptionsModel).execute();
    assertNotNull(response);
    DialogNode responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(true));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, updateDialogNodeNullablePath);
}
Also used : DialogNodeOutputGeneric(com.ibm.watson.assistant.v1.model.DialogNodeOutputGeneric) HashMap(java.util.HashMap) UpdateDialogNode(com.ibm.watson.assistant.v1.model.UpdateDialogNode) 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) UpdateDialogNodeNullableOptions(com.ibm.watson.assistant.v1.model.UpdateDialogNodeNullableOptions) UpdateDialogNode(com.ibm.watson.assistant.v1.model.UpdateDialogNode) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DialogNodeAction(com.ibm.watson.assistant.v1.model.DialogNodeAction) DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill(com.ibm.watson.assistant.v1.model.DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill) DialogNodeContext(com.ibm.watson.assistant.v1.model.DialogNodeContext) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 2 with UpdateDialogNodeNullableOptions

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

the class Assistant method updateDialogNodeNullable.

/**
 * Update dialog node.
 *
 * <p>Update an existing dialog node with new or modified data.
 *
 * <p>If you want to update multiple dialog nodes with a single API call, consider using the
 * **[Update workspace](#update-workspace)** method instead.
 *
 * @param UpdateDialogNodeNullableOptions the {@link UpdateDialogNodeNullableOptions} containing
 *     the options for the call
 * @return a {@link ServiceCall} with a result of type {@link DialogNode}
 */
public ServiceCall<DialogNode> updateDialogNodeNullable(UpdateDialogNodeNullableOptions UpdateDialogNodeNullableOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(UpdateDialogNodeNullableOptions, "UpdateDialogNodeNullableOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", UpdateDialogNodeNullableOptions.workspaceId());
    pathParamsMap.put("dialog_node", UpdateDialogNodeNullableOptions.dialogNode());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/dialog_nodes/{dialog_node}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "testUpdateDialogNode");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    if (UpdateDialogNodeNullableOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(UpdateDialogNodeNullableOptions.includeAudit()));
    }
    builder.bodyContent(com.ibm.cloud.sdk.core.util.GsonSingleton.getGsonWithSerializeNulls().toJson(UpdateDialogNodeNullableOptions.body()), "application/json");
    ResponseConverter<DialogNode> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DialogNode>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DialogNode(com.ibm.watson.assistant.v1.model.DialogNode)

Aggregations

DialogNode (com.ibm.watson.assistant.v1.model.DialogNode)2 HashMap (java.util.HashMap)2 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 DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill (com.ibm.watson.assistant.v1.model.DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill)1 DialogNodeOutputModifiers (com.ibm.watson.assistant.v1.model.DialogNodeOutputModifiers)1 UpdateDialogNode (com.ibm.watson.assistant.v1.model.UpdateDialogNode)1 UpdateDialogNodeNullableOptions (com.ibm.watson.assistant.v1.model.UpdateDialogNodeNullableOptions)1 Map (java.util.Map)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1