Skip to content

Commit 9718770

Browse files
committed
test(assistant-v1): add unit tests for updateDialogNodeNullable
1 parent 0dc76aa commit 9718770

File tree

3 files changed

+598
-0
lines changed

3 files changed

+598
-0
lines changed

assistant/src/test/java/com/ibm/watson/assistant/v1/AssistantTest.java

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
import com.ibm.watson.assistant.v1.model.Synonym;
102102
import com.ibm.watson.assistant.v1.model.SynonymCollection;
103103
import com.ibm.watson.assistant.v1.model.UpdateCounterexampleOptions;
104+
import com.ibm.watson.assistant.v1.model.UpdateDialogNode;
105+
import com.ibm.watson.assistant.v1.model.UpdateDialogNodeNullableOptions;
104106
import com.ibm.watson.assistant.v1.model.UpdateDialogNodeOptions;
105107
import com.ibm.watson.assistant.v1.model.UpdateEntityOptions;
106108
import com.ibm.watson.assistant.v1.model.UpdateExampleOptions;
@@ -3767,6 +3769,175 @@ public void testListAllLogsNoOptions() throws Throwable {
37673769
assistantService.listAllLogs(null).execute();
37683770
}
37693771

3772+
@Test
3773+
public void testUpdateDialogNodeNullableWOptions() throws Throwable {
3774+
// Schedule some responses.
3775+
String mockResponseBody =
3776+
"{\"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\"}";
3777+
String updateDialogNodeNullablePath = "/v1/workspaces/testString/dialog_nodes/testString";
3778+
3779+
server.enqueue(
3780+
new MockResponse()
3781+
.setHeader("Content-type", "application/json")
3782+
.setResponseCode(200)
3783+
.setBody(mockResponseBody));
3784+
3785+
constructClientService();
3786+
3787+
// Construct an instance of the DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill
3788+
// model
3789+
DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill dialogNodeOutputGenericModel =
3790+
new DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill.Builder()
3791+
.responseType("search_skill")
3792+
.query("testString")
3793+
.queryType("natural_language")
3794+
.filter("testString")
3795+
.discoveryVersion("testString")
3796+
.build();
3797+
3798+
// Construct an instance of the DialogNodeOutputModifiers model
3799+
DialogNodeOutputModifiers dialogNodeOutputModifiersModel =
3800+
new DialogNodeOutputModifiers.Builder().overwrite(true).build();
3801+
3802+
// Construct an instance of the DialogNodeOutput model
3803+
DialogNodeOutput dialogNodeOutputModel =
3804+
new DialogNodeOutput.Builder()
3805+
.generic(
3806+
new java.util.ArrayList<DialogNodeOutputGeneric>(
3807+
java.util.Arrays.asList(dialogNodeOutputGenericModel)))
3808+
.integrations(
3809+
new java.util.HashMap<String, Map<String, Object>>() {
3810+
{
3811+
put(
3812+
"foo",
3813+
new java.util.HashMap<String, Object>() {
3814+
{
3815+
put("foo", "testString");
3816+
}
3817+
});
3818+
}
3819+
})
3820+
.modifiers(dialogNodeOutputModifiersModel)
3821+
.add("foo", "testString")
3822+
.build();
3823+
3824+
// Construct an instance of the DialogNodeContext model
3825+
DialogNodeContext dialogNodeContextModel =
3826+
new DialogNodeContext.Builder()
3827+
.integrations(
3828+
new java.util.HashMap<String, Map<String, Object>>() {
3829+
{
3830+
put(
3831+
"foo",
3832+
new java.util.HashMap<String, Object>() {
3833+
{
3834+
put("foo", "testString");
3835+
}
3836+
});
3837+
}
3838+
})
3839+
.add("foo", "testString")
3840+
.build();
3841+
3842+
// Construct an instance of the DialogNodeNextStep model
3843+
DialogNodeNextStep dialogNodeNextStepModel =
3844+
new DialogNodeNextStep.Builder()
3845+
.behavior("get_user_input")
3846+
.dialogNode("testString")
3847+
.selector("condition")
3848+
.build();
3849+
3850+
// Construct an instance of the DialogNodeAction model
3851+
DialogNodeAction dialogNodeActionModel =
3852+
new DialogNodeAction.Builder()
3853+
.name("testString")
3854+
.type("client")
3855+
.parameters(
3856+
new java.util.HashMap<String, Object>() {
3857+
{
3858+
put("foo", "testString");
3859+
}
3860+
})
3861+
.resultVariable("testString")
3862+
.credentials("testString")
3863+
.build();
3864+
3865+
// Construct an instance of the UpdateDialogNode model
3866+
UpdateDialogNode updateDialogNodeModel =
3867+
new UpdateDialogNode.Builder()
3868+
.dialogNode("testString")
3869+
.description("testString")
3870+
.conditions("testString")
3871+
.parent("testString")
3872+
.previousSibling("testString")
3873+
.output(dialogNodeOutputModel)
3874+
.context(dialogNodeContextModel)
3875+
.metadata(
3876+
new java.util.HashMap<String, Object>() {
3877+
{
3878+
put("foo", "testString");
3879+
}
3880+
})
3881+
.nextStep(dialogNodeNextStepModel)
3882+
.title("testString")
3883+
.type("standard")
3884+
.eventName("focus")
3885+
.variable("testString")
3886+
.actions(
3887+
new java.util.ArrayList<DialogNodeAction>(
3888+
java.util.Arrays.asList(dialogNodeActionModel)))
3889+
.digressIn("not_available")
3890+
.digressOut("allow_returning")
3891+
.digressOutSlots("not_allowed")
3892+
.userLabel("testString")
3893+
.disambiguationOptOut(true)
3894+
.build();
3895+
Map<String, Object> updateDialogNodeModelAsPatch = updateDialogNodeModel.asPatch();
3896+
3897+
// Construct an instance of the UpdateDialogNodeNullableOptions model
3898+
UpdateDialogNodeNullableOptions updateDialogNodeNullableOptionsModel =
3899+
new UpdateDialogNodeNullableOptions.Builder()
3900+
.workspaceId("testString")
3901+
.dialogNode("testString")
3902+
.body(updateDialogNodeModelAsPatch)
3903+
.includeAudit(true)
3904+
.build();
3905+
3906+
// Invoke operation with valid options model (positive test)
3907+
Response<DialogNode> response =
3908+
assistantService.updateDialogNodeNullable(updateDialogNodeNullableOptionsModel).execute();
3909+
assertNotNull(response);
3910+
DialogNode responseObj = response.getResult();
3911+
assertNotNull(responseObj);
3912+
3913+
// Verify the contents of the request
3914+
RecordedRequest request = server.takeRequest();
3915+
assertNotNull(request);
3916+
assertEquals(request.getMethod(), "POST");
3917+
3918+
// Check query
3919+
Map<String, String> query = TestUtilities.parseQueryString(request);
3920+
assertNotNull(query);
3921+
// Get query params
3922+
assertEquals(query.get("version"), "testString");
3923+
assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(true));
3924+
// Check request path
3925+
String parsedPath = TestUtilities.parseReqPath(request);
3926+
assertEquals(parsedPath, updateDialogNodeNullablePath);
3927+
}
3928+
3929+
// Test the updateDialogNodeNullable operation with null options model parameter
3930+
@Test(expectedExceptions = IllegalArgumentException.class)
3931+
public void testUpdateDialogNodeNullableNoOptions() throws Throwable {
3932+
// construct the service
3933+
constructClientService();
3934+
3935+
server.enqueue(new MockResponse());
3936+
3937+
// Invoke operation with null options model (negative test)
3938+
assistantService.updateDialogNodeNullable(null).execute();
3939+
}
3940+
37703941
@Test
37713942
public void testDeleteUserDataWOptions() throws Throwable {
37723943
// Schedule some responses.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* (C) Copyright IBM Corp. 2021.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package com.ibm.watson.assistant.v1.model;
15+
16+
import static org.testng.Assert.*;
17+
18+
import com.ibm.cloud.sdk.core.service.model.FileWithMetadata;
19+
import com.ibm.watson.assistant.v1.utils.TestUtilities;
20+
import java.io.InputStream;
21+
import java.util.HashMap;
22+
import java.util.List;
23+
import org.testng.annotations.Test;
24+
25+
/** Unit test class for the UpdateDialogNodeNullableOptions model. */
26+
public class UpdateDialogNodeNullableOptionsTest {
27+
final HashMap<String, InputStream> mockStreamMap = TestUtilities.createMockStreamMap();
28+
final List<FileWithMetadata> mockListFileWithMetadata =
29+
TestUtilities.creatMockListFileWithMetadata();
30+
31+
@Test
32+
public void testUpdateDialogNodeNullableOptions() throws Throwable {
33+
UpdateDialogNodeNullableOptions updateDialogNodeNullableOptionsModel =
34+
new UpdateDialogNodeNullableOptions.Builder()
35+
.workspaceId("testString")
36+
.dialogNode("testString")
37+
.body(
38+
new java.util.HashMap<String, Object>() {
39+
{
40+
put("foo", "testString");
41+
}
42+
})
43+
.includeAudit(true)
44+
.build();
45+
assertEquals(updateDialogNodeNullableOptionsModel.workspaceId(), "testString");
46+
assertEquals(updateDialogNodeNullableOptionsModel.dialogNode(), "testString");
47+
assertEquals(
48+
updateDialogNodeNullableOptionsModel.body(),
49+
new java.util.HashMap<String, Object>() {
50+
{
51+
put("foo", "testString");
52+
}
53+
});
54+
assertEquals(updateDialogNodeNullableOptionsModel.includeAudit(), Boolean.valueOf(true));
55+
}
56+
57+
@Test(expectedExceptions = IllegalArgumentException.class)
58+
public void testUpdateDialogNodeNullableOptionsError() throws Throwable {
59+
new UpdateDialogNodeNullableOptions.Builder().build();
60+
}
61+
}

0 commit comments

Comments
 (0)