• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 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  *      https://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.google.cloud.dialogflow.v2beta1;
18 
19 import static com.google.cloud.dialogflow.v2beta1.IntentsClient.ListIntentsPagedResponse;
20 import static com.google.cloud.dialogflow.v2beta1.IntentsClient.ListLocationsPagedResponse;
21 
22 import com.google.api.gax.core.NoCredentialsProvider;
23 import com.google.api.gax.grpc.GaxGrpcProperties;
24 import com.google.api.gax.grpc.testing.LocalChannelProvider;
25 import com.google.api.gax.grpc.testing.MockGrpcService;
26 import com.google.api.gax.grpc.testing.MockServiceHelper;
27 import com.google.api.gax.rpc.ApiClientHeaderProvider;
28 import com.google.api.gax.rpc.InvalidArgumentException;
29 import com.google.api.gax.rpc.StatusCode;
30 import com.google.cloud.location.GetLocationRequest;
31 import com.google.cloud.location.ListLocationsRequest;
32 import com.google.cloud.location.ListLocationsResponse;
33 import com.google.cloud.location.Location;
34 import com.google.common.collect.Lists;
35 import com.google.longrunning.Operation;
36 import com.google.protobuf.AbstractMessage;
37 import com.google.protobuf.Any;
38 import com.google.protobuf.Empty;
39 import com.google.protobuf.FieldMask;
40 import io.grpc.StatusRuntimeException;
41 import java.io.IOException;
42 import java.util.ArrayList;
43 import java.util.Arrays;
44 import java.util.HashMap;
45 import java.util.List;
46 import java.util.UUID;
47 import java.util.concurrent.ExecutionException;
48 import javax.annotation.Generated;
49 import org.junit.After;
50 import org.junit.AfterClass;
51 import org.junit.Assert;
52 import org.junit.Before;
53 import org.junit.BeforeClass;
54 import org.junit.Test;
55 
56 @Generated("by gapic-generator-java")
57 public class IntentsClientTest {
58   private static MockIntents mockIntents;
59   private static MockLocations mockLocations;
60   private static MockServiceHelper mockServiceHelper;
61   private LocalChannelProvider channelProvider;
62   private IntentsClient client;
63 
64   @BeforeClass
startStaticServer()65   public static void startStaticServer() {
66     mockIntents = new MockIntents();
67     mockLocations = new MockLocations();
68     mockServiceHelper =
69         new MockServiceHelper(
70             UUID.randomUUID().toString(),
71             Arrays.<MockGrpcService>asList(mockIntents, mockLocations));
72     mockServiceHelper.start();
73   }
74 
75   @AfterClass
stopServer()76   public static void stopServer() {
77     mockServiceHelper.stop();
78   }
79 
80   @Before
setUp()81   public void setUp() throws IOException {
82     mockServiceHelper.reset();
83     channelProvider = mockServiceHelper.createChannelProvider();
84     IntentsSettings settings =
85         IntentsSettings.newBuilder()
86             .setTransportChannelProvider(channelProvider)
87             .setCredentialsProvider(NoCredentialsProvider.create())
88             .build();
89     client = IntentsClient.create(settings);
90   }
91 
92   @After
tearDown()93   public void tearDown() throws Exception {
94     client.close();
95   }
96 
97   @Test
listIntentsTest()98   public void listIntentsTest() throws Exception {
99     Intent responsesElement = Intent.newBuilder().build();
100     ListIntentsResponse expectedResponse =
101         ListIntentsResponse.newBuilder()
102             .setNextPageToken("")
103             .addAllIntents(Arrays.asList(responsesElement))
104             .build();
105     mockIntents.addResponse(expectedResponse);
106 
107     AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
108 
109     ListIntentsPagedResponse pagedListResponse = client.listIntents(parent);
110 
111     List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll());
112 
113     Assert.assertEquals(1, resources.size());
114     Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0));
115 
116     List<AbstractMessage> actualRequests = mockIntents.getRequests();
117     Assert.assertEquals(1, actualRequests.size());
118     ListIntentsRequest actualRequest = ((ListIntentsRequest) actualRequests.get(0));
119 
120     Assert.assertEquals(parent.toString(), actualRequest.getParent());
121     Assert.assertTrue(
122         channelProvider.isHeaderSent(
123             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
124             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
125   }
126 
127   @Test
listIntentsExceptionTest()128   public void listIntentsExceptionTest() throws Exception {
129     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
130     mockIntents.addException(exception);
131 
132     try {
133       AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
134       client.listIntents(parent);
135       Assert.fail("No exception raised");
136     } catch (InvalidArgumentException e) {
137       // Expected exception.
138     }
139   }
140 
141   @Test
listIntentsTest2()142   public void listIntentsTest2() throws Exception {
143     Intent responsesElement = Intent.newBuilder().build();
144     ListIntentsResponse expectedResponse =
145         ListIntentsResponse.newBuilder()
146             .setNextPageToken("")
147             .addAllIntents(Arrays.asList(responsesElement))
148             .build();
149     mockIntents.addResponse(expectedResponse);
150 
151     String parent = "parent-995424086";
152 
153     ListIntentsPagedResponse pagedListResponse = client.listIntents(parent);
154 
155     List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll());
156 
157     Assert.assertEquals(1, resources.size());
158     Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0));
159 
160     List<AbstractMessage> actualRequests = mockIntents.getRequests();
161     Assert.assertEquals(1, actualRequests.size());
162     ListIntentsRequest actualRequest = ((ListIntentsRequest) actualRequests.get(0));
163 
164     Assert.assertEquals(parent, actualRequest.getParent());
165     Assert.assertTrue(
166         channelProvider.isHeaderSent(
167             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
168             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
169   }
170 
171   @Test
listIntentsExceptionTest2()172   public void listIntentsExceptionTest2() throws Exception {
173     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
174     mockIntents.addException(exception);
175 
176     try {
177       String parent = "parent-995424086";
178       client.listIntents(parent);
179       Assert.fail("No exception raised");
180     } catch (InvalidArgumentException e) {
181       // Expected exception.
182     }
183   }
184 
185   @Test
listIntentsTest3()186   public void listIntentsTest3() throws Exception {
187     Intent responsesElement = Intent.newBuilder().build();
188     ListIntentsResponse expectedResponse =
189         ListIntentsResponse.newBuilder()
190             .setNextPageToken("")
191             .addAllIntents(Arrays.asList(responsesElement))
192             .build();
193     mockIntents.addResponse(expectedResponse);
194 
195     AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
196     String languageCode = "languageCode-2092349083";
197 
198     ListIntentsPagedResponse pagedListResponse = client.listIntents(parent, languageCode);
199 
200     List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll());
201 
202     Assert.assertEquals(1, resources.size());
203     Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0));
204 
205     List<AbstractMessage> actualRequests = mockIntents.getRequests();
206     Assert.assertEquals(1, actualRequests.size());
207     ListIntentsRequest actualRequest = ((ListIntentsRequest) actualRequests.get(0));
208 
209     Assert.assertEquals(parent.toString(), actualRequest.getParent());
210     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
211     Assert.assertTrue(
212         channelProvider.isHeaderSent(
213             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
214             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
215   }
216 
217   @Test
listIntentsExceptionTest3()218   public void listIntentsExceptionTest3() throws Exception {
219     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
220     mockIntents.addException(exception);
221 
222     try {
223       AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
224       String languageCode = "languageCode-2092349083";
225       client.listIntents(parent, languageCode);
226       Assert.fail("No exception raised");
227     } catch (InvalidArgumentException e) {
228       // Expected exception.
229     }
230   }
231 
232   @Test
listIntentsTest4()233   public void listIntentsTest4() throws Exception {
234     Intent responsesElement = Intent.newBuilder().build();
235     ListIntentsResponse expectedResponse =
236         ListIntentsResponse.newBuilder()
237             .setNextPageToken("")
238             .addAllIntents(Arrays.asList(responsesElement))
239             .build();
240     mockIntents.addResponse(expectedResponse);
241 
242     String parent = "parent-995424086";
243     String languageCode = "languageCode-2092349083";
244 
245     ListIntentsPagedResponse pagedListResponse = client.listIntents(parent, languageCode);
246 
247     List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll());
248 
249     Assert.assertEquals(1, resources.size());
250     Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0));
251 
252     List<AbstractMessage> actualRequests = mockIntents.getRequests();
253     Assert.assertEquals(1, actualRequests.size());
254     ListIntentsRequest actualRequest = ((ListIntentsRequest) actualRequests.get(0));
255 
256     Assert.assertEquals(parent, actualRequest.getParent());
257     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
258     Assert.assertTrue(
259         channelProvider.isHeaderSent(
260             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
261             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
262   }
263 
264   @Test
listIntentsExceptionTest4()265   public void listIntentsExceptionTest4() throws Exception {
266     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
267     mockIntents.addException(exception);
268 
269     try {
270       String parent = "parent-995424086";
271       String languageCode = "languageCode-2092349083";
272       client.listIntents(parent, languageCode);
273       Assert.fail("No exception raised");
274     } catch (InvalidArgumentException e) {
275       // Expected exception.
276     }
277   }
278 
279   @Test
getIntentTest()280   public void getIntentTest() throws Exception {
281     Intent expectedResponse =
282         Intent.newBuilder()
283             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
284             .setDisplayName("displayName1714148973")
285             .setPriority(-1165461084)
286             .setIsFallback(true)
287             .setMlEnabled(true)
288             .setMlDisabled(true)
289             .setLiveAgentHandoff(true)
290             .setEndInteraction(true)
291             .addAllInputContextNames(new ArrayList<String>())
292             .addAllEvents(new ArrayList<String>())
293             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
294             .setAction("action-1422950858")
295             .addAllOutputContexts(new ArrayList<Context>())
296             .setResetContexts(true)
297             .addAllParameters(new ArrayList<Intent.Parameter>())
298             .addAllMessages(new ArrayList<Intent.Message>())
299             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
300             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
301             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
302             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
303             .build();
304     mockIntents.addResponse(expectedResponse);
305 
306     IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]");
307 
308     Intent actualResponse = client.getIntent(name);
309     Assert.assertEquals(expectedResponse, actualResponse);
310 
311     List<AbstractMessage> actualRequests = mockIntents.getRequests();
312     Assert.assertEquals(1, actualRequests.size());
313     GetIntentRequest actualRequest = ((GetIntentRequest) actualRequests.get(0));
314 
315     Assert.assertEquals(name.toString(), actualRequest.getName());
316     Assert.assertTrue(
317         channelProvider.isHeaderSent(
318             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
319             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
320   }
321 
322   @Test
getIntentExceptionTest()323   public void getIntentExceptionTest() throws Exception {
324     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
325     mockIntents.addException(exception);
326 
327     try {
328       IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]");
329       client.getIntent(name);
330       Assert.fail("No exception raised");
331     } catch (InvalidArgumentException e) {
332       // Expected exception.
333     }
334   }
335 
336   @Test
getIntentTest2()337   public void getIntentTest2() throws Exception {
338     Intent expectedResponse =
339         Intent.newBuilder()
340             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
341             .setDisplayName("displayName1714148973")
342             .setPriority(-1165461084)
343             .setIsFallback(true)
344             .setMlEnabled(true)
345             .setMlDisabled(true)
346             .setLiveAgentHandoff(true)
347             .setEndInteraction(true)
348             .addAllInputContextNames(new ArrayList<String>())
349             .addAllEvents(new ArrayList<String>())
350             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
351             .setAction("action-1422950858")
352             .addAllOutputContexts(new ArrayList<Context>())
353             .setResetContexts(true)
354             .addAllParameters(new ArrayList<Intent.Parameter>())
355             .addAllMessages(new ArrayList<Intent.Message>())
356             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
357             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
358             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
359             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
360             .build();
361     mockIntents.addResponse(expectedResponse);
362 
363     String name = "name3373707";
364 
365     Intent actualResponse = client.getIntent(name);
366     Assert.assertEquals(expectedResponse, actualResponse);
367 
368     List<AbstractMessage> actualRequests = mockIntents.getRequests();
369     Assert.assertEquals(1, actualRequests.size());
370     GetIntentRequest actualRequest = ((GetIntentRequest) actualRequests.get(0));
371 
372     Assert.assertEquals(name, actualRequest.getName());
373     Assert.assertTrue(
374         channelProvider.isHeaderSent(
375             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
376             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
377   }
378 
379   @Test
getIntentExceptionTest2()380   public void getIntentExceptionTest2() throws Exception {
381     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
382     mockIntents.addException(exception);
383 
384     try {
385       String name = "name3373707";
386       client.getIntent(name);
387       Assert.fail("No exception raised");
388     } catch (InvalidArgumentException e) {
389       // Expected exception.
390     }
391   }
392 
393   @Test
getIntentTest3()394   public void getIntentTest3() throws Exception {
395     Intent expectedResponse =
396         Intent.newBuilder()
397             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
398             .setDisplayName("displayName1714148973")
399             .setPriority(-1165461084)
400             .setIsFallback(true)
401             .setMlEnabled(true)
402             .setMlDisabled(true)
403             .setLiveAgentHandoff(true)
404             .setEndInteraction(true)
405             .addAllInputContextNames(new ArrayList<String>())
406             .addAllEvents(new ArrayList<String>())
407             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
408             .setAction("action-1422950858")
409             .addAllOutputContexts(new ArrayList<Context>())
410             .setResetContexts(true)
411             .addAllParameters(new ArrayList<Intent.Parameter>())
412             .addAllMessages(new ArrayList<Intent.Message>())
413             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
414             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
415             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
416             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
417             .build();
418     mockIntents.addResponse(expectedResponse);
419 
420     IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]");
421     String languageCode = "languageCode-2092349083";
422 
423     Intent actualResponse = client.getIntent(name, languageCode);
424     Assert.assertEquals(expectedResponse, actualResponse);
425 
426     List<AbstractMessage> actualRequests = mockIntents.getRequests();
427     Assert.assertEquals(1, actualRequests.size());
428     GetIntentRequest actualRequest = ((GetIntentRequest) actualRequests.get(0));
429 
430     Assert.assertEquals(name.toString(), actualRequest.getName());
431     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
432     Assert.assertTrue(
433         channelProvider.isHeaderSent(
434             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
435             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
436   }
437 
438   @Test
getIntentExceptionTest3()439   public void getIntentExceptionTest3() throws Exception {
440     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
441     mockIntents.addException(exception);
442 
443     try {
444       IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]");
445       String languageCode = "languageCode-2092349083";
446       client.getIntent(name, languageCode);
447       Assert.fail("No exception raised");
448     } catch (InvalidArgumentException e) {
449       // Expected exception.
450     }
451   }
452 
453   @Test
getIntentTest4()454   public void getIntentTest4() throws Exception {
455     Intent expectedResponse =
456         Intent.newBuilder()
457             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
458             .setDisplayName("displayName1714148973")
459             .setPriority(-1165461084)
460             .setIsFallback(true)
461             .setMlEnabled(true)
462             .setMlDisabled(true)
463             .setLiveAgentHandoff(true)
464             .setEndInteraction(true)
465             .addAllInputContextNames(new ArrayList<String>())
466             .addAllEvents(new ArrayList<String>())
467             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
468             .setAction("action-1422950858")
469             .addAllOutputContexts(new ArrayList<Context>())
470             .setResetContexts(true)
471             .addAllParameters(new ArrayList<Intent.Parameter>())
472             .addAllMessages(new ArrayList<Intent.Message>())
473             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
474             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
475             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
476             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
477             .build();
478     mockIntents.addResponse(expectedResponse);
479 
480     String name = "name3373707";
481     String languageCode = "languageCode-2092349083";
482 
483     Intent actualResponse = client.getIntent(name, languageCode);
484     Assert.assertEquals(expectedResponse, actualResponse);
485 
486     List<AbstractMessage> actualRequests = mockIntents.getRequests();
487     Assert.assertEquals(1, actualRequests.size());
488     GetIntentRequest actualRequest = ((GetIntentRequest) actualRequests.get(0));
489 
490     Assert.assertEquals(name, actualRequest.getName());
491     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
492     Assert.assertTrue(
493         channelProvider.isHeaderSent(
494             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
495             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
496   }
497 
498   @Test
getIntentExceptionTest4()499   public void getIntentExceptionTest4() throws Exception {
500     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
501     mockIntents.addException(exception);
502 
503     try {
504       String name = "name3373707";
505       String languageCode = "languageCode-2092349083";
506       client.getIntent(name, languageCode);
507       Assert.fail("No exception raised");
508     } catch (InvalidArgumentException e) {
509       // Expected exception.
510     }
511   }
512 
513   @Test
createIntentTest()514   public void createIntentTest() throws Exception {
515     Intent expectedResponse =
516         Intent.newBuilder()
517             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
518             .setDisplayName("displayName1714148973")
519             .setPriority(-1165461084)
520             .setIsFallback(true)
521             .setMlEnabled(true)
522             .setMlDisabled(true)
523             .setLiveAgentHandoff(true)
524             .setEndInteraction(true)
525             .addAllInputContextNames(new ArrayList<String>())
526             .addAllEvents(new ArrayList<String>())
527             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
528             .setAction("action-1422950858")
529             .addAllOutputContexts(new ArrayList<Context>())
530             .setResetContexts(true)
531             .addAllParameters(new ArrayList<Intent.Parameter>())
532             .addAllMessages(new ArrayList<Intent.Message>())
533             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
534             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
535             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
536             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
537             .build();
538     mockIntents.addResponse(expectedResponse);
539 
540     AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
541     Intent intent = Intent.newBuilder().build();
542 
543     Intent actualResponse = client.createIntent(parent, intent);
544     Assert.assertEquals(expectedResponse, actualResponse);
545 
546     List<AbstractMessage> actualRequests = mockIntents.getRequests();
547     Assert.assertEquals(1, actualRequests.size());
548     CreateIntentRequest actualRequest = ((CreateIntentRequest) actualRequests.get(0));
549 
550     Assert.assertEquals(parent.toString(), actualRequest.getParent());
551     Assert.assertEquals(intent, actualRequest.getIntent());
552     Assert.assertTrue(
553         channelProvider.isHeaderSent(
554             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
555             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
556   }
557 
558   @Test
createIntentExceptionTest()559   public void createIntentExceptionTest() throws Exception {
560     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
561     mockIntents.addException(exception);
562 
563     try {
564       AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
565       Intent intent = Intent.newBuilder().build();
566       client.createIntent(parent, intent);
567       Assert.fail("No exception raised");
568     } catch (InvalidArgumentException e) {
569       // Expected exception.
570     }
571   }
572 
573   @Test
createIntentTest2()574   public void createIntentTest2() throws Exception {
575     Intent expectedResponse =
576         Intent.newBuilder()
577             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
578             .setDisplayName("displayName1714148973")
579             .setPriority(-1165461084)
580             .setIsFallback(true)
581             .setMlEnabled(true)
582             .setMlDisabled(true)
583             .setLiveAgentHandoff(true)
584             .setEndInteraction(true)
585             .addAllInputContextNames(new ArrayList<String>())
586             .addAllEvents(new ArrayList<String>())
587             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
588             .setAction("action-1422950858")
589             .addAllOutputContexts(new ArrayList<Context>())
590             .setResetContexts(true)
591             .addAllParameters(new ArrayList<Intent.Parameter>())
592             .addAllMessages(new ArrayList<Intent.Message>())
593             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
594             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
595             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
596             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
597             .build();
598     mockIntents.addResponse(expectedResponse);
599 
600     String parent = "parent-995424086";
601     Intent intent = Intent.newBuilder().build();
602 
603     Intent actualResponse = client.createIntent(parent, intent);
604     Assert.assertEquals(expectedResponse, actualResponse);
605 
606     List<AbstractMessage> actualRequests = mockIntents.getRequests();
607     Assert.assertEquals(1, actualRequests.size());
608     CreateIntentRequest actualRequest = ((CreateIntentRequest) actualRequests.get(0));
609 
610     Assert.assertEquals(parent, actualRequest.getParent());
611     Assert.assertEquals(intent, actualRequest.getIntent());
612     Assert.assertTrue(
613         channelProvider.isHeaderSent(
614             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
615             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
616   }
617 
618   @Test
createIntentExceptionTest2()619   public void createIntentExceptionTest2() throws Exception {
620     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
621     mockIntents.addException(exception);
622 
623     try {
624       String parent = "parent-995424086";
625       Intent intent = Intent.newBuilder().build();
626       client.createIntent(parent, intent);
627       Assert.fail("No exception raised");
628     } catch (InvalidArgumentException e) {
629       // Expected exception.
630     }
631   }
632 
633   @Test
createIntentTest3()634   public void createIntentTest3() throws Exception {
635     Intent expectedResponse =
636         Intent.newBuilder()
637             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
638             .setDisplayName("displayName1714148973")
639             .setPriority(-1165461084)
640             .setIsFallback(true)
641             .setMlEnabled(true)
642             .setMlDisabled(true)
643             .setLiveAgentHandoff(true)
644             .setEndInteraction(true)
645             .addAllInputContextNames(new ArrayList<String>())
646             .addAllEvents(new ArrayList<String>())
647             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
648             .setAction("action-1422950858")
649             .addAllOutputContexts(new ArrayList<Context>())
650             .setResetContexts(true)
651             .addAllParameters(new ArrayList<Intent.Parameter>())
652             .addAllMessages(new ArrayList<Intent.Message>())
653             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
654             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
655             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
656             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
657             .build();
658     mockIntents.addResponse(expectedResponse);
659 
660     AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
661     Intent intent = Intent.newBuilder().build();
662     String languageCode = "languageCode-2092349083";
663 
664     Intent actualResponse = client.createIntent(parent, intent, languageCode);
665     Assert.assertEquals(expectedResponse, actualResponse);
666 
667     List<AbstractMessage> actualRequests = mockIntents.getRequests();
668     Assert.assertEquals(1, actualRequests.size());
669     CreateIntentRequest actualRequest = ((CreateIntentRequest) actualRequests.get(0));
670 
671     Assert.assertEquals(parent.toString(), actualRequest.getParent());
672     Assert.assertEquals(intent, actualRequest.getIntent());
673     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
674     Assert.assertTrue(
675         channelProvider.isHeaderSent(
676             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
677             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
678   }
679 
680   @Test
createIntentExceptionTest3()681   public void createIntentExceptionTest3() throws Exception {
682     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
683     mockIntents.addException(exception);
684 
685     try {
686       AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
687       Intent intent = Intent.newBuilder().build();
688       String languageCode = "languageCode-2092349083";
689       client.createIntent(parent, intent, languageCode);
690       Assert.fail("No exception raised");
691     } catch (InvalidArgumentException e) {
692       // Expected exception.
693     }
694   }
695 
696   @Test
createIntentTest4()697   public void createIntentTest4() throws Exception {
698     Intent expectedResponse =
699         Intent.newBuilder()
700             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
701             .setDisplayName("displayName1714148973")
702             .setPriority(-1165461084)
703             .setIsFallback(true)
704             .setMlEnabled(true)
705             .setMlDisabled(true)
706             .setLiveAgentHandoff(true)
707             .setEndInteraction(true)
708             .addAllInputContextNames(new ArrayList<String>())
709             .addAllEvents(new ArrayList<String>())
710             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
711             .setAction("action-1422950858")
712             .addAllOutputContexts(new ArrayList<Context>())
713             .setResetContexts(true)
714             .addAllParameters(new ArrayList<Intent.Parameter>())
715             .addAllMessages(new ArrayList<Intent.Message>())
716             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
717             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
718             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
719             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
720             .build();
721     mockIntents.addResponse(expectedResponse);
722 
723     String parent = "parent-995424086";
724     Intent intent = Intent.newBuilder().build();
725     String languageCode = "languageCode-2092349083";
726 
727     Intent actualResponse = client.createIntent(parent, intent, languageCode);
728     Assert.assertEquals(expectedResponse, actualResponse);
729 
730     List<AbstractMessage> actualRequests = mockIntents.getRequests();
731     Assert.assertEquals(1, actualRequests.size());
732     CreateIntentRequest actualRequest = ((CreateIntentRequest) actualRequests.get(0));
733 
734     Assert.assertEquals(parent, actualRequest.getParent());
735     Assert.assertEquals(intent, actualRequest.getIntent());
736     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
737     Assert.assertTrue(
738         channelProvider.isHeaderSent(
739             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
740             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
741   }
742 
743   @Test
createIntentExceptionTest4()744   public void createIntentExceptionTest4() throws Exception {
745     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
746     mockIntents.addException(exception);
747 
748     try {
749       String parent = "parent-995424086";
750       Intent intent = Intent.newBuilder().build();
751       String languageCode = "languageCode-2092349083";
752       client.createIntent(parent, intent, languageCode);
753       Assert.fail("No exception raised");
754     } catch (InvalidArgumentException e) {
755       // Expected exception.
756     }
757   }
758 
759   @Test
updateIntentTest()760   public void updateIntentTest() throws Exception {
761     Intent expectedResponse =
762         Intent.newBuilder()
763             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
764             .setDisplayName("displayName1714148973")
765             .setPriority(-1165461084)
766             .setIsFallback(true)
767             .setMlEnabled(true)
768             .setMlDisabled(true)
769             .setLiveAgentHandoff(true)
770             .setEndInteraction(true)
771             .addAllInputContextNames(new ArrayList<String>())
772             .addAllEvents(new ArrayList<String>())
773             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
774             .setAction("action-1422950858")
775             .addAllOutputContexts(new ArrayList<Context>())
776             .setResetContexts(true)
777             .addAllParameters(new ArrayList<Intent.Parameter>())
778             .addAllMessages(new ArrayList<Intent.Message>())
779             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
780             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
781             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
782             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
783             .build();
784     mockIntents.addResponse(expectedResponse);
785 
786     Intent intent = Intent.newBuilder().build();
787 
788     Intent actualResponse = client.updateIntent(intent);
789     Assert.assertEquals(expectedResponse, actualResponse);
790 
791     List<AbstractMessage> actualRequests = mockIntents.getRequests();
792     Assert.assertEquals(1, actualRequests.size());
793     UpdateIntentRequest actualRequest = ((UpdateIntentRequest) actualRequests.get(0));
794 
795     Assert.assertEquals(intent, actualRequest.getIntent());
796     Assert.assertTrue(
797         channelProvider.isHeaderSent(
798             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
799             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
800   }
801 
802   @Test
updateIntentExceptionTest()803   public void updateIntentExceptionTest() throws Exception {
804     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
805     mockIntents.addException(exception);
806 
807     try {
808       Intent intent = Intent.newBuilder().build();
809       client.updateIntent(intent);
810       Assert.fail("No exception raised");
811     } catch (InvalidArgumentException e) {
812       // Expected exception.
813     }
814   }
815 
816   @Test
updateIntentTest2()817   public void updateIntentTest2() throws Exception {
818     Intent expectedResponse =
819         Intent.newBuilder()
820             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
821             .setDisplayName("displayName1714148973")
822             .setPriority(-1165461084)
823             .setIsFallback(true)
824             .setMlEnabled(true)
825             .setMlDisabled(true)
826             .setLiveAgentHandoff(true)
827             .setEndInteraction(true)
828             .addAllInputContextNames(new ArrayList<String>())
829             .addAllEvents(new ArrayList<String>())
830             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
831             .setAction("action-1422950858")
832             .addAllOutputContexts(new ArrayList<Context>())
833             .setResetContexts(true)
834             .addAllParameters(new ArrayList<Intent.Parameter>())
835             .addAllMessages(new ArrayList<Intent.Message>())
836             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
837             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
838             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
839             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
840             .build();
841     mockIntents.addResponse(expectedResponse);
842 
843     Intent intent = Intent.newBuilder().build();
844     FieldMask updateMask = FieldMask.newBuilder().build();
845 
846     Intent actualResponse = client.updateIntent(intent, updateMask);
847     Assert.assertEquals(expectedResponse, actualResponse);
848 
849     List<AbstractMessage> actualRequests = mockIntents.getRequests();
850     Assert.assertEquals(1, actualRequests.size());
851     UpdateIntentRequest actualRequest = ((UpdateIntentRequest) actualRequests.get(0));
852 
853     Assert.assertEquals(intent, actualRequest.getIntent());
854     Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
855     Assert.assertTrue(
856         channelProvider.isHeaderSent(
857             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
858             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
859   }
860 
861   @Test
updateIntentExceptionTest2()862   public void updateIntentExceptionTest2() throws Exception {
863     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
864     mockIntents.addException(exception);
865 
866     try {
867       Intent intent = Intent.newBuilder().build();
868       FieldMask updateMask = FieldMask.newBuilder().build();
869       client.updateIntent(intent, updateMask);
870       Assert.fail("No exception raised");
871     } catch (InvalidArgumentException e) {
872       // Expected exception.
873     }
874   }
875 
876   @Test
updateIntentTest3()877   public void updateIntentTest3() throws Exception {
878     Intent expectedResponse =
879         Intent.newBuilder()
880             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
881             .setDisplayName("displayName1714148973")
882             .setPriority(-1165461084)
883             .setIsFallback(true)
884             .setMlEnabled(true)
885             .setMlDisabled(true)
886             .setLiveAgentHandoff(true)
887             .setEndInteraction(true)
888             .addAllInputContextNames(new ArrayList<String>())
889             .addAllEvents(new ArrayList<String>())
890             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
891             .setAction("action-1422950858")
892             .addAllOutputContexts(new ArrayList<Context>())
893             .setResetContexts(true)
894             .addAllParameters(new ArrayList<Intent.Parameter>())
895             .addAllMessages(new ArrayList<Intent.Message>())
896             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
897             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
898             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
899             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
900             .build();
901     mockIntents.addResponse(expectedResponse);
902 
903     Intent intent = Intent.newBuilder().build();
904     String languageCode = "languageCode-2092349083";
905 
906     Intent actualResponse = client.updateIntent(intent, languageCode);
907     Assert.assertEquals(expectedResponse, actualResponse);
908 
909     List<AbstractMessage> actualRequests = mockIntents.getRequests();
910     Assert.assertEquals(1, actualRequests.size());
911     UpdateIntentRequest actualRequest = ((UpdateIntentRequest) actualRequests.get(0));
912 
913     Assert.assertEquals(intent, actualRequest.getIntent());
914     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
915     Assert.assertTrue(
916         channelProvider.isHeaderSent(
917             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
918             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
919   }
920 
921   @Test
updateIntentExceptionTest3()922   public void updateIntentExceptionTest3() throws Exception {
923     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
924     mockIntents.addException(exception);
925 
926     try {
927       Intent intent = Intent.newBuilder().build();
928       String languageCode = "languageCode-2092349083";
929       client.updateIntent(intent, languageCode);
930       Assert.fail("No exception raised");
931     } catch (InvalidArgumentException e) {
932       // Expected exception.
933     }
934   }
935 
936   @Test
updateIntentTest4()937   public void updateIntentTest4() throws Exception {
938     Intent expectedResponse =
939         Intent.newBuilder()
940             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
941             .setDisplayName("displayName1714148973")
942             .setPriority(-1165461084)
943             .setIsFallback(true)
944             .setMlEnabled(true)
945             .setMlDisabled(true)
946             .setLiveAgentHandoff(true)
947             .setEndInteraction(true)
948             .addAllInputContextNames(new ArrayList<String>())
949             .addAllEvents(new ArrayList<String>())
950             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
951             .setAction("action-1422950858")
952             .addAllOutputContexts(new ArrayList<Context>())
953             .setResetContexts(true)
954             .addAllParameters(new ArrayList<Intent.Parameter>())
955             .addAllMessages(new ArrayList<Intent.Message>())
956             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
957             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
958             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
959             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
960             .build();
961     mockIntents.addResponse(expectedResponse);
962 
963     Intent intent = Intent.newBuilder().build();
964     String languageCode = "languageCode-2092349083";
965     FieldMask updateMask = FieldMask.newBuilder().build();
966 
967     Intent actualResponse = client.updateIntent(intent, languageCode, updateMask);
968     Assert.assertEquals(expectedResponse, actualResponse);
969 
970     List<AbstractMessage> actualRequests = mockIntents.getRequests();
971     Assert.assertEquals(1, actualRequests.size());
972     UpdateIntentRequest actualRequest = ((UpdateIntentRequest) actualRequests.get(0));
973 
974     Assert.assertEquals(intent, actualRequest.getIntent());
975     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
976     Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
977     Assert.assertTrue(
978         channelProvider.isHeaderSent(
979             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
980             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
981   }
982 
983   @Test
updateIntentExceptionTest4()984   public void updateIntentExceptionTest4() throws Exception {
985     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
986     mockIntents.addException(exception);
987 
988     try {
989       Intent intent = Intent.newBuilder().build();
990       String languageCode = "languageCode-2092349083";
991       FieldMask updateMask = FieldMask.newBuilder().build();
992       client.updateIntent(intent, languageCode, updateMask);
993       Assert.fail("No exception raised");
994     } catch (InvalidArgumentException e) {
995       // Expected exception.
996     }
997   }
998 
999   @Test
deleteIntentTest()1000   public void deleteIntentTest() throws Exception {
1001     Empty expectedResponse = Empty.newBuilder().build();
1002     mockIntents.addResponse(expectedResponse);
1003 
1004     IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]");
1005 
1006     client.deleteIntent(name);
1007 
1008     List<AbstractMessage> actualRequests = mockIntents.getRequests();
1009     Assert.assertEquals(1, actualRequests.size());
1010     DeleteIntentRequest actualRequest = ((DeleteIntentRequest) actualRequests.get(0));
1011 
1012     Assert.assertEquals(name.toString(), actualRequest.getName());
1013     Assert.assertTrue(
1014         channelProvider.isHeaderSent(
1015             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1016             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1017   }
1018 
1019   @Test
deleteIntentExceptionTest()1020   public void deleteIntentExceptionTest() throws Exception {
1021     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1022     mockIntents.addException(exception);
1023 
1024     try {
1025       IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]");
1026       client.deleteIntent(name);
1027       Assert.fail("No exception raised");
1028     } catch (InvalidArgumentException e) {
1029       // Expected exception.
1030     }
1031   }
1032 
1033   @Test
deleteIntentTest2()1034   public void deleteIntentTest2() throws Exception {
1035     Empty expectedResponse = Empty.newBuilder().build();
1036     mockIntents.addResponse(expectedResponse);
1037 
1038     String name = "name3373707";
1039 
1040     client.deleteIntent(name);
1041 
1042     List<AbstractMessage> actualRequests = mockIntents.getRequests();
1043     Assert.assertEquals(1, actualRequests.size());
1044     DeleteIntentRequest actualRequest = ((DeleteIntentRequest) actualRequests.get(0));
1045 
1046     Assert.assertEquals(name, actualRequest.getName());
1047     Assert.assertTrue(
1048         channelProvider.isHeaderSent(
1049             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1050             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1051   }
1052 
1053   @Test
deleteIntentExceptionTest2()1054   public void deleteIntentExceptionTest2() throws Exception {
1055     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1056     mockIntents.addException(exception);
1057 
1058     try {
1059       String name = "name3373707";
1060       client.deleteIntent(name);
1061       Assert.fail("No exception raised");
1062     } catch (InvalidArgumentException e) {
1063       // Expected exception.
1064     }
1065   }
1066 
1067   @Test
batchUpdateIntentsTest()1068   public void batchUpdateIntentsTest() throws Exception {
1069     BatchUpdateIntentsResponse expectedResponse =
1070         BatchUpdateIntentsResponse.newBuilder().addAllIntents(new ArrayList<Intent>()).build();
1071     Operation resultOperation =
1072         Operation.newBuilder()
1073             .setName("batchUpdateIntentsTest")
1074             .setDone(true)
1075             .setResponse(Any.pack(expectedResponse))
1076             .build();
1077     mockIntents.addResponse(resultOperation);
1078 
1079     AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
1080     IntentBatch intentBatchInline = IntentBatch.newBuilder().build();
1081 
1082     BatchUpdateIntentsResponse actualResponse =
1083         client.batchUpdateIntentsAsync(parent, intentBatchInline).get();
1084     Assert.assertEquals(expectedResponse, actualResponse);
1085 
1086     List<AbstractMessage> actualRequests = mockIntents.getRequests();
1087     Assert.assertEquals(1, actualRequests.size());
1088     BatchUpdateIntentsRequest actualRequest = ((BatchUpdateIntentsRequest) actualRequests.get(0));
1089 
1090     Assert.assertEquals(parent.toString(), actualRequest.getParent());
1091     Assert.assertEquals(intentBatchInline, actualRequest.getIntentBatchInline());
1092     Assert.assertTrue(
1093         channelProvider.isHeaderSent(
1094             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1095             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1096   }
1097 
1098   @Test
batchUpdateIntentsExceptionTest()1099   public void batchUpdateIntentsExceptionTest() throws Exception {
1100     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1101     mockIntents.addException(exception);
1102 
1103     try {
1104       AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
1105       IntentBatch intentBatchInline = IntentBatch.newBuilder().build();
1106       client.batchUpdateIntentsAsync(parent, intentBatchInline).get();
1107       Assert.fail("No exception raised");
1108     } catch (ExecutionException e) {
1109       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
1110       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
1111       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
1112     }
1113   }
1114 
1115   @Test
batchUpdateIntentsTest2()1116   public void batchUpdateIntentsTest2() throws Exception {
1117     BatchUpdateIntentsResponse expectedResponse =
1118         BatchUpdateIntentsResponse.newBuilder().addAllIntents(new ArrayList<Intent>()).build();
1119     Operation resultOperation =
1120         Operation.newBuilder()
1121             .setName("batchUpdateIntentsTest")
1122             .setDone(true)
1123             .setResponse(Any.pack(expectedResponse))
1124             .build();
1125     mockIntents.addResponse(resultOperation);
1126 
1127     AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
1128     String intentBatchUri = "intentBatchUri544125582";
1129 
1130     BatchUpdateIntentsResponse actualResponse =
1131         client.batchUpdateIntentsAsync(parent, intentBatchUri).get();
1132     Assert.assertEquals(expectedResponse, actualResponse);
1133 
1134     List<AbstractMessage> actualRequests = mockIntents.getRequests();
1135     Assert.assertEquals(1, actualRequests.size());
1136     BatchUpdateIntentsRequest actualRequest = ((BatchUpdateIntentsRequest) actualRequests.get(0));
1137 
1138     Assert.assertEquals(parent.toString(), actualRequest.getParent());
1139     Assert.assertEquals(intentBatchUri, actualRequest.getIntentBatchUri());
1140     Assert.assertTrue(
1141         channelProvider.isHeaderSent(
1142             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1143             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1144   }
1145 
1146   @Test
batchUpdateIntentsExceptionTest2()1147   public void batchUpdateIntentsExceptionTest2() throws Exception {
1148     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1149     mockIntents.addException(exception);
1150 
1151     try {
1152       AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
1153       String intentBatchUri = "intentBatchUri544125582";
1154       client.batchUpdateIntentsAsync(parent, intentBatchUri).get();
1155       Assert.fail("No exception raised");
1156     } catch (ExecutionException e) {
1157       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
1158       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
1159       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
1160     }
1161   }
1162 
1163   @Test
batchUpdateIntentsTest3()1164   public void batchUpdateIntentsTest3() throws Exception {
1165     BatchUpdateIntentsResponse expectedResponse =
1166         BatchUpdateIntentsResponse.newBuilder().addAllIntents(new ArrayList<Intent>()).build();
1167     Operation resultOperation =
1168         Operation.newBuilder()
1169             .setName("batchUpdateIntentsTest")
1170             .setDone(true)
1171             .setResponse(Any.pack(expectedResponse))
1172             .build();
1173     mockIntents.addResponse(resultOperation);
1174 
1175     String parent = "parent-995424086";
1176     IntentBatch intentBatchInline = IntentBatch.newBuilder().build();
1177 
1178     BatchUpdateIntentsResponse actualResponse =
1179         client.batchUpdateIntentsAsync(parent, intentBatchInline).get();
1180     Assert.assertEquals(expectedResponse, actualResponse);
1181 
1182     List<AbstractMessage> actualRequests = mockIntents.getRequests();
1183     Assert.assertEquals(1, actualRequests.size());
1184     BatchUpdateIntentsRequest actualRequest = ((BatchUpdateIntentsRequest) actualRequests.get(0));
1185 
1186     Assert.assertEquals(parent, actualRequest.getParent());
1187     Assert.assertEquals(intentBatchInline, actualRequest.getIntentBatchInline());
1188     Assert.assertTrue(
1189         channelProvider.isHeaderSent(
1190             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1191             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1192   }
1193 
1194   @Test
batchUpdateIntentsExceptionTest3()1195   public void batchUpdateIntentsExceptionTest3() throws Exception {
1196     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1197     mockIntents.addException(exception);
1198 
1199     try {
1200       String parent = "parent-995424086";
1201       IntentBatch intentBatchInline = IntentBatch.newBuilder().build();
1202       client.batchUpdateIntentsAsync(parent, intentBatchInline).get();
1203       Assert.fail("No exception raised");
1204     } catch (ExecutionException e) {
1205       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
1206       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
1207       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
1208     }
1209   }
1210 
1211   @Test
batchUpdateIntentsTest4()1212   public void batchUpdateIntentsTest4() throws Exception {
1213     BatchUpdateIntentsResponse expectedResponse =
1214         BatchUpdateIntentsResponse.newBuilder().addAllIntents(new ArrayList<Intent>()).build();
1215     Operation resultOperation =
1216         Operation.newBuilder()
1217             .setName("batchUpdateIntentsTest")
1218             .setDone(true)
1219             .setResponse(Any.pack(expectedResponse))
1220             .build();
1221     mockIntents.addResponse(resultOperation);
1222 
1223     String parent = "parent-995424086";
1224     String intentBatchUri = "intentBatchUri544125582";
1225 
1226     BatchUpdateIntentsResponse actualResponse =
1227         client.batchUpdateIntentsAsync(parent, intentBatchUri).get();
1228     Assert.assertEquals(expectedResponse, actualResponse);
1229 
1230     List<AbstractMessage> actualRequests = mockIntents.getRequests();
1231     Assert.assertEquals(1, actualRequests.size());
1232     BatchUpdateIntentsRequest actualRequest = ((BatchUpdateIntentsRequest) actualRequests.get(0));
1233 
1234     Assert.assertEquals(parent, actualRequest.getParent());
1235     Assert.assertEquals(intentBatchUri, actualRequest.getIntentBatchUri());
1236     Assert.assertTrue(
1237         channelProvider.isHeaderSent(
1238             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1239             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1240   }
1241 
1242   @Test
batchUpdateIntentsExceptionTest4()1243   public void batchUpdateIntentsExceptionTest4() throws Exception {
1244     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1245     mockIntents.addException(exception);
1246 
1247     try {
1248       String parent = "parent-995424086";
1249       String intentBatchUri = "intentBatchUri544125582";
1250       client.batchUpdateIntentsAsync(parent, intentBatchUri).get();
1251       Assert.fail("No exception raised");
1252     } catch (ExecutionException e) {
1253       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
1254       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
1255       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
1256     }
1257   }
1258 
1259   @Test
batchDeleteIntentsTest()1260   public void batchDeleteIntentsTest() throws Exception {
1261     Empty expectedResponse = Empty.newBuilder().build();
1262     Operation resultOperation =
1263         Operation.newBuilder()
1264             .setName("batchDeleteIntentsTest")
1265             .setDone(true)
1266             .setResponse(Any.pack(expectedResponse))
1267             .build();
1268     mockIntents.addResponse(resultOperation);
1269 
1270     AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
1271     List<Intent> intents = new ArrayList<>();
1272 
1273     client.batchDeleteIntentsAsync(parent, intents).get();
1274 
1275     List<AbstractMessage> actualRequests = mockIntents.getRequests();
1276     Assert.assertEquals(1, actualRequests.size());
1277     BatchDeleteIntentsRequest actualRequest = ((BatchDeleteIntentsRequest) actualRequests.get(0));
1278 
1279     Assert.assertEquals(parent.toString(), actualRequest.getParent());
1280     Assert.assertEquals(intents, actualRequest.getIntentsList());
1281     Assert.assertTrue(
1282         channelProvider.isHeaderSent(
1283             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1284             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1285   }
1286 
1287   @Test
batchDeleteIntentsExceptionTest()1288   public void batchDeleteIntentsExceptionTest() throws Exception {
1289     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1290     mockIntents.addException(exception);
1291 
1292     try {
1293       AgentName parent = AgentName.ofProjectAgentName("[PROJECT]");
1294       List<Intent> intents = new ArrayList<>();
1295       client.batchDeleteIntentsAsync(parent, intents).get();
1296       Assert.fail("No exception raised");
1297     } catch (ExecutionException e) {
1298       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
1299       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
1300       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
1301     }
1302   }
1303 
1304   @Test
batchDeleteIntentsTest2()1305   public void batchDeleteIntentsTest2() throws Exception {
1306     Empty expectedResponse = Empty.newBuilder().build();
1307     Operation resultOperation =
1308         Operation.newBuilder()
1309             .setName("batchDeleteIntentsTest")
1310             .setDone(true)
1311             .setResponse(Any.pack(expectedResponse))
1312             .build();
1313     mockIntents.addResponse(resultOperation);
1314 
1315     String parent = "parent-995424086";
1316     List<Intent> intents = new ArrayList<>();
1317 
1318     client.batchDeleteIntentsAsync(parent, intents).get();
1319 
1320     List<AbstractMessage> actualRequests = mockIntents.getRequests();
1321     Assert.assertEquals(1, actualRequests.size());
1322     BatchDeleteIntentsRequest actualRequest = ((BatchDeleteIntentsRequest) actualRequests.get(0));
1323 
1324     Assert.assertEquals(parent, actualRequest.getParent());
1325     Assert.assertEquals(intents, actualRequest.getIntentsList());
1326     Assert.assertTrue(
1327         channelProvider.isHeaderSent(
1328             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1329             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1330   }
1331 
1332   @Test
batchDeleteIntentsExceptionTest2()1333   public void batchDeleteIntentsExceptionTest2() throws Exception {
1334     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1335     mockIntents.addException(exception);
1336 
1337     try {
1338       String parent = "parent-995424086";
1339       List<Intent> intents = new ArrayList<>();
1340       client.batchDeleteIntentsAsync(parent, intents).get();
1341       Assert.fail("No exception raised");
1342     } catch (ExecutionException e) {
1343       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
1344       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
1345       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
1346     }
1347   }
1348 
1349   @Test
listLocationsTest()1350   public void listLocationsTest() throws Exception {
1351     Location responsesElement = Location.newBuilder().build();
1352     ListLocationsResponse expectedResponse =
1353         ListLocationsResponse.newBuilder()
1354             .setNextPageToken("")
1355             .addAllLocations(Arrays.asList(responsesElement))
1356             .build();
1357     mockLocations.addResponse(expectedResponse);
1358 
1359     ListLocationsRequest request =
1360         ListLocationsRequest.newBuilder()
1361             .setName("name3373707")
1362             .setFilter("filter-1274492040")
1363             .setPageSize(883849137)
1364             .setPageToken("pageToken873572522")
1365             .build();
1366 
1367     ListLocationsPagedResponse pagedListResponse = client.listLocations(request);
1368 
1369     List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1370 
1371     Assert.assertEquals(1, resources.size());
1372     Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0));
1373 
1374     List<AbstractMessage> actualRequests = mockLocations.getRequests();
1375     Assert.assertEquals(1, actualRequests.size());
1376     ListLocationsRequest actualRequest = ((ListLocationsRequest) actualRequests.get(0));
1377 
1378     Assert.assertEquals(request.getName(), actualRequest.getName());
1379     Assert.assertEquals(request.getFilter(), actualRequest.getFilter());
1380     Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
1381     Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
1382     Assert.assertTrue(
1383         channelProvider.isHeaderSent(
1384             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1385             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1386   }
1387 
1388   @Test
listLocationsExceptionTest()1389   public void listLocationsExceptionTest() throws Exception {
1390     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1391     mockLocations.addException(exception);
1392 
1393     try {
1394       ListLocationsRequest request =
1395           ListLocationsRequest.newBuilder()
1396               .setName("name3373707")
1397               .setFilter("filter-1274492040")
1398               .setPageSize(883849137)
1399               .setPageToken("pageToken873572522")
1400               .build();
1401       client.listLocations(request);
1402       Assert.fail("No exception raised");
1403     } catch (InvalidArgumentException e) {
1404       // Expected exception.
1405     }
1406   }
1407 
1408   @Test
getLocationTest()1409   public void getLocationTest() throws Exception {
1410     Location expectedResponse =
1411         Location.newBuilder()
1412             .setName("name3373707")
1413             .setLocationId("locationId1541836720")
1414             .setDisplayName("displayName1714148973")
1415             .putAllLabels(new HashMap<String, String>())
1416             .setMetadata(Any.newBuilder().build())
1417             .build();
1418     mockLocations.addResponse(expectedResponse);
1419 
1420     GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
1421 
1422     Location actualResponse = client.getLocation(request);
1423     Assert.assertEquals(expectedResponse, actualResponse);
1424 
1425     List<AbstractMessage> actualRequests = mockLocations.getRequests();
1426     Assert.assertEquals(1, actualRequests.size());
1427     GetLocationRequest actualRequest = ((GetLocationRequest) actualRequests.get(0));
1428 
1429     Assert.assertEquals(request.getName(), actualRequest.getName());
1430     Assert.assertTrue(
1431         channelProvider.isHeaderSent(
1432             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1433             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1434   }
1435 
1436   @Test
getLocationExceptionTest()1437   public void getLocationExceptionTest() throws Exception {
1438     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1439     mockLocations.addException(exception);
1440 
1441     try {
1442       GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
1443       client.getLocation(request);
1444       Assert.fail("No exception raised");
1445     } catch (InvalidArgumentException e) {
1446       // Expected exception.
1447     }
1448   }
1449 }
1450