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 java .util .Map ;
24+ import org .testng .annotations .Test ;
25+
26+ /** Unit test class for the UpdateDialogNode model. */
27+ public class UpdateDialogNodeTest {
28+ final HashMap <String , InputStream > mockStreamMap = TestUtilities .createMockStreamMap ();
29+ final List <FileWithMetadata > mockListFileWithMetadata =
30+ TestUtilities .creatMockListFileWithMetadata ();
31+
32+ @ Test
33+ public void testUpdateDialogNode () throws Throwable {
34+ DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill dialogNodeOutputGenericModel =
35+ new DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill .Builder ()
36+ .responseType ("search_skill" )
37+ .query ("testString" )
38+ .queryType ("natural_language" )
39+ .filter ("testString" )
40+ .discoveryVersion ("testString" )
41+ .build ();
42+ assertEquals (dialogNodeOutputGenericModel .responseType (), "search_skill" );
43+ assertEquals (dialogNodeOutputGenericModel .query (), "testString" );
44+ assertEquals (dialogNodeOutputGenericModel .queryType (), "natural_language" );
45+ assertEquals (dialogNodeOutputGenericModel .filter (), "testString" );
46+ assertEquals (dialogNodeOutputGenericModel .discoveryVersion (), "testString" );
47+
48+ DialogNodeOutputModifiers dialogNodeOutputModifiersModel =
49+ new DialogNodeOutputModifiers .Builder ().overwrite (true ).build ();
50+ assertEquals (dialogNodeOutputModifiersModel .overwrite (), Boolean .valueOf (true ));
51+
52+ DialogNodeOutput dialogNodeOutputModel =
53+ new DialogNodeOutput .Builder ()
54+ .generic (
55+ new java .util .ArrayList <DialogNodeOutputGeneric >(
56+ java .util .Arrays .asList (dialogNodeOutputGenericModel )))
57+ .integrations (
58+ new java .util .HashMap <String , Map <String , Object >>() {
59+ {
60+ put (
61+ "foo" ,
62+ new java .util .HashMap <String , Object >() {
63+ {
64+ put ("foo" , "testString" );
65+ }
66+ });
67+ }
68+ })
69+ .modifiers (dialogNodeOutputModifiersModel )
70+ .add ("foo" , "testString" )
71+ .build ();
72+ assertEquals (
73+ dialogNodeOutputModel .getGeneric (),
74+ new java .util .ArrayList <DialogNodeOutputGeneric >(
75+ java .util .Arrays .asList (dialogNodeOutputGenericModel )));
76+ assertEquals (
77+ dialogNodeOutputModel .getIntegrations (),
78+ new java .util .HashMap <String , Map <String , Object >>() {
79+ {
80+ put (
81+ "foo" ,
82+ new java .util .HashMap <String , Object >() {
83+ {
84+ put ("foo" , "testString" );
85+ }
86+ });
87+ }
88+ });
89+ assertEquals (dialogNodeOutputModel .getModifiers (), dialogNodeOutputModifiersModel );
90+ assertEquals (dialogNodeOutputModel .get ("foo" ), "testString" );
91+
92+ DialogNodeContext dialogNodeContextModel =
93+ new DialogNodeContext .Builder ()
94+ .integrations (
95+ new java .util .HashMap <String , Map <String , Object >>() {
96+ {
97+ put (
98+ "foo" ,
99+ new java .util .HashMap <String , Object >() {
100+ {
101+ put ("foo" , "testString" );
102+ }
103+ });
104+ }
105+ })
106+ .add ("foo" , "testString" )
107+ .build ();
108+ assertEquals (
109+ dialogNodeContextModel .getIntegrations (),
110+ new java .util .HashMap <String , Map <String , Object >>() {
111+ {
112+ put (
113+ "foo" ,
114+ new java .util .HashMap <String , Object >() {
115+ {
116+ put ("foo" , "testString" );
117+ }
118+ });
119+ }
120+ });
121+ assertEquals (dialogNodeContextModel .get ("foo" ), "testString" );
122+
123+ DialogNodeNextStep dialogNodeNextStepModel =
124+ new DialogNodeNextStep .Builder ()
125+ .behavior ("get_user_input" )
126+ .dialogNode ("testString" )
127+ .selector ("condition" )
128+ .build ();
129+ assertEquals (dialogNodeNextStepModel .behavior (), "get_user_input" );
130+ assertEquals (dialogNodeNextStepModel .dialogNode (), "testString" );
131+ assertEquals (dialogNodeNextStepModel .selector (), "condition" );
132+
133+ DialogNodeAction dialogNodeActionModel =
134+ new DialogNodeAction .Builder ()
135+ .name ("testString" )
136+ .type ("client" )
137+ .parameters (
138+ new java .util .HashMap <String , Object >() {
139+ {
140+ put ("foo" , "testString" );
141+ }
142+ })
143+ .resultVariable ("testString" )
144+ .credentials ("testString" )
145+ .build ();
146+ assertEquals (dialogNodeActionModel .name (), "testString" );
147+ assertEquals (dialogNodeActionModel .type (), "client" );
148+ assertEquals (
149+ dialogNodeActionModel .parameters (),
150+ new java .util .HashMap <String , Object >() {
151+ {
152+ put ("foo" , "testString" );
153+ }
154+ });
155+ assertEquals (dialogNodeActionModel .resultVariable (), "testString" );
156+ assertEquals (dialogNodeActionModel .credentials (), "testString" );
157+
158+ UpdateDialogNode updateDialogNodeModel =
159+ new UpdateDialogNode .Builder ()
160+ .dialogNode ("testString" )
161+ .description ("testString" )
162+ .conditions ("testString" )
163+ .parent ("testString" )
164+ .previousSibling ("testString" )
165+ .output (dialogNodeOutputModel )
166+ .context (dialogNodeContextModel )
167+ .metadata (
168+ new java .util .HashMap <String , Object >() {
169+ {
170+ put ("foo" , "testString" );
171+ }
172+ })
173+ .nextStep (dialogNodeNextStepModel )
174+ .title ("testString" )
175+ .type ("standard" )
176+ .eventName ("focus" )
177+ .variable ("testString" )
178+ .actions (
179+ new java .util .ArrayList <DialogNodeAction >(
180+ java .util .Arrays .asList (dialogNodeActionModel )))
181+ .digressIn ("not_available" )
182+ .digressOut ("allow_returning" )
183+ .digressOutSlots ("not_allowed" )
184+ .userLabel ("testString" )
185+ .disambiguationOptOut (true )
186+ .build ();
187+ assertEquals (updateDialogNodeModel .dialogNode (), "testString" );
188+ assertEquals (updateDialogNodeModel .description (), "testString" );
189+ assertEquals (updateDialogNodeModel .conditions (), "testString" );
190+ assertEquals (updateDialogNodeModel .parent (), "testString" );
191+ assertEquals (updateDialogNodeModel .previousSibling (), "testString" );
192+ assertEquals (updateDialogNodeModel .output (), dialogNodeOutputModel );
193+ assertEquals (updateDialogNodeModel .context (), dialogNodeContextModel );
194+ assertEquals (
195+ updateDialogNodeModel .metadata (),
196+ new java .util .HashMap <String , Object >() {
197+ {
198+ put ("foo" , "testString" );
199+ }
200+ });
201+ assertEquals (updateDialogNodeModel .nextStep (), dialogNodeNextStepModel );
202+ assertEquals (updateDialogNodeModel .title (), "testString" );
203+ assertEquals (updateDialogNodeModel .type (), "standard" );
204+ assertEquals (updateDialogNodeModel .eventName (), "focus" );
205+ assertEquals (updateDialogNodeModel .variable (), "testString" );
206+ assertEquals (
207+ updateDialogNodeModel .actions (),
208+ new java .util .ArrayList <DialogNodeAction >(java .util .Arrays .asList (dialogNodeActionModel )));
209+ assertEquals (updateDialogNodeModel .digressIn (), "not_available" );
210+ assertEquals (updateDialogNodeModel .digressOut (), "allow_returning" );
211+ assertEquals (updateDialogNodeModel .digressOutSlots (), "not_allowed" );
212+ assertEquals (updateDialogNodeModel .userLabel (), "testString" );
213+ assertEquals (updateDialogNodeModel .disambiguationOptOut (), Boolean .valueOf (true ));
214+
215+ String json = TestUtilities .serialize (updateDialogNodeModel );
216+
217+ UpdateDialogNode updateDialogNodeModelNew =
218+ TestUtilities .deserialize (json , UpdateDialogNode .class );
219+ assertTrue (updateDialogNodeModelNew instanceof UpdateDialogNode );
220+ assertEquals (updateDialogNodeModelNew .dialogNode (), "testString" );
221+ assertEquals (updateDialogNodeModelNew .description (), "testString" );
222+ assertEquals (updateDialogNodeModelNew .conditions (), "testString" );
223+ assertEquals (updateDialogNodeModelNew .parent (), "testString" );
224+ assertEquals (updateDialogNodeModelNew .previousSibling (), "testString" );
225+ assertEquals (updateDialogNodeModelNew .output ().toString (), dialogNodeOutputModel .toString ());
226+ assertEquals (updateDialogNodeModelNew .context ().toString (), dialogNodeContextModel .toString ());
227+ assertEquals (
228+ updateDialogNodeModelNew .nextStep ().toString (), dialogNodeNextStepModel .toString ());
229+ assertEquals (updateDialogNodeModelNew .title (), "testString" );
230+ assertEquals (updateDialogNodeModelNew .type (), "standard" );
231+ assertEquals (updateDialogNodeModelNew .eventName (), "focus" );
232+ assertEquals (updateDialogNodeModelNew .variable (), "testString" );
233+ assertEquals (updateDialogNodeModelNew .digressIn (), "not_available" );
234+ assertEquals (updateDialogNodeModelNew .digressOut (), "allow_returning" );
235+ assertEquals (updateDialogNodeModelNew .digressOutSlots (), "not_allowed" );
236+ assertEquals (updateDialogNodeModelNew .userLabel (), "testString" );
237+ assertEquals (updateDialogNodeModelNew .disambiguationOptOut (), Boolean .valueOf (true ));
238+ }
239+
240+ @ Test
241+ public void testUpdateDialogNodeNullable () throws Throwable {
242+
243+ DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill dialogNodeOutputGenericModel =
244+ new DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill .Builder ()
245+ .responseType ("search_skill" )
246+ .query ("testString" )
247+ .queryType ("natural_language" )
248+ .filter ("testString" )
249+ .discoveryVersion ("testString" )
250+ .build ();
251+
252+ DialogNodeOutputModifiers dialogNodeOutputModifiersModel =
253+ new DialogNodeOutputModifiers .Builder ().overwrite (true ).build ();
254+
255+ DialogNodeOutput dialogNodeOutputModel =
256+ new DialogNodeOutput .Builder ()
257+ .generic (
258+ new java .util .ArrayList <DialogNodeOutputGeneric >(
259+ java .util .Arrays .asList (dialogNodeOutputGenericModel )))
260+ .integrations (
261+ new java .util .HashMap <String , Map <String , Object >>() {
262+ {
263+ put (
264+ "foo" ,
265+ new java .util .HashMap <String , Object >() {
266+ {
267+ put ("foo" , "testString" );
268+ }
269+ });
270+ }
271+ })
272+ .modifiers (dialogNodeOutputModifiersModel )
273+ .add ("foo" , "testString" )
274+ .build ();
275+
276+ DialogNodeContext dialogNodeContextModel =
277+ new DialogNodeContext .Builder ()
278+ .integrations (
279+ new java .util .HashMap <String , Map <String , Object >>() {
280+ {
281+ put (
282+ "foo" ,
283+ new java .util .HashMap <String , Object >() {
284+ {
285+ put ("foo" , "testString" );
286+ }
287+ });
288+ }
289+ })
290+ .add ("foo" , "testString" )
291+ .build ();
292+
293+ DialogNodeNextStep dialogNodeNextStepModel =
294+ new DialogNodeNextStep .Builder ()
295+ .behavior ("get_user_input" )
296+ .dialogNode ("testString" )
297+ .selector ("condition" )
298+ .build ();
299+
300+ DialogNodeAction dialogNodeActionModel =
301+ new DialogNodeAction .Builder ()
302+ .name ("testString" )
303+ .type ("client" )
304+ .parameters (
305+ new java .util .HashMap <String , Object >() {
306+ {
307+ put ("foo" , "testString" );
308+ }
309+ })
310+ .resultVariable ("testString" )
311+ .credentials ("testString" )
312+ .build ();
313+
314+ UpdateDialogNode updateDialogNodeModel =
315+ new UpdateDialogNode .Builder ()
316+ .dialogNode ("testString" )
317+ .description ("testString" )
318+ .conditions ("testString" )
319+ .parent ("testString" )
320+ .previousSibling ("testString" )
321+ .output (dialogNodeOutputModel )
322+ .context (dialogNodeContextModel )
323+ .metadata (
324+ new java .util .HashMap <String , Object >() {
325+ {
326+ put ("foo" , "testString" );
327+ }
328+ })
329+ .nextStep (dialogNodeNextStepModel )
330+ .title ("testString" )
331+ .type ("standard" )
332+ .eventName ("focus" )
333+ .variable ("testString" )
334+ .actions (
335+ new java .util .ArrayList <DialogNodeAction >(
336+ java .util .Arrays .asList (dialogNodeActionModel )))
337+ .digressIn ("not_available" )
338+ .digressOut ("allow_returning" )
339+ .digressOutSlots ("not_allowed" )
340+ .userLabel ("testString" )
341+ .disambiguationOptOut (true )
342+ .build ();
343+
344+ Map <String , Object > mergePatch = updateDialogNodeModel .asPatch ();
345+
346+ assertEquals (mergePatch .get ("dialog_node" ), "testString" );
347+ assertEquals (mergePatch .get ("description" ), "testString" );
348+ assertEquals (mergePatch .get ("conditions" ), "testString" );
349+ assertEquals (mergePatch .get ("parent" ), "testString" );
350+ assertEquals (mergePatch .get ("previous_sibling" ), "testString" );
351+ assertTrue (mergePatch .containsKey ("output" ));
352+ assertTrue (mergePatch .containsKey ("context" ));
353+ assertTrue (mergePatch .containsKey ("metadata" ));
354+ assertTrue (mergePatch .containsKey ("next_step" ));
355+ assertEquals (mergePatch .get ("title" ), "testString" );
356+ assertEquals (mergePatch .get ("type" ), "standard" );
357+ assertEquals (mergePatch .get ("event_name" ), "focus" );
358+ assertEquals (mergePatch .get ("variable" ), "testString" );
359+ assertTrue (mergePatch .containsKey ("actions" ));
360+ assertEquals (mergePatch .get ("digress_in" ), "not_available" );
361+ assertEquals (mergePatch .get ("digress_out" ), "allow_returning" );
362+ assertEquals (mergePatch .get ("digress_out_slots" ), "not_allowed" );
363+ assertEquals (mergePatch .get ("user_label" ), "testString" );
364+ assertTrue (mergePatch .containsKey ("disambiguation_opt_out" ));
365+ }
366+ }
0 commit comments