1
+ /*
2
+ * Copyright 2021 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com .example .dialogflow ;
18
+
19
+ import static com .google .common .truth .Truth .assertThat ;
20
+
21
+ import com .google .cloud .dialogflow .v2 .Agent ;
22
+ import com .google .cloud .dialogflow .v2 .Agent .Builder ;
23
+ import com .google .cloud .dialogflow .v2 .AgentsClient ;
24
+ import com .google .cloud .dialogflow .v2 .AgentsSettings ;
25
+ import com .google .cloud .dialogflow .v2 .Intent ;
26
+ import com .google .cloud .dialogflow .v2 .IntentsClient ;
27
+ import java .io .ByteArrayOutputStream ;
28
+ import java .io .IOException ;
29
+ import java .io .PrintStream ;
30
+ import java .util .UUID ;
31
+ import org .junit .After ;
32
+ import org .junit .Before ;
33
+ import org .junit .Test ;
34
+
35
+ public class UpdateIntentIT {
36
+
37
+ private static String PROJECT_ID = System .getenv ().get ("GOOGLE_CLOUD_PROJECT" );
38
+
39
+ private static String parent = "projects/" + PROJECT_ID + "/locations/global/agent" ;
40
+ private static String intentID = "" ;
41
+ private static String intentPath = "" ;
42
+
43
+ private ByteArrayOutputStream stdOut ;
44
+
45
+ @ Before
46
+ public void setUp () throws IOException {
47
+
48
+ stdOut = new ByteArrayOutputStream ();
49
+ System .setOut (new PrintStream (stdOut ));
50
+
51
+ try (IntentsClient intentsClient = IntentsClient .create ()) {
52
+ com .google .cloud .dialogflow .v2 .Intent .Builder intent = Intent .newBuilder ();
53
+ intent .setDisplayName ("temp_intent_" + UUID .randomUUID ().toString ());
54
+
55
+ UpdateIntentIT .intentPath = intentsClient .createIntent (parent , intent .build ()).getName ();
56
+ UpdateIntentIT .intentID = UpdateIntentIT .intentPath .split ("/" )[6 ];
57
+ }
58
+ }
59
+
60
+ @ After
61
+ public void tearDown () throws IOException {
62
+ stdOut = null ;
63
+ System .setOut (null );
64
+
65
+ IntentsClient client = IntentsClient .create ();
66
+
67
+ String intentPath =
68
+ "projects/"
69
+ + PROJECT_ID
70
+ + "/locations/global/agent/intents/"
71
+ + UpdateIntentIT .intentID ;
72
+
73
+ client .deleteIntent (intentPath );
74
+ }
75
+
76
+ @ Test
77
+ public void testUpdateIntent () throws IOException {
78
+
79
+ String fakeIntent = "fake_intent_" + UUID .randomUUID ().toString ();
80
+
81
+ UpdateIntent .updateIntent (
82
+ PROJECT_ID , UpdateIntentIT .intentID , "global" , fakeIntent );
83
+
84
+ assertThat (stdOut .toString ()).contains (fakeIntent );
85
+ }
86
+ }
0 commit comments