• 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.v2;
18 
19 import static com.google.cloud.dialogflow.v2.IntentsClient.ListIntentsPagedResponse;
20 import static com.google.cloud.dialogflow.v2.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.ofProjectName("[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.ofProjectName("[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.ofProjectName("[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.ofProjectName("[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             .setMlDisabled(true)
288             .setLiveAgentHandoff(true)
289             .setEndInteraction(true)
290             .addAllInputContextNames(new ArrayList<String>())
291             .addAllEvents(new ArrayList<String>())
292             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
293             .setAction("action-1422950858")
294             .addAllOutputContexts(new ArrayList<Context>())
295             .setResetContexts(true)
296             .addAllParameters(new ArrayList<Intent.Parameter>())
297             .addAllMessages(new ArrayList<Intent.Message>())
298             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
299             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
300             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
301             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
302             .build();
303     mockIntents.addResponse(expectedResponse);
304 
305     IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]");
306 
307     Intent actualResponse = client.getIntent(name);
308     Assert.assertEquals(expectedResponse, actualResponse);
309 
310     List<AbstractMessage> actualRequests = mockIntents.getRequests();
311     Assert.assertEquals(1, actualRequests.size());
312     GetIntentRequest actualRequest = ((GetIntentRequest) actualRequests.get(0));
313 
314     Assert.assertEquals(name.toString(), actualRequest.getName());
315     Assert.assertTrue(
316         channelProvider.isHeaderSent(
317             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
318             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
319   }
320 
321   @Test
getIntentExceptionTest()322   public void getIntentExceptionTest() throws Exception {
323     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
324     mockIntents.addException(exception);
325 
326     try {
327       IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]");
328       client.getIntent(name);
329       Assert.fail("No exception raised");
330     } catch (InvalidArgumentException e) {
331       // Expected exception.
332     }
333   }
334 
335   @Test
getIntentTest2()336   public void getIntentTest2() throws Exception {
337     Intent expectedResponse =
338         Intent.newBuilder()
339             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
340             .setDisplayName("displayName1714148973")
341             .setPriority(-1165461084)
342             .setIsFallback(true)
343             .setMlDisabled(true)
344             .setLiveAgentHandoff(true)
345             .setEndInteraction(true)
346             .addAllInputContextNames(new ArrayList<String>())
347             .addAllEvents(new ArrayList<String>())
348             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
349             .setAction("action-1422950858")
350             .addAllOutputContexts(new ArrayList<Context>())
351             .setResetContexts(true)
352             .addAllParameters(new ArrayList<Intent.Parameter>())
353             .addAllMessages(new ArrayList<Intent.Message>())
354             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
355             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
356             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
357             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
358             .build();
359     mockIntents.addResponse(expectedResponse);
360 
361     String name = "name3373707";
362 
363     Intent actualResponse = client.getIntent(name);
364     Assert.assertEquals(expectedResponse, actualResponse);
365 
366     List<AbstractMessage> actualRequests = mockIntents.getRequests();
367     Assert.assertEquals(1, actualRequests.size());
368     GetIntentRequest actualRequest = ((GetIntentRequest) actualRequests.get(0));
369 
370     Assert.assertEquals(name, actualRequest.getName());
371     Assert.assertTrue(
372         channelProvider.isHeaderSent(
373             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
374             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
375   }
376 
377   @Test
getIntentExceptionTest2()378   public void getIntentExceptionTest2() throws Exception {
379     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
380     mockIntents.addException(exception);
381 
382     try {
383       String name = "name3373707";
384       client.getIntent(name);
385       Assert.fail("No exception raised");
386     } catch (InvalidArgumentException e) {
387       // Expected exception.
388     }
389   }
390 
391   @Test
getIntentTest3()392   public void getIntentTest3() throws Exception {
393     Intent expectedResponse =
394         Intent.newBuilder()
395             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
396             .setDisplayName("displayName1714148973")
397             .setPriority(-1165461084)
398             .setIsFallback(true)
399             .setMlDisabled(true)
400             .setLiveAgentHandoff(true)
401             .setEndInteraction(true)
402             .addAllInputContextNames(new ArrayList<String>())
403             .addAllEvents(new ArrayList<String>())
404             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
405             .setAction("action-1422950858")
406             .addAllOutputContexts(new ArrayList<Context>())
407             .setResetContexts(true)
408             .addAllParameters(new ArrayList<Intent.Parameter>())
409             .addAllMessages(new ArrayList<Intent.Message>())
410             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
411             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
412             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
413             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
414             .build();
415     mockIntents.addResponse(expectedResponse);
416 
417     IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]");
418     String languageCode = "languageCode-2092349083";
419 
420     Intent actualResponse = client.getIntent(name, languageCode);
421     Assert.assertEquals(expectedResponse, actualResponse);
422 
423     List<AbstractMessage> actualRequests = mockIntents.getRequests();
424     Assert.assertEquals(1, actualRequests.size());
425     GetIntentRequest actualRequest = ((GetIntentRequest) actualRequests.get(0));
426 
427     Assert.assertEquals(name.toString(), actualRequest.getName());
428     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
429     Assert.assertTrue(
430         channelProvider.isHeaderSent(
431             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
432             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
433   }
434 
435   @Test
getIntentExceptionTest3()436   public void getIntentExceptionTest3() throws Exception {
437     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
438     mockIntents.addException(exception);
439 
440     try {
441       IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]");
442       String languageCode = "languageCode-2092349083";
443       client.getIntent(name, languageCode);
444       Assert.fail("No exception raised");
445     } catch (InvalidArgumentException e) {
446       // Expected exception.
447     }
448   }
449 
450   @Test
getIntentTest4()451   public void getIntentTest4() throws Exception {
452     Intent expectedResponse =
453         Intent.newBuilder()
454             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
455             .setDisplayName("displayName1714148973")
456             .setPriority(-1165461084)
457             .setIsFallback(true)
458             .setMlDisabled(true)
459             .setLiveAgentHandoff(true)
460             .setEndInteraction(true)
461             .addAllInputContextNames(new ArrayList<String>())
462             .addAllEvents(new ArrayList<String>())
463             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
464             .setAction("action-1422950858")
465             .addAllOutputContexts(new ArrayList<Context>())
466             .setResetContexts(true)
467             .addAllParameters(new ArrayList<Intent.Parameter>())
468             .addAllMessages(new ArrayList<Intent.Message>())
469             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
470             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
471             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
472             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
473             .build();
474     mockIntents.addResponse(expectedResponse);
475 
476     String name = "name3373707";
477     String languageCode = "languageCode-2092349083";
478 
479     Intent actualResponse = client.getIntent(name, languageCode);
480     Assert.assertEquals(expectedResponse, actualResponse);
481 
482     List<AbstractMessage> actualRequests = mockIntents.getRequests();
483     Assert.assertEquals(1, actualRequests.size());
484     GetIntentRequest actualRequest = ((GetIntentRequest) actualRequests.get(0));
485 
486     Assert.assertEquals(name, actualRequest.getName());
487     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
488     Assert.assertTrue(
489         channelProvider.isHeaderSent(
490             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
491             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
492   }
493 
494   @Test
getIntentExceptionTest4()495   public void getIntentExceptionTest4() throws Exception {
496     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
497     mockIntents.addException(exception);
498 
499     try {
500       String name = "name3373707";
501       String languageCode = "languageCode-2092349083";
502       client.getIntent(name, languageCode);
503       Assert.fail("No exception raised");
504     } catch (InvalidArgumentException e) {
505       // Expected exception.
506     }
507   }
508 
509   @Test
createIntentTest()510   public void createIntentTest() throws Exception {
511     Intent expectedResponse =
512         Intent.newBuilder()
513             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
514             .setDisplayName("displayName1714148973")
515             .setPriority(-1165461084)
516             .setIsFallback(true)
517             .setMlDisabled(true)
518             .setLiveAgentHandoff(true)
519             .setEndInteraction(true)
520             .addAllInputContextNames(new ArrayList<String>())
521             .addAllEvents(new ArrayList<String>())
522             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
523             .setAction("action-1422950858")
524             .addAllOutputContexts(new ArrayList<Context>())
525             .setResetContexts(true)
526             .addAllParameters(new ArrayList<Intent.Parameter>())
527             .addAllMessages(new ArrayList<Intent.Message>())
528             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
529             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
530             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
531             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
532             .build();
533     mockIntents.addResponse(expectedResponse);
534 
535     AgentName parent = AgentName.ofProjectName("[PROJECT]");
536     Intent intent = Intent.newBuilder().build();
537 
538     Intent actualResponse = client.createIntent(parent, intent);
539     Assert.assertEquals(expectedResponse, actualResponse);
540 
541     List<AbstractMessage> actualRequests = mockIntents.getRequests();
542     Assert.assertEquals(1, actualRequests.size());
543     CreateIntentRequest actualRequest = ((CreateIntentRequest) actualRequests.get(0));
544 
545     Assert.assertEquals(parent.toString(), actualRequest.getParent());
546     Assert.assertEquals(intent, actualRequest.getIntent());
547     Assert.assertTrue(
548         channelProvider.isHeaderSent(
549             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
550             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
551   }
552 
553   @Test
createIntentExceptionTest()554   public void createIntentExceptionTest() throws Exception {
555     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
556     mockIntents.addException(exception);
557 
558     try {
559       AgentName parent = AgentName.ofProjectName("[PROJECT]");
560       Intent intent = Intent.newBuilder().build();
561       client.createIntent(parent, intent);
562       Assert.fail("No exception raised");
563     } catch (InvalidArgumentException e) {
564       // Expected exception.
565     }
566   }
567 
568   @Test
createIntentTest2()569   public void createIntentTest2() throws Exception {
570     Intent expectedResponse =
571         Intent.newBuilder()
572             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
573             .setDisplayName("displayName1714148973")
574             .setPriority(-1165461084)
575             .setIsFallback(true)
576             .setMlDisabled(true)
577             .setLiveAgentHandoff(true)
578             .setEndInteraction(true)
579             .addAllInputContextNames(new ArrayList<String>())
580             .addAllEvents(new ArrayList<String>())
581             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
582             .setAction("action-1422950858")
583             .addAllOutputContexts(new ArrayList<Context>())
584             .setResetContexts(true)
585             .addAllParameters(new ArrayList<Intent.Parameter>())
586             .addAllMessages(new ArrayList<Intent.Message>())
587             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
588             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
589             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
590             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
591             .build();
592     mockIntents.addResponse(expectedResponse);
593 
594     String parent = "parent-995424086";
595     Intent intent = Intent.newBuilder().build();
596 
597     Intent actualResponse = client.createIntent(parent, intent);
598     Assert.assertEquals(expectedResponse, actualResponse);
599 
600     List<AbstractMessage> actualRequests = mockIntents.getRequests();
601     Assert.assertEquals(1, actualRequests.size());
602     CreateIntentRequest actualRequest = ((CreateIntentRequest) actualRequests.get(0));
603 
604     Assert.assertEquals(parent, actualRequest.getParent());
605     Assert.assertEquals(intent, actualRequest.getIntent());
606     Assert.assertTrue(
607         channelProvider.isHeaderSent(
608             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
609             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
610   }
611 
612   @Test
createIntentExceptionTest2()613   public void createIntentExceptionTest2() throws Exception {
614     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
615     mockIntents.addException(exception);
616 
617     try {
618       String parent = "parent-995424086";
619       Intent intent = Intent.newBuilder().build();
620       client.createIntent(parent, intent);
621       Assert.fail("No exception raised");
622     } catch (InvalidArgumentException e) {
623       // Expected exception.
624     }
625   }
626 
627   @Test
createIntentTest3()628   public void createIntentTest3() throws Exception {
629     Intent expectedResponse =
630         Intent.newBuilder()
631             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
632             .setDisplayName("displayName1714148973")
633             .setPriority(-1165461084)
634             .setIsFallback(true)
635             .setMlDisabled(true)
636             .setLiveAgentHandoff(true)
637             .setEndInteraction(true)
638             .addAllInputContextNames(new ArrayList<String>())
639             .addAllEvents(new ArrayList<String>())
640             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
641             .setAction("action-1422950858")
642             .addAllOutputContexts(new ArrayList<Context>())
643             .setResetContexts(true)
644             .addAllParameters(new ArrayList<Intent.Parameter>())
645             .addAllMessages(new ArrayList<Intent.Message>())
646             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
647             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
648             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
649             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
650             .build();
651     mockIntents.addResponse(expectedResponse);
652 
653     AgentName parent = AgentName.ofProjectName("[PROJECT]");
654     Intent intent = Intent.newBuilder().build();
655     String languageCode = "languageCode-2092349083";
656 
657     Intent actualResponse = client.createIntent(parent, intent, languageCode);
658     Assert.assertEquals(expectedResponse, actualResponse);
659 
660     List<AbstractMessage> actualRequests = mockIntents.getRequests();
661     Assert.assertEquals(1, actualRequests.size());
662     CreateIntentRequest actualRequest = ((CreateIntentRequest) actualRequests.get(0));
663 
664     Assert.assertEquals(parent.toString(), actualRequest.getParent());
665     Assert.assertEquals(intent, actualRequest.getIntent());
666     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
667     Assert.assertTrue(
668         channelProvider.isHeaderSent(
669             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
670             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
671   }
672 
673   @Test
createIntentExceptionTest3()674   public void createIntentExceptionTest3() throws Exception {
675     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
676     mockIntents.addException(exception);
677 
678     try {
679       AgentName parent = AgentName.ofProjectName("[PROJECT]");
680       Intent intent = Intent.newBuilder().build();
681       String languageCode = "languageCode-2092349083";
682       client.createIntent(parent, intent, languageCode);
683       Assert.fail("No exception raised");
684     } catch (InvalidArgumentException e) {
685       // Expected exception.
686     }
687   }
688 
689   @Test
createIntentTest4()690   public void createIntentTest4() throws Exception {
691     Intent expectedResponse =
692         Intent.newBuilder()
693             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
694             .setDisplayName("displayName1714148973")
695             .setPriority(-1165461084)
696             .setIsFallback(true)
697             .setMlDisabled(true)
698             .setLiveAgentHandoff(true)
699             .setEndInteraction(true)
700             .addAllInputContextNames(new ArrayList<String>())
701             .addAllEvents(new ArrayList<String>())
702             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
703             .setAction("action-1422950858")
704             .addAllOutputContexts(new ArrayList<Context>())
705             .setResetContexts(true)
706             .addAllParameters(new ArrayList<Intent.Parameter>())
707             .addAllMessages(new ArrayList<Intent.Message>())
708             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
709             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
710             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
711             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
712             .build();
713     mockIntents.addResponse(expectedResponse);
714 
715     String parent = "parent-995424086";
716     Intent intent = Intent.newBuilder().build();
717     String languageCode = "languageCode-2092349083";
718 
719     Intent actualResponse = client.createIntent(parent, intent, languageCode);
720     Assert.assertEquals(expectedResponse, actualResponse);
721 
722     List<AbstractMessage> actualRequests = mockIntents.getRequests();
723     Assert.assertEquals(1, actualRequests.size());
724     CreateIntentRequest actualRequest = ((CreateIntentRequest) actualRequests.get(0));
725 
726     Assert.assertEquals(parent, actualRequest.getParent());
727     Assert.assertEquals(intent, actualRequest.getIntent());
728     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
729     Assert.assertTrue(
730         channelProvider.isHeaderSent(
731             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
732             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
733   }
734 
735   @Test
createIntentExceptionTest4()736   public void createIntentExceptionTest4() throws Exception {
737     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
738     mockIntents.addException(exception);
739 
740     try {
741       String parent = "parent-995424086";
742       Intent intent = Intent.newBuilder().build();
743       String languageCode = "languageCode-2092349083";
744       client.createIntent(parent, intent, languageCode);
745       Assert.fail("No exception raised");
746     } catch (InvalidArgumentException e) {
747       // Expected exception.
748     }
749   }
750 
751   @Test
updateIntentTest()752   public void updateIntentTest() throws Exception {
753     Intent expectedResponse =
754         Intent.newBuilder()
755             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
756             .setDisplayName("displayName1714148973")
757             .setPriority(-1165461084)
758             .setIsFallback(true)
759             .setMlDisabled(true)
760             .setLiveAgentHandoff(true)
761             .setEndInteraction(true)
762             .addAllInputContextNames(new ArrayList<String>())
763             .addAllEvents(new ArrayList<String>())
764             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
765             .setAction("action-1422950858")
766             .addAllOutputContexts(new ArrayList<Context>())
767             .setResetContexts(true)
768             .addAllParameters(new ArrayList<Intent.Parameter>())
769             .addAllMessages(new ArrayList<Intent.Message>())
770             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
771             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
772             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
773             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
774             .build();
775     mockIntents.addResponse(expectedResponse);
776 
777     Intent intent = Intent.newBuilder().build();
778     String languageCode = "languageCode-2092349083";
779 
780     Intent actualResponse = client.updateIntent(intent, languageCode);
781     Assert.assertEquals(expectedResponse, actualResponse);
782 
783     List<AbstractMessage> actualRequests = mockIntents.getRequests();
784     Assert.assertEquals(1, actualRequests.size());
785     UpdateIntentRequest actualRequest = ((UpdateIntentRequest) actualRequests.get(0));
786 
787     Assert.assertEquals(intent, actualRequest.getIntent());
788     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
789     Assert.assertTrue(
790         channelProvider.isHeaderSent(
791             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
792             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
793   }
794 
795   @Test
updateIntentExceptionTest()796   public void updateIntentExceptionTest() throws Exception {
797     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
798     mockIntents.addException(exception);
799 
800     try {
801       Intent intent = Intent.newBuilder().build();
802       String languageCode = "languageCode-2092349083";
803       client.updateIntent(intent, languageCode);
804       Assert.fail("No exception raised");
805     } catch (InvalidArgumentException e) {
806       // Expected exception.
807     }
808   }
809 
810   @Test
updateIntentTest2()811   public void updateIntentTest2() throws Exception {
812     Intent expectedResponse =
813         Intent.newBuilder()
814             .setName(IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]").toString())
815             .setDisplayName("displayName1714148973")
816             .setPriority(-1165461084)
817             .setIsFallback(true)
818             .setMlDisabled(true)
819             .setLiveAgentHandoff(true)
820             .setEndInteraction(true)
821             .addAllInputContextNames(new ArrayList<String>())
822             .addAllEvents(new ArrayList<String>())
823             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
824             .setAction("action-1422950858")
825             .addAllOutputContexts(new ArrayList<Context>())
826             .setResetContexts(true)
827             .addAllParameters(new ArrayList<Intent.Parameter>())
828             .addAllMessages(new ArrayList<Intent.Message>())
829             .addAllDefaultResponsePlatforms(new ArrayList<Intent.Message.Platform>())
830             .setRootFollowupIntentName("rootFollowupIntentName1370087157")
831             .setParentFollowupIntentName("parentFollowupIntentName1233650877")
832             .addAllFollowupIntentInfo(new ArrayList<Intent.FollowupIntentInfo>())
833             .build();
834     mockIntents.addResponse(expectedResponse);
835 
836     Intent intent = Intent.newBuilder().build();
837     String languageCode = "languageCode-2092349083";
838     FieldMask updateMask = FieldMask.newBuilder().build();
839 
840     Intent actualResponse = client.updateIntent(intent, languageCode, updateMask);
841     Assert.assertEquals(expectedResponse, actualResponse);
842 
843     List<AbstractMessage> actualRequests = mockIntents.getRequests();
844     Assert.assertEquals(1, actualRequests.size());
845     UpdateIntentRequest actualRequest = ((UpdateIntentRequest) actualRequests.get(0));
846 
847     Assert.assertEquals(intent, actualRequest.getIntent());
848     Assert.assertEquals(languageCode, actualRequest.getLanguageCode());
849     Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
850     Assert.assertTrue(
851         channelProvider.isHeaderSent(
852             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
853             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
854   }
855 
856   @Test
updateIntentExceptionTest2()857   public void updateIntentExceptionTest2() throws Exception {
858     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
859     mockIntents.addException(exception);
860 
861     try {
862       Intent intent = Intent.newBuilder().build();
863       String languageCode = "languageCode-2092349083";
864       FieldMask updateMask = FieldMask.newBuilder().build();
865       client.updateIntent(intent, languageCode, updateMask);
866       Assert.fail("No exception raised");
867     } catch (InvalidArgumentException e) {
868       // Expected exception.
869     }
870   }
871 
872   @Test
deleteIntentTest()873   public void deleteIntentTest() throws Exception {
874     Empty expectedResponse = Empty.newBuilder().build();
875     mockIntents.addResponse(expectedResponse);
876 
877     IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]");
878 
879     client.deleteIntent(name);
880 
881     List<AbstractMessage> actualRequests = mockIntents.getRequests();
882     Assert.assertEquals(1, actualRequests.size());
883     DeleteIntentRequest actualRequest = ((DeleteIntentRequest) actualRequests.get(0));
884 
885     Assert.assertEquals(name.toString(), actualRequest.getName());
886     Assert.assertTrue(
887         channelProvider.isHeaderSent(
888             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
889             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
890   }
891 
892   @Test
deleteIntentExceptionTest()893   public void deleteIntentExceptionTest() throws Exception {
894     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
895     mockIntents.addException(exception);
896 
897     try {
898       IntentName name = IntentName.ofProjectIntentName("[PROJECT]", "[INTENT]");
899       client.deleteIntent(name);
900       Assert.fail("No exception raised");
901     } catch (InvalidArgumentException e) {
902       // Expected exception.
903     }
904   }
905 
906   @Test
deleteIntentTest2()907   public void deleteIntentTest2() throws Exception {
908     Empty expectedResponse = Empty.newBuilder().build();
909     mockIntents.addResponse(expectedResponse);
910 
911     String name = "name3373707";
912 
913     client.deleteIntent(name);
914 
915     List<AbstractMessage> actualRequests = mockIntents.getRequests();
916     Assert.assertEquals(1, actualRequests.size());
917     DeleteIntentRequest actualRequest = ((DeleteIntentRequest) actualRequests.get(0));
918 
919     Assert.assertEquals(name, actualRequest.getName());
920     Assert.assertTrue(
921         channelProvider.isHeaderSent(
922             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
923             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
924   }
925 
926   @Test
deleteIntentExceptionTest2()927   public void deleteIntentExceptionTest2() throws Exception {
928     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
929     mockIntents.addException(exception);
930 
931     try {
932       String name = "name3373707";
933       client.deleteIntent(name);
934       Assert.fail("No exception raised");
935     } catch (InvalidArgumentException e) {
936       // Expected exception.
937     }
938   }
939 
940   @Test
batchUpdateIntentsTest()941   public void batchUpdateIntentsTest() throws Exception {
942     BatchUpdateIntentsResponse expectedResponse =
943         BatchUpdateIntentsResponse.newBuilder().addAllIntents(new ArrayList<Intent>()).build();
944     Operation resultOperation =
945         Operation.newBuilder()
946             .setName("batchUpdateIntentsTest")
947             .setDone(true)
948             .setResponse(Any.pack(expectedResponse))
949             .build();
950     mockIntents.addResponse(resultOperation);
951 
952     AgentName parent = AgentName.ofProjectName("[PROJECT]");
953     IntentBatch intentBatchInline = IntentBatch.newBuilder().build();
954 
955     BatchUpdateIntentsResponse actualResponse =
956         client.batchUpdateIntentsAsync(parent, intentBatchInline).get();
957     Assert.assertEquals(expectedResponse, actualResponse);
958 
959     List<AbstractMessage> actualRequests = mockIntents.getRequests();
960     Assert.assertEquals(1, actualRequests.size());
961     BatchUpdateIntentsRequest actualRequest = ((BatchUpdateIntentsRequest) actualRequests.get(0));
962 
963     Assert.assertEquals(parent.toString(), actualRequest.getParent());
964     Assert.assertEquals(intentBatchInline, actualRequest.getIntentBatchInline());
965     Assert.assertTrue(
966         channelProvider.isHeaderSent(
967             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
968             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
969   }
970 
971   @Test
batchUpdateIntentsExceptionTest()972   public void batchUpdateIntentsExceptionTest() throws Exception {
973     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
974     mockIntents.addException(exception);
975 
976     try {
977       AgentName parent = AgentName.ofProjectName("[PROJECT]");
978       IntentBatch intentBatchInline = IntentBatch.newBuilder().build();
979       client.batchUpdateIntentsAsync(parent, intentBatchInline).get();
980       Assert.fail("No exception raised");
981     } catch (ExecutionException e) {
982       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
983       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
984       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
985     }
986   }
987 
988   @Test
batchUpdateIntentsTest2()989   public void batchUpdateIntentsTest2() throws Exception {
990     BatchUpdateIntentsResponse expectedResponse =
991         BatchUpdateIntentsResponse.newBuilder().addAllIntents(new ArrayList<Intent>()).build();
992     Operation resultOperation =
993         Operation.newBuilder()
994             .setName("batchUpdateIntentsTest")
995             .setDone(true)
996             .setResponse(Any.pack(expectedResponse))
997             .build();
998     mockIntents.addResponse(resultOperation);
999 
1000     AgentName parent = AgentName.ofProjectName("[PROJECT]");
1001     String intentBatchUri = "intentBatchUri544125582";
1002 
1003     BatchUpdateIntentsResponse actualResponse =
1004         client.batchUpdateIntentsAsync(parent, intentBatchUri).get();
1005     Assert.assertEquals(expectedResponse, actualResponse);
1006 
1007     List<AbstractMessage> actualRequests = mockIntents.getRequests();
1008     Assert.assertEquals(1, actualRequests.size());
1009     BatchUpdateIntentsRequest actualRequest = ((BatchUpdateIntentsRequest) actualRequests.get(0));
1010 
1011     Assert.assertEquals(parent.toString(), actualRequest.getParent());
1012     Assert.assertEquals(intentBatchUri, actualRequest.getIntentBatchUri());
1013     Assert.assertTrue(
1014         channelProvider.isHeaderSent(
1015             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1016             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1017   }
1018 
1019   @Test
batchUpdateIntentsExceptionTest2()1020   public void batchUpdateIntentsExceptionTest2() throws Exception {
1021     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1022     mockIntents.addException(exception);
1023 
1024     try {
1025       AgentName parent = AgentName.ofProjectName("[PROJECT]");
1026       String intentBatchUri = "intentBatchUri544125582";
1027       client.batchUpdateIntentsAsync(parent, intentBatchUri).get();
1028       Assert.fail("No exception raised");
1029     } catch (ExecutionException e) {
1030       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
1031       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
1032       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
1033     }
1034   }
1035 
1036   @Test
batchUpdateIntentsTest3()1037   public void batchUpdateIntentsTest3() throws Exception {
1038     BatchUpdateIntentsResponse expectedResponse =
1039         BatchUpdateIntentsResponse.newBuilder().addAllIntents(new ArrayList<Intent>()).build();
1040     Operation resultOperation =
1041         Operation.newBuilder()
1042             .setName("batchUpdateIntentsTest")
1043             .setDone(true)
1044             .setResponse(Any.pack(expectedResponse))
1045             .build();
1046     mockIntents.addResponse(resultOperation);
1047 
1048     String parent = "parent-995424086";
1049     IntentBatch intentBatchInline = IntentBatch.newBuilder().build();
1050 
1051     BatchUpdateIntentsResponse actualResponse =
1052         client.batchUpdateIntentsAsync(parent, intentBatchInline).get();
1053     Assert.assertEquals(expectedResponse, actualResponse);
1054 
1055     List<AbstractMessage> actualRequests = mockIntents.getRequests();
1056     Assert.assertEquals(1, actualRequests.size());
1057     BatchUpdateIntentsRequest actualRequest = ((BatchUpdateIntentsRequest) actualRequests.get(0));
1058 
1059     Assert.assertEquals(parent, actualRequest.getParent());
1060     Assert.assertEquals(intentBatchInline, actualRequest.getIntentBatchInline());
1061     Assert.assertTrue(
1062         channelProvider.isHeaderSent(
1063             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1064             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1065   }
1066 
1067   @Test
batchUpdateIntentsExceptionTest3()1068   public void batchUpdateIntentsExceptionTest3() throws Exception {
1069     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1070     mockIntents.addException(exception);
1071 
1072     try {
1073       String parent = "parent-995424086";
1074       IntentBatch intentBatchInline = IntentBatch.newBuilder().build();
1075       client.batchUpdateIntentsAsync(parent, intentBatchInline).get();
1076       Assert.fail("No exception raised");
1077     } catch (ExecutionException e) {
1078       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
1079       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
1080       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
1081     }
1082   }
1083 
1084   @Test
batchUpdateIntentsTest4()1085   public void batchUpdateIntentsTest4() throws Exception {
1086     BatchUpdateIntentsResponse expectedResponse =
1087         BatchUpdateIntentsResponse.newBuilder().addAllIntents(new ArrayList<Intent>()).build();
1088     Operation resultOperation =
1089         Operation.newBuilder()
1090             .setName("batchUpdateIntentsTest")
1091             .setDone(true)
1092             .setResponse(Any.pack(expectedResponse))
1093             .build();
1094     mockIntents.addResponse(resultOperation);
1095 
1096     String parent = "parent-995424086";
1097     String intentBatchUri = "intentBatchUri544125582";
1098 
1099     BatchUpdateIntentsResponse actualResponse =
1100         client.batchUpdateIntentsAsync(parent, intentBatchUri).get();
1101     Assert.assertEquals(expectedResponse, actualResponse);
1102 
1103     List<AbstractMessage> actualRequests = mockIntents.getRequests();
1104     Assert.assertEquals(1, actualRequests.size());
1105     BatchUpdateIntentsRequest actualRequest = ((BatchUpdateIntentsRequest) actualRequests.get(0));
1106 
1107     Assert.assertEquals(parent, actualRequest.getParent());
1108     Assert.assertEquals(intentBatchUri, actualRequest.getIntentBatchUri());
1109     Assert.assertTrue(
1110         channelProvider.isHeaderSent(
1111             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1112             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1113   }
1114 
1115   @Test
batchUpdateIntentsExceptionTest4()1116   public void batchUpdateIntentsExceptionTest4() throws Exception {
1117     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1118     mockIntents.addException(exception);
1119 
1120     try {
1121       String parent = "parent-995424086";
1122       String intentBatchUri = "intentBatchUri544125582";
1123       client.batchUpdateIntentsAsync(parent, intentBatchUri).get();
1124       Assert.fail("No exception raised");
1125     } catch (ExecutionException e) {
1126       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
1127       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
1128       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
1129     }
1130   }
1131 
1132   @Test
batchDeleteIntentsTest()1133   public void batchDeleteIntentsTest() throws Exception {
1134     Empty expectedResponse = Empty.newBuilder().build();
1135     Operation resultOperation =
1136         Operation.newBuilder()
1137             .setName("batchDeleteIntentsTest")
1138             .setDone(true)
1139             .setResponse(Any.pack(expectedResponse))
1140             .build();
1141     mockIntents.addResponse(resultOperation);
1142 
1143     AgentName parent = AgentName.ofProjectName("[PROJECT]");
1144     List<Intent> intents = new ArrayList<>();
1145 
1146     client.batchDeleteIntentsAsync(parent, intents).get();
1147 
1148     List<AbstractMessage> actualRequests = mockIntents.getRequests();
1149     Assert.assertEquals(1, actualRequests.size());
1150     BatchDeleteIntentsRequest actualRequest = ((BatchDeleteIntentsRequest) actualRequests.get(0));
1151 
1152     Assert.assertEquals(parent.toString(), actualRequest.getParent());
1153     Assert.assertEquals(intents, actualRequest.getIntentsList());
1154     Assert.assertTrue(
1155         channelProvider.isHeaderSent(
1156             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1157             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1158   }
1159 
1160   @Test
batchDeleteIntentsExceptionTest()1161   public void batchDeleteIntentsExceptionTest() throws Exception {
1162     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1163     mockIntents.addException(exception);
1164 
1165     try {
1166       AgentName parent = AgentName.ofProjectName("[PROJECT]");
1167       List<Intent> intents = new ArrayList<>();
1168       client.batchDeleteIntentsAsync(parent, intents).get();
1169       Assert.fail("No exception raised");
1170     } catch (ExecutionException e) {
1171       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
1172       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
1173       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
1174     }
1175   }
1176 
1177   @Test
batchDeleteIntentsTest2()1178   public void batchDeleteIntentsTest2() throws Exception {
1179     Empty expectedResponse = Empty.newBuilder().build();
1180     Operation resultOperation =
1181         Operation.newBuilder()
1182             .setName("batchDeleteIntentsTest")
1183             .setDone(true)
1184             .setResponse(Any.pack(expectedResponse))
1185             .build();
1186     mockIntents.addResponse(resultOperation);
1187 
1188     String parent = "parent-995424086";
1189     List<Intent> intents = new ArrayList<>();
1190 
1191     client.batchDeleteIntentsAsync(parent, intents).get();
1192 
1193     List<AbstractMessage> actualRequests = mockIntents.getRequests();
1194     Assert.assertEquals(1, actualRequests.size());
1195     BatchDeleteIntentsRequest actualRequest = ((BatchDeleteIntentsRequest) actualRequests.get(0));
1196 
1197     Assert.assertEquals(parent, actualRequest.getParent());
1198     Assert.assertEquals(intents, actualRequest.getIntentsList());
1199     Assert.assertTrue(
1200         channelProvider.isHeaderSent(
1201             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1202             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1203   }
1204 
1205   @Test
batchDeleteIntentsExceptionTest2()1206   public void batchDeleteIntentsExceptionTest2() throws Exception {
1207     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1208     mockIntents.addException(exception);
1209 
1210     try {
1211       String parent = "parent-995424086";
1212       List<Intent> intents = new ArrayList<>();
1213       client.batchDeleteIntentsAsync(parent, intents).get();
1214       Assert.fail("No exception raised");
1215     } catch (ExecutionException e) {
1216       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
1217       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
1218       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
1219     }
1220   }
1221 
1222   @Test
listLocationsTest()1223   public void listLocationsTest() throws Exception {
1224     Location responsesElement = Location.newBuilder().build();
1225     ListLocationsResponse expectedResponse =
1226         ListLocationsResponse.newBuilder()
1227             .setNextPageToken("")
1228             .addAllLocations(Arrays.asList(responsesElement))
1229             .build();
1230     mockLocations.addResponse(expectedResponse);
1231 
1232     ListLocationsRequest request =
1233         ListLocationsRequest.newBuilder()
1234             .setName("name3373707")
1235             .setFilter("filter-1274492040")
1236             .setPageSize(883849137)
1237             .setPageToken("pageToken873572522")
1238             .build();
1239 
1240     ListLocationsPagedResponse pagedListResponse = client.listLocations(request);
1241 
1242     List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1243 
1244     Assert.assertEquals(1, resources.size());
1245     Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0));
1246 
1247     List<AbstractMessage> actualRequests = mockLocations.getRequests();
1248     Assert.assertEquals(1, actualRequests.size());
1249     ListLocationsRequest actualRequest = ((ListLocationsRequest) actualRequests.get(0));
1250 
1251     Assert.assertEquals(request.getName(), actualRequest.getName());
1252     Assert.assertEquals(request.getFilter(), actualRequest.getFilter());
1253     Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
1254     Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
1255     Assert.assertTrue(
1256         channelProvider.isHeaderSent(
1257             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1258             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1259   }
1260 
1261   @Test
listLocationsExceptionTest()1262   public void listLocationsExceptionTest() throws Exception {
1263     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1264     mockLocations.addException(exception);
1265 
1266     try {
1267       ListLocationsRequest request =
1268           ListLocationsRequest.newBuilder()
1269               .setName("name3373707")
1270               .setFilter("filter-1274492040")
1271               .setPageSize(883849137)
1272               .setPageToken("pageToken873572522")
1273               .build();
1274       client.listLocations(request);
1275       Assert.fail("No exception raised");
1276     } catch (InvalidArgumentException e) {
1277       // Expected exception.
1278     }
1279   }
1280 
1281   @Test
getLocationTest()1282   public void getLocationTest() throws Exception {
1283     Location expectedResponse =
1284         Location.newBuilder()
1285             .setName("name3373707")
1286             .setLocationId("locationId1541836720")
1287             .setDisplayName("displayName1714148973")
1288             .putAllLabels(new HashMap<String, String>())
1289             .setMetadata(Any.newBuilder().build())
1290             .build();
1291     mockLocations.addResponse(expectedResponse);
1292 
1293     GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
1294 
1295     Location actualResponse = client.getLocation(request);
1296     Assert.assertEquals(expectedResponse, actualResponse);
1297 
1298     List<AbstractMessage> actualRequests = mockLocations.getRequests();
1299     Assert.assertEquals(1, actualRequests.size());
1300     GetLocationRequest actualRequest = ((GetLocationRequest) actualRequests.get(0));
1301 
1302     Assert.assertEquals(request.getName(), actualRequest.getName());
1303     Assert.assertTrue(
1304         channelProvider.isHeaderSent(
1305             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1306             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1307   }
1308 
1309   @Test
getLocationExceptionTest()1310   public void getLocationExceptionTest() throws Exception {
1311     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1312     mockLocations.addException(exception);
1313 
1314     try {
1315       GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
1316       client.getLocation(request);
1317       Assert.fail("No exception raised");
1318     } catch (InvalidArgumentException e) {
1319       // Expected exception.
1320     }
1321   }
1322 }
1323