• 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.EntityTypesClient.ListEntityTypesPagedResponse;
20 import static com.google.cloud.dialogflow.v2beta1.EntityTypesClient.ListLocationsPagedResponse;
21 
22 import com.google.api.gax.core.NoCredentialsProvider;
23 import com.google.api.gax.httpjson.GaxHttpJsonProperties;
24 import com.google.api.gax.httpjson.testing.MockHttpService;
25 import com.google.api.gax.rpc.ApiClientHeaderProvider;
26 import com.google.api.gax.rpc.ApiException;
27 import com.google.api.gax.rpc.ApiExceptionFactory;
28 import com.google.api.gax.rpc.InvalidArgumentException;
29 import com.google.api.gax.rpc.StatusCode;
30 import com.google.api.gax.rpc.testing.FakeStatusCode;
31 import com.google.cloud.dialogflow.v2beta1.stub.HttpJsonEntityTypesStub;
32 import com.google.cloud.location.GetLocationRequest;
33 import com.google.cloud.location.ListLocationsRequest;
34 import com.google.cloud.location.ListLocationsResponse;
35 import com.google.cloud.location.Location;
36 import com.google.common.collect.Lists;
37 import com.google.longrunning.Operation;
38 import com.google.protobuf.Any;
39 import com.google.protobuf.Empty;
40 import com.google.protobuf.FieldMask;
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.concurrent.ExecutionException;
47 import javax.annotation.Generated;
48 import org.junit.After;
49 import org.junit.AfterClass;
50 import org.junit.Assert;
51 import org.junit.Before;
52 import org.junit.BeforeClass;
53 import org.junit.Test;
54 
55 @Generated("by gapic-generator-java")
56 public class EntityTypesClientHttpJsonTest {
57   private static MockHttpService mockService;
58   private static EntityTypesClient client;
59 
60   @BeforeClass
startStaticServer()61   public static void startStaticServer() throws IOException {
62     mockService =
63         new MockHttpService(
64             HttpJsonEntityTypesStub.getMethodDescriptors(),
65             EntityTypesSettings.getDefaultEndpoint());
66     EntityTypesSettings settings =
67         EntityTypesSettings.newHttpJsonBuilder()
68             .setTransportChannelProvider(
69                 EntityTypesSettings.defaultHttpJsonTransportProviderBuilder()
70                     .setHttpTransport(mockService)
71                     .build())
72             .setCredentialsProvider(NoCredentialsProvider.create())
73             .build();
74     client = EntityTypesClient.create(settings);
75   }
76 
77   @AfterClass
stopServer()78   public static void stopServer() {
79     client.close();
80   }
81 
82   @Before
setUp()83   public void setUp() {}
84 
85   @After
tearDown()86   public void tearDown() throws Exception {
87     mockService.reset();
88   }
89 
90   @Test
listEntityTypesTest()91   public void listEntityTypesTest() throws Exception {
92     EntityType responsesElement = EntityType.newBuilder().build();
93     ListEntityTypesResponse expectedResponse =
94         ListEntityTypesResponse.newBuilder()
95             .setNextPageToken("")
96             .addAllEntityTypes(Arrays.asList(responsesElement))
97             .build();
98     mockService.addResponse(expectedResponse);
99 
100     AgentName parent = AgentName.ofProjectName("[PROJECT]");
101 
102     ListEntityTypesPagedResponse pagedListResponse = client.listEntityTypes(parent);
103 
104     List<EntityType> resources = Lists.newArrayList(pagedListResponse.iterateAll());
105 
106     Assert.assertEquals(1, resources.size());
107     Assert.assertEquals(expectedResponse.getEntityTypesList().get(0), resources.get(0));
108 
109     List<String> actualRequests = mockService.getRequestPaths();
110     Assert.assertEquals(1, actualRequests.size());
111 
112     String apiClientHeaderKey =
113         mockService
114             .getRequestHeaders()
115             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
116             .iterator()
117             .next();
118     Assert.assertTrue(
119         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
120             .matcher(apiClientHeaderKey)
121             .matches());
122   }
123 
124   @Test
listEntityTypesExceptionTest()125   public void listEntityTypesExceptionTest() throws Exception {
126     ApiException exception =
127         ApiExceptionFactory.createException(
128             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
129     mockService.addException(exception);
130 
131     try {
132       AgentName parent = AgentName.ofProjectName("[PROJECT]");
133       client.listEntityTypes(parent);
134       Assert.fail("No exception raised");
135     } catch (InvalidArgumentException e) {
136       // Expected exception.
137     }
138   }
139 
140   @Test
listEntityTypesTest2()141   public void listEntityTypesTest2() throws Exception {
142     EntityType responsesElement = EntityType.newBuilder().build();
143     ListEntityTypesResponse expectedResponse =
144         ListEntityTypesResponse.newBuilder()
145             .setNextPageToken("")
146             .addAllEntityTypes(Arrays.asList(responsesElement))
147             .build();
148     mockService.addResponse(expectedResponse);
149 
150     String parent = "projects/project-2469/agent";
151 
152     ListEntityTypesPagedResponse pagedListResponse = client.listEntityTypes(parent);
153 
154     List<EntityType> resources = Lists.newArrayList(pagedListResponse.iterateAll());
155 
156     Assert.assertEquals(1, resources.size());
157     Assert.assertEquals(expectedResponse.getEntityTypesList().get(0), resources.get(0));
158 
159     List<String> actualRequests = mockService.getRequestPaths();
160     Assert.assertEquals(1, actualRequests.size());
161 
162     String apiClientHeaderKey =
163         mockService
164             .getRequestHeaders()
165             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
166             .iterator()
167             .next();
168     Assert.assertTrue(
169         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
170             .matcher(apiClientHeaderKey)
171             .matches());
172   }
173 
174   @Test
listEntityTypesExceptionTest2()175   public void listEntityTypesExceptionTest2() throws Exception {
176     ApiException exception =
177         ApiExceptionFactory.createException(
178             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
179     mockService.addException(exception);
180 
181     try {
182       String parent = "projects/project-2469/agent";
183       client.listEntityTypes(parent);
184       Assert.fail("No exception raised");
185     } catch (InvalidArgumentException e) {
186       // Expected exception.
187     }
188   }
189 
190   @Test
listEntityTypesTest3()191   public void listEntityTypesTest3() throws Exception {
192     EntityType responsesElement = EntityType.newBuilder().build();
193     ListEntityTypesResponse expectedResponse =
194         ListEntityTypesResponse.newBuilder()
195             .setNextPageToken("")
196             .addAllEntityTypes(Arrays.asList(responsesElement))
197             .build();
198     mockService.addResponse(expectedResponse);
199 
200     AgentName parent = AgentName.ofProjectName("[PROJECT]");
201     String languageCode = "languageCode-2092349083";
202 
203     ListEntityTypesPagedResponse pagedListResponse = client.listEntityTypes(parent, languageCode);
204 
205     List<EntityType> resources = Lists.newArrayList(pagedListResponse.iterateAll());
206 
207     Assert.assertEquals(1, resources.size());
208     Assert.assertEquals(expectedResponse.getEntityTypesList().get(0), resources.get(0));
209 
210     List<String> actualRequests = mockService.getRequestPaths();
211     Assert.assertEquals(1, actualRequests.size());
212 
213     String apiClientHeaderKey =
214         mockService
215             .getRequestHeaders()
216             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
217             .iterator()
218             .next();
219     Assert.assertTrue(
220         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
221             .matcher(apiClientHeaderKey)
222             .matches());
223   }
224 
225   @Test
listEntityTypesExceptionTest3()226   public void listEntityTypesExceptionTest3() throws Exception {
227     ApiException exception =
228         ApiExceptionFactory.createException(
229             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
230     mockService.addException(exception);
231 
232     try {
233       AgentName parent = AgentName.ofProjectName("[PROJECT]");
234       String languageCode = "languageCode-2092349083";
235       client.listEntityTypes(parent, languageCode);
236       Assert.fail("No exception raised");
237     } catch (InvalidArgumentException e) {
238       // Expected exception.
239     }
240   }
241 
242   @Test
listEntityTypesTest4()243   public void listEntityTypesTest4() throws Exception {
244     EntityType responsesElement = EntityType.newBuilder().build();
245     ListEntityTypesResponse expectedResponse =
246         ListEntityTypesResponse.newBuilder()
247             .setNextPageToken("")
248             .addAllEntityTypes(Arrays.asList(responsesElement))
249             .build();
250     mockService.addResponse(expectedResponse);
251 
252     String parent = "projects/project-2469/agent";
253     String languageCode = "languageCode-2092349083";
254 
255     ListEntityTypesPagedResponse pagedListResponse = client.listEntityTypes(parent, languageCode);
256 
257     List<EntityType> resources = Lists.newArrayList(pagedListResponse.iterateAll());
258 
259     Assert.assertEquals(1, resources.size());
260     Assert.assertEquals(expectedResponse.getEntityTypesList().get(0), resources.get(0));
261 
262     List<String> actualRequests = mockService.getRequestPaths();
263     Assert.assertEquals(1, actualRequests.size());
264 
265     String apiClientHeaderKey =
266         mockService
267             .getRequestHeaders()
268             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
269             .iterator()
270             .next();
271     Assert.assertTrue(
272         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
273             .matcher(apiClientHeaderKey)
274             .matches());
275   }
276 
277   @Test
listEntityTypesExceptionTest4()278   public void listEntityTypesExceptionTest4() throws Exception {
279     ApiException exception =
280         ApiExceptionFactory.createException(
281             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
282     mockService.addException(exception);
283 
284     try {
285       String parent = "projects/project-2469/agent";
286       String languageCode = "languageCode-2092349083";
287       client.listEntityTypes(parent, languageCode);
288       Assert.fail("No exception raised");
289     } catch (InvalidArgumentException e) {
290       // Expected exception.
291     }
292   }
293 
294   @Test
getEntityTypeTest()295   public void getEntityTypeTest() throws Exception {
296     EntityType expectedResponse =
297         EntityType.newBuilder()
298             .setName(
299                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
300             .setDisplayName("displayName1714148973")
301             .addAllEntities(new ArrayList<EntityType.Entity>())
302             .setEnableFuzzyExtraction(true)
303             .build();
304     mockService.addResponse(expectedResponse);
305 
306     EntityTypeName name = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
307 
308     EntityType actualResponse = client.getEntityType(name);
309     Assert.assertEquals(expectedResponse, actualResponse);
310 
311     List<String> actualRequests = mockService.getRequestPaths();
312     Assert.assertEquals(1, actualRequests.size());
313 
314     String apiClientHeaderKey =
315         mockService
316             .getRequestHeaders()
317             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
318             .iterator()
319             .next();
320     Assert.assertTrue(
321         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
322             .matcher(apiClientHeaderKey)
323             .matches());
324   }
325 
326   @Test
getEntityTypeExceptionTest()327   public void getEntityTypeExceptionTest() throws Exception {
328     ApiException exception =
329         ApiExceptionFactory.createException(
330             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
331     mockService.addException(exception);
332 
333     try {
334       EntityTypeName name = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
335       client.getEntityType(name);
336       Assert.fail("No exception raised");
337     } catch (InvalidArgumentException e) {
338       // Expected exception.
339     }
340   }
341 
342   @Test
getEntityTypeTest2()343   public void getEntityTypeTest2() throws Exception {
344     EntityType expectedResponse =
345         EntityType.newBuilder()
346             .setName(
347                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
348             .setDisplayName("displayName1714148973")
349             .addAllEntities(new ArrayList<EntityType.Entity>())
350             .setEnableFuzzyExtraction(true)
351             .build();
352     mockService.addResponse(expectedResponse);
353 
354     String name = "projects/project-3464/agent/entityTypes/entityType-3464";
355 
356     EntityType actualResponse = client.getEntityType(name);
357     Assert.assertEquals(expectedResponse, actualResponse);
358 
359     List<String> actualRequests = mockService.getRequestPaths();
360     Assert.assertEquals(1, actualRequests.size());
361 
362     String apiClientHeaderKey =
363         mockService
364             .getRequestHeaders()
365             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
366             .iterator()
367             .next();
368     Assert.assertTrue(
369         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
370             .matcher(apiClientHeaderKey)
371             .matches());
372   }
373 
374   @Test
getEntityTypeExceptionTest2()375   public void getEntityTypeExceptionTest2() throws Exception {
376     ApiException exception =
377         ApiExceptionFactory.createException(
378             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
379     mockService.addException(exception);
380 
381     try {
382       String name = "projects/project-3464/agent/entityTypes/entityType-3464";
383       client.getEntityType(name);
384       Assert.fail("No exception raised");
385     } catch (InvalidArgumentException e) {
386       // Expected exception.
387     }
388   }
389 
390   @Test
getEntityTypeTest3()391   public void getEntityTypeTest3() throws Exception {
392     EntityType expectedResponse =
393         EntityType.newBuilder()
394             .setName(
395                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
396             .setDisplayName("displayName1714148973")
397             .addAllEntities(new ArrayList<EntityType.Entity>())
398             .setEnableFuzzyExtraction(true)
399             .build();
400     mockService.addResponse(expectedResponse);
401 
402     EntityTypeName name = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
403     String languageCode = "languageCode-2092349083";
404 
405     EntityType actualResponse = client.getEntityType(name, languageCode);
406     Assert.assertEquals(expectedResponse, actualResponse);
407 
408     List<String> actualRequests = mockService.getRequestPaths();
409     Assert.assertEquals(1, actualRequests.size());
410 
411     String apiClientHeaderKey =
412         mockService
413             .getRequestHeaders()
414             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
415             .iterator()
416             .next();
417     Assert.assertTrue(
418         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
419             .matcher(apiClientHeaderKey)
420             .matches());
421   }
422 
423   @Test
getEntityTypeExceptionTest3()424   public void getEntityTypeExceptionTest3() throws Exception {
425     ApiException exception =
426         ApiExceptionFactory.createException(
427             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
428     mockService.addException(exception);
429 
430     try {
431       EntityTypeName name = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
432       String languageCode = "languageCode-2092349083";
433       client.getEntityType(name, languageCode);
434       Assert.fail("No exception raised");
435     } catch (InvalidArgumentException e) {
436       // Expected exception.
437     }
438   }
439 
440   @Test
getEntityTypeTest4()441   public void getEntityTypeTest4() throws Exception {
442     EntityType expectedResponse =
443         EntityType.newBuilder()
444             .setName(
445                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
446             .setDisplayName("displayName1714148973")
447             .addAllEntities(new ArrayList<EntityType.Entity>())
448             .setEnableFuzzyExtraction(true)
449             .build();
450     mockService.addResponse(expectedResponse);
451 
452     String name = "projects/project-3464/agent/entityTypes/entityType-3464";
453     String languageCode = "languageCode-2092349083";
454 
455     EntityType actualResponse = client.getEntityType(name, languageCode);
456     Assert.assertEquals(expectedResponse, actualResponse);
457 
458     List<String> actualRequests = mockService.getRequestPaths();
459     Assert.assertEquals(1, actualRequests.size());
460 
461     String apiClientHeaderKey =
462         mockService
463             .getRequestHeaders()
464             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
465             .iterator()
466             .next();
467     Assert.assertTrue(
468         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
469             .matcher(apiClientHeaderKey)
470             .matches());
471   }
472 
473   @Test
getEntityTypeExceptionTest4()474   public void getEntityTypeExceptionTest4() throws Exception {
475     ApiException exception =
476         ApiExceptionFactory.createException(
477             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
478     mockService.addException(exception);
479 
480     try {
481       String name = "projects/project-3464/agent/entityTypes/entityType-3464";
482       String languageCode = "languageCode-2092349083";
483       client.getEntityType(name, languageCode);
484       Assert.fail("No exception raised");
485     } catch (InvalidArgumentException e) {
486       // Expected exception.
487     }
488   }
489 
490   @Test
createEntityTypeTest()491   public void createEntityTypeTest() throws Exception {
492     EntityType expectedResponse =
493         EntityType.newBuilder()
494             .setName(
495                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
496             .setDisplayName("displayName1714148973")
497             .addAllEntities(new ArrayList<EntityType.Entity>())
498             .setEnableFuzzyExtraction(true)
499             .build();
500     mockService.addResponse(expectedResponse);
501 
502     AgentName parent = AgentName.ofProjectName("[PROJECT]");
503     EntityType entityType = EntityType.newBuilder().build();
504 
505     EntityType actualResponse = client.createEntityType(parent, entityType);
506     Assert.assertEquals(expectedResponse, actualResponse);
507 
508     List<String> actualRequests = mockService.getRequestPaths();
509     Assert.assertEquals(1, actualRequests.size());
510 
511     String apiClientHeaderKey =
512         mockService
513             .getRequestHeaders()
514             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
515             .iterator()
516             .next();
517     Assert.assertTrue(
518         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
519             .matcher(apiClientHeaderKey)
520             .matches());
521   }
522 
523   @Test
createEntityTypeExceptionTest()524   public void createEntityTypeExceptionTest() throws Exception {
525     ApiException exception =
526         ApiExceptionFactory.createException(
527             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
528     mockService.addException(exception);
529 
530     try {
531       AgentName parent = AgentName.ofProjectName("[PROJECT]");
532       EntityType entityType = EntityType.newBuilder().build();
533       client.createEntityType(parent, entityType);
534       Assert.fail("No exception raised");
535     } catch (InvalidArgumentException e) {
536       // Expected exception.
537     }
538   }
539 
540   @Test
createEntityTypeTest2()541   public void createEntityTypeTest2() throws Exception {
542     EntityType expectedResponse =
543         EntityType.newBuilder()
544             .setName(
545                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
546             .setDisplayName("displayName1714148973")
547             .addAllEntities(new ArrayList<EntityType.Entity>())
548             .setEnableFuzzyExtraction(true)
549             .build();
550     mockService.addResponse(expectedResponse);
551 
552     String parent = "projects/project-2469/agent";
553     EntityType entityType = EntityType.newBuilder().build();
554 
555     EntityType actualResponse = client.createEntityType(parent, entityType);
556     Assert.assertEquals(expectedResponse, actualResponse);
557 
558     List<String> actualRequests = mockService.getRequestPaths();
559     Assert.assertEquals(1, actualRequests.size());
560 
561     String apiClientHeaderKey =
562         mockService
563             .getRequestHeaders()
564             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
565             .iterator()
566             .next();
567     Assert.assertTrue(
568         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
569             .matcher(apiClientHeaderKey)
570             .matches());
571   }
572 
573   @Test
createEntityTypeExceptionTest2()574   public void createEntityTypeExceptionTest2() throws Exception {
575     ApiException exception =
576         ApiExceptionFactory.createException(
577             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
578     mockService.addException(exception);
579 
580     try {
581       String parent = "projects/project-2469/agent";
582       EntityType entityType = EntityType.newBuilder().build();
583       client.createEntityType(parent, entityType);
584       Assert.fail("No exception raised");
585     } catch (InvalidArgumentException e) {
586       // Expected exception.
587     }
588   }
589 
590   @Test
createEntityTypeTest3()591   public void createEntityTypeTest3() throws Exception {
592     EntityType expectedResponse =
593         EntityType.newBuilder()
594             .setName(
595                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
596             .setDisplayName("displayName1714148973")
597             .addAllEntities(new ArrayList<EntityType.Entity>())
598             .setEnableFuzzyExtraction(true)
599             .build();
600     mockService.addResponse(expectedResponse);
601 
602     AgentName parent = AgentName.ofProjectName("[PROJECT]");
603     EntityType entityType = EntityType.newBuilder().build();
604     String languageCode = "languageCode-2092349083";
605 
606     EntityType actualResponse = client.createEntityType(parent, entityType, languageCode);
607     Assert.assertEquals(expectedResponse, actualResponse);
608 
609     List<String> actualRequests = mockService.getRequestPaths();
610     Assert.assertEquals(1, actualRequests.size());
611 
612     String apiClientHeaderKey =
613         mockService
614             .getRequestHeaders()
615             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
616             .iterator()
617             .next();
618     Assert.assertTrue(
619         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
620             .matcher(apiClientHeaderKey)
621             .matches());
622   }
623 
624   @Test
createEntityTypeExceptionTest3()625   public void createEntityTypeExceptionTest3() throws Exception {
626     ApiException exception =
627         ApiExceptionFactory.createException(
628             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
629     mockService.addException(exception);
630 
631     try {
632       AgentName parent = AgentName.ofProjectName("[PROJECT]");
633       EntityType entityType = EntityType.newBuilder().build();
634       String languageCode = "languageCode-2092349083";
635       client.createEntityType(parent, entityType, languageCode);
636       Assert.fail("No exception raised");
637     } catch (InvalidArgumentException e) {
638       // Expected exception.
639     }
640   }
641 
642   @Test
createEntityTypeTest4()643   public void createEntityTypeTest4() throws Exception {
644     EntityType expectedResponse =
645         EntityType.newBuilder()
646             .setName(
647                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
648             .setDisplayName("displayName1714148973")
649             .addAllEntities(new ArrayList<EntityType.Entity>())
650             .setEnableFuzzyExtraction(true)
651             .build();
652     mockService.addResponse(expectedResponse);
653 
654     String parent = "projects/project-2469/agent";
655     EntityType entityType = EntityType.newBuilder().build();
656     String languageCode = "languageCode-2092349083";
657 
658     EntityType actualResponse = client.createEntityType(parent, entityType, languageCode);
659     Assert.assertEquals(expectedResponse, actualResponse);
660 
661     List<String> actualRequests = mockService.getRequestPaths();
662     Assert.assertEquals(1, actualRequests.size());
663 
664     String apiClientHeaderKey =
665         mockService
666             .getRequestHeaders()
667             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
668             .iterator()
669             .next();
670     Assert.assertTrue(
671         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
672             .matcher(apiClientHeaderKey)
673             .matches());
674   }
675 
676   @Test
createEntityTypeExceptionTest4()677   public void createEntityTypeExceptionTest4() throws Exception {
678     ApiException exception =
679         ApiExceptionFactory.createException(
680             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
681     mockService.addException(exception);
682 
683     try {
684       String parent = "projects/project-2469/agent";
685       EntityType entityType = EntityType.newBuilder().build();
686       String languageCode = "languageCode-2092349083";
687       client.createEntityType(parent, entityType, languageCode);
688       Assert.fail("No exception raised");
689     } catch (InvalidArgumentException e) {
690       // Expected exception.
691     }
692   }
693 
694   @Test
updateEntityTypeTest()695   public void updateEntityTypeTest() throws Exception {
696     EntityType expectedResponse =
697         EntityType.newBuilder()
698             .setName(
699                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
700             .setDisplayName("displayName1714148973")
701             .addAllEntities(new ArrayList<EntityType.Entity>())
702             .setEnableFuzzyExtraction(true)
703             .build();
704     mockService.addResponse(expectedResponse);
705 
706     EntityType entityType =
707         EntityType.newBuilder()
708             .setName(
709                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
710             .setDisplayName("displayName1714148973")
711             .addAllEntities(new ArrayList<EntityType.Entity>())
712             .setEnableFuzzyExtraction(true)
713             .build();
714 
715     EntityType actualResponse = client.updateEntityType(entityType);
716     Assert.assertEquals(expectedResponse, actualResponse);
717 
718     List<String> actualRequests = mockService.getRequestPaths();
719     Assert.assertEquals(1, actualRequests.size());
720 
721     String apiClientHeaderKey =
722         mockService
723             .getRequestHeaders()
724             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
725             .iterator()
726             .next();
727     Assert.assertTrue(
728         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
729             .matcher(apiClientHeaderKey)
730             .matches());
731   }
732 
733   @Test
updateEntityTypeExceptionTest()734   public void updateEntityTypeExceptionTest() throws Exception {
735     ApiException exception =
736         ApiExceptionFactory.createException(
737             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
738     mockService.addException(exception);
739 
740     try {
741       EntityType entityType =
742           EntityType.newBuilder()
743               .setName(
744                   EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
745               .setDisplayName("displayName1714148973")
746               .addAllEntities(new ArrayList<EntityType.Entity>())
747               .setEnableFuzzyExtraction(true)
748               .build();
749       client.updateEntityType(entityType);
750       Assert.fail("No exception raised");
751     } catch (InvalidArgumentException e) {
752       // Expected exception.
753     }
754   }
755 
756   @Test
updateEntityTypeTest2()757   public void updateEntityTypeTest2() throws Exception {
758     EntityType expectedResponse =
759         EntityType.newBuilder()
760             .setName(
761                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
762             .setDisplayName("displayName1714148973")
763             .addAllEntities(new ArrayList<EntityType.Entity>())
764             .setEnableFuzzyExtraction(true)
765             .build();
766     mockService.addResponse(expectedResponse);
767 
768     EntityType entityType =
769         EntityType.newBuilder()
770             .setName(
771                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
772             .setDisplayName("displayName1714148973")
773             .addAllEntities(new ArrayList<EntityType.Entity>())
774             .setEnableFuzzyExtraction(true)
775             .build();
776     String languageCode = "languageCode-2092349083";
777 
778     EntityType actualResponse = client.updateEntityType(entityType, languageCode);
779     Assert.assertEquals(expectedResponse, actualResponse);
780 
781     List<String> actualRequests = mockService.getRequestPaths();
782     Assert.assertEquals(1, actualRequests.size());
783 
784     String apiClientHeaderKey =
785         mockService
786             .getRequestHeaders()
787             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
788             .iterator()
789             .next();
790     Assert.assertTrue(
791         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
792             .matcher(apiClientHeaderKey)
793             .matches());
794   }
795 
796   @Test
updateEntityTypeExceptionTest2()797   public void updateEntityTypeExceptionTest2() throws Exception {
798     ApiException exception =
799         ApiExceptionFactory.createException(
800             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
801     mockService.addException(exception);
802 
803     try {
804       EntityType entityType =
805           EntityType.newBuilder()
806               .setName(
807                   EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
808               .setDisplayName("displayName1714148973")
809               .addAllEntities(new ArrayList<EntityType.Entity>())
810               .setEnableFuzzyExtraction(true)
811               .build();
812       String languageCode = "languageCode-2092349083";
813       client.updateEntityType(entityType, languageCode);
814       Assert.fail("No exception raised");
815     } catch (InvalidArgumentException e) {
816       // Expected exception.
817     }
818   }
819 
820   @Test
updateEntityTypeTest3()821   public void updateEntityTypeTest3() throws Exception {
822     EntityType expectedResponse =
823         EntityType.newBuilder()
824             .setName(
825                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
826             .setDisplayName("displayName1714148973")
827             .addAllEntities(new ArrayList<EntityType.Entity>())
828             .setEnableFuzzyExtraction(true)
829             .build();
830     mockService.addResponse(expectedResponse);
831 
832     EntityType entityType =
833         EntityType.newBuilder()
834             .setName(
835                 EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
836             .setDisplayName("displayName1714148973")
837             .addAllEntities(new ArrayList<EntityType.Entity>())
838             .setEnableFuzzyExtraction(true)
839             .build();
840     String languageCode = "languageCode-2092349083";
841     FieldMask updateMask = FieldMask.newBuilder().build();
842 
843     EntityType actualResponse = client.updateEntityType(entityType, languageCode, updateMask);
844     Assert.assertEquals(expectedResponse, actualResponse);
845 
846     List<String> actualRequests = mockService.getRequestPaths();
847     Assert.assertEquals(1, actualRequests.size());
848 
849     String apiClientHeaderKey =
850         mockService
851             .getRequestHeaders()
852             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
853             .iterator()
854             .next();
855     Assert.assertTrue(
856         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
857             .matcher(apiClientHeaderKey)
858             .matches());
859   }
860 
861   @Test
updateEntityTypeExceptionTest3()862   public void updateEntityTypeExceptionTest3() throws Exception {
863     ApiException exception =
864         ApiExceptionFactory.createException(
865             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
866     mockService.addException(exception);
867 
868     try {
869       EntityType entityType =
870           EntityType.newBuilder()
871               .setName(
872                   EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]").toString())
873               .setDisplayName("displayName1714148973")
874               .addAllEntities(new ArrayList<EntityType.Entity>())
875               .setEnableFuzzyExtraction(true)
876               .build();
877       String languageCode = "languageCode-2092349083";
878       FieldMask updateMask = FieldMask.newBuilder().build();
879       client.updateEntityType(entityType, languageCode, updateMask);
880       Assert.fail("No exception raised");
881     } catch (InvalidArgumentException e) {
882       // Expected exception.
883     }
884   }
885 
886   @Test
deleteEntityTypeTest()887   public void deleteEntityTypeTest() throws Exception {
888     Empty expectedResponse = Empty.newBuilder().build();
889     mockService.addResponse(expectedResponse);
890 
891     EntityTypeName name = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
892 
893     client.deleteEntityType(name);
894 
895     List<String> actualRequests = mockService.getRequestPaths();
896     Assert.assertEquals(1, actualRequests.size());
897 
898     String apiClientHeaderKey =
899         mockService
900             .getRequestHeaders()
901             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
902             .iterator()
903             .next();
904     Assert.assertTrue(
905         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
906             .matcher(apiClientHeaderKey)
907             .matches());
908   }
909 
910   @Test
deleteEntityTypeExceptionTest()911   public void deleteEntityTypeExceptionTest() throws Exception {
912     ApiException exception =
913         ApiExceptionFactory.createException(
914             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
915     mockService.addException(exception);
916 
917     try {
918       EntityTypeName name = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
919       client.deleteEntityType(name);
920       Assert.fail("No exception raised");
921     } catch (InvalidArgumentException e) {
922       // Expected exception.
923     }
924   }
925 
926   @Test
deleteEntityTypeTest2()927   public void deleteEntityTypeTest2() throws Exception {
928     Empty expectedResponse = Empty.newBuilder().build();
929     mockService.addResponse(expectedResponse);
930 
931     String name = "projects/project-3464/agent/entityTypes/entityType-3464";
932 
933     client.deleteEntityType(name);
934 
935     List<String> actualRequests = mockService.getRequestPaths();
936     Assert.assertEquals(1, actualRequests.size());
937 
938     String apiClientHeaderKey =
939         mockService
940             .getRequestHeaders()
941             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
942             .iterator()
943             .next();
944     Assert.assertTrue(
945         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
946             .matcher(apiClientHeaderKey)
947             .matches());
948   }
949 
950   @Test
deleteEntityTypeExceptionTest2()951   public void deleteEntityTypeExceptionTest2() throws Exception {
952     ApiException exception =
953         ApiExceptionFactory.createException(
954             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
955     mockService.addException(exception);
956 
957     try {
958       String name = "projects/project-3464/agent/entityTypes/entityType-3464";
959       client.deleteEntityType(name);
960       Assert.fail("No exception raised");
961     } catch (InvalidArgumentException e) {
962       // Expected exception.
963     }
964   }
965 
966   @Test
batchUpdateEntityTypesTest()967   public void batchUpdateEntityTypesTest() throws Exception {
968     BatchUpdateEntityTypesResponse expectedResponse =
969         BatchUpdateEntityTypesResponse.newBuilder()
970             .addAllEntityTypes(new ArrayList<EntityType>())
971             .build();
972     Operation resultOperation =
973         Operation.newBuilder()
974             .setName("batchUpdateEntityTypesTest")
975             .setDone(true)
976             .setResponse(Any.pack(expectedResponse))
977             .build();
978     mockService.addResponse(resultOperation);
979 
980     BatchUpdateEntityTypesRequest request =
981         BatchUpdateEntityTypesRequest.newBuilder()
982             .setParent(AgentName.ofProjectName("[PROJECT]").toString())
983             .setLanguageCode("languageCode-2092349083")
984             .setUpdateMask(FieldMask.newBuilder().build())
985             .build();
986 
987     BatchUpdateEntityTypesResponse actualResponse =
988         client.batchUpdateEntityTypesAsync(request).get();
989     Assert.assertEquals(expectedResponse, actualResponse);
990 
991     List<String> actualRequests = mockService.getRequestPaths();
992     Assert.assertEquals(1, actualRequests.size());
993 
994     String apiClientHeaderKey =
995         mockService
996             .getRequestHeaders()
997             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
998             .iterator()
999             .next();
1000     Assert.assertTrue(
1001         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1002             .matcher(apiClientHeaderKey)
1003             .matches());
1004   }
1005 
1006   @Test
batchUpdateEntityTypesExceptionTest()1007   public void batchUpdateEntityTypesExceptionTest() throws Exception {
1008     ApiException exception =
1009         ApiExceptionFactory.createException(
1010             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1011     mockService.addException(exception);
1012 
1013     try {
1014       BatchUpdateEntityTypesRequest request =
1015           BatchUpdateEntityTypesRequest.newBuilder()
1016               .setParent(AgentName.ofProjectName("[PROJECT]").toString())
1017               .setLanguageCode("languageCode-2092349083")
1018               .setUpdateMask(FieldMask.newBuilder().build())
1019               .build();
1020       client.batchUpdateEntityTypesAsync(request).get();
1021       Assert.fail("No exception raised");
1022     } catch (ExecutionException e) {
1023     }
1024   }
1025 
1026   @Test
batchDeleteEntityTypesTest()1027   public void batchDeleteEntityTypesTest() throws Exception {
1028     Empty expectedResponse = Empty.newBuilder().build();
1029     Operation resultOperation =
1030         Operation.newBuilder()
1031             .setName("batchDeleteEntityTypesTest")
1032             .setDone(true)
1033             .setResponse(Any.pack(expectedResponse))
1034             .build();
1035     mockService.addResponse(resultOperation);
1036 
1037     AgentName parent = AgentName.ofProjectName("[PROJECT]");
1038     List<String> entityTypeNames = new ArrayList<>();
1039 
1040     client.batchDeleteEntityTypesAsync(parent, entityTypeNames).get();
1041 
1042     List<String> actualRequests = mockService.getRequestPaths();
1043     Assert.assertEquals(1, actualRequests.size());
1044 
1045     String apiClientHeaderKey =
1046         mockService
1047             .getRequestHeaders()
1048             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1049             .iterator()
1050             .next();
1051     Assert.assertTrue(
1052         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1053             .matcher(apiClientHeaderKey)
1054             .matches());
1055   }
1056 
1057   @Test
batchDeleteEntityTypesExceptionTest()1058   public void batchDeleteEntityTypesExceptionTest() throws Exception {
1059     ApiException exception =
1060         ApiExceptionFactory.createException(
1061             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1062     mockService.addException(exception);
1063 
1064     try {
1065       AgentName parent = AgentName.ofProjectName("[PROJECT]");
1066       List<String> entityTypeNames = new ArrayList<>();
1067       client.batchDeleteEntityTypesAsync(parent, entityTypeNames).get();
1068       Assert.fail("No exception raised");
1069     } catch (ExecutionException e) {
1070     }
1071   }
1072 
1073   @Test
batchDeleteEntityTypesTest2()1074   public void batchDeleteEntityTypesTest2() throws Exception {
1075     Empty expectedResponse = Empty.newBuilder().build();
1076     Operation resultOperation =
1077         Operation.newBuilder()
1078             .setName("batchDeleteEntityTypesTest")
1079             .setDone(true)
1080             .setResponse(Any.pack(expectedResponse))
1081             .build();
1082     mockService.addResponse(resultOperation);
1083 
1084     String parent = "projects/project-2469/agent";
1085     List<String> entityTypeNames = new ArrayList<>();
1086 
1087     client.batchDeleteEntityTypesAsync(parent, entityTypeNames).get();
1088 
1089     List<String> actualRequests = mockService.getRequestPaths();
1090     Assert.assertEquals(1, actualRequests.size());
1091 
1092     String apiClientHeaderKey =
1093         mockService
1094             .getRequestHeaders()
1095             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1096             .iterator()
1097             .next();
1098     Assert.assertTrue(
1099         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1100             .matcher(apiClientHeaderKey)
1101             .matches());
1102   }
1103 
1104   @Test
batchDeleteEntityTypesExceptionTest2()1105   public void batchDeleteEntityTypesExceptionTest2() throws Exception {
1106     ApiException exception =
1107         ApiExceptionFactory.createException(
1108             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1109     mockService.addException(exception);
1110 
1111     try {
1112       String parent = "projects/project-2469/agent";
1113       List<String> entityTypeNames = new ArrayList<>();
1114       client.batchDeleteEntityTypesAsync(parent, entityTypeNames).get();
1115       Assert.fail("No exception raised");
1116     } catch (ExecutionException e) {
1117     }
1118   }
1119 
1120   @Test
batchCreateEntitiesTest()1121   public void batchCreateEntitiesTest() throws Exception {
1122     Empty expectedResponse = Empty.newBuilder().build();
1123     Operation resultOperation =
1124         Operation.newBuilder()
1125             .setName("batchCreateEntitiesTest")
1126             .setDone(true)
1127             .setResponse(Any.pack(expectedResponse))
1128             .build();
1129     mockService.addResponse(resultOperation);
1130 
1131     EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
1132     List<EntityType.Entity> entities = new ArrayList<>();
1133 
1134     client.batchCreateEntitiesAsync(parent, entities).get();
1135 
1136     List<String> actualRequests = mockService.getRequestPaths();
1137     Assert.assertEquals(1, actualRequests.size());
1138 
1139     String apiClientHeaderKey =
1140         mockService
1141             .getRequestHeaders()
1142             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1143             .iterator()
1144             .next();
1145     Assert.assertTrue(
1146         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1147             .matcher(apiClientHeaderKey)
1148             .matches());
1149   }
1150 
1151   @Test
batchCreateEntitiesExceptionTest()1152   public void batchCreateEntitiesExceptionTest() throws Exception {
1153     ApiException exception =
1154         ApiExceptionFactory.createException(
1155             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1156     mockService.addException(exception);
1157 
1158     try {
1159       EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
1160       List<EntityType.Entity> entities = new ArrayList<>();
1161       client.batchCreateEntitiesAsync(parent, entities).get();
1162       Assert.fail("No exception raised");
1163     } catch (ExecutionException e) {
1164     }
1165   }
1166 
1167   @Test
batchCreateEntitiesTest2()1168   public void batchCreateEntitiesTest2() throws Exception {
1169     Empty expectedResponse = Empty.newBuilder().build();
1170     Operation resultOperation =
1171         Operation.newBuilder()
1172             .setName("batchCreateEntitiesTest")
1173             .setDone(true)
1174             .setResponse(Any.pack(expectedResponse))
1175             .build();
1176     mockService.addResponse(resultOperation);
1177 
1178     String parent = "projects/project-2105/agent/entityTypes/entityType-2105";
1179     List<EntityType.Entity> entities = new ArrayList<>();
1180 
1181     client.batchCreateEntitiesAsync(parent, entities).get();
1182 
1183     List<String> actualRequests = mockService.getRequestPaths();
1184     Assert.assertEquals(1, actualRequests.size());
1185 
1186     String apiClientHeaderKey =
1187         mockService
1188             .getRequestHeaders()
1189             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1190             .iterator()
1191             .next();
1192     Assert.assertTrue(
1193         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1194             .matcher(apiClientHeaderKey)
1195             .matches());
1196   }
1197 
1198   @Test
batchCreateEntitiesExceptionTest2()1199   public void batchCreateEntitiesExceptionTest2() throws Exception {
1200     ApiException exception =
1201         ApiExceptionFactory.createException(
1202             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1203     mockService.addException(exception);
1204 
1205     try {
1206       String parent = "projects/project-2105/agent/entityTypes/entityType-2105";
1207       List<EntityType.Entity> entities = new ArrayList<>();
1208       client.batchCreateEntitiesAsync(parent, entities).get();
1209       Assert.fail("No exception raised");
1210     } catch (ExecutionException e) {
1211     }
1212   }
1213 
1214   @Test
batchCreateEntitiesTest3()1215   public void batchCreateEntitiesTest3() throws Exception {
1216     Empty expectedResponse = Empty.newBuilder().build();
1217     Operation resultOperation =
1218         Operation.newBuilder()
1219             .setName("batchCreateEntitiesTest")
1220             .setDone(true)
1221             .setResponse(Any.pack(expectedResponse))
1222             .build();
1223     mockService.addResponse(resultOperation);
1224 
1225     EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
1226     List<EntityType.Entity> entities = new ArrayList<>();
1227     String languageCode = "languageCode-2092349083";
1228 
1229     client.batchCreateEntitiesAsync(parent, entities, languageCode).get();
1230 
1231     List<String> actualRequests = mockService.getRequestPaths();
1232     Assert.assertEquals(1, actualRequests.size());
1233 
1234     String apiClientHeaderKey =
1235         mockService
1236             .getRequestHeaders()
1237             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1238             .iterator()
1239             .next();
1240     Assert.assertTrue(
1241         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1242             .matcher(apiClientHeaderKey)
1243             .matches());
1244   }
1245 
1246   @Test
batchCreateEntitiesExceptionTest3()1247   public void batchCreateEntitiesExceptionTest3() throws Exception {
1248     ApiException exception =
1249         ApiExceptionFactory.createException(
1250             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1251     mockService.addException(exception);
1252 
1253     try {
1254       EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
1255       List<EntityType.Entity> entities = new ArrayList<>();
1256       String languageCode = "languageCode-2092349083";
1257       client.batchCreateEntitiesAsync(parent, entities, languageCode).get();
1258       Assert.fail("No exception raised");
1259     } catch (ExecutionException e) {
1260     }
1261   }
1262 
1263   @Test
batchCreateEntitiesTest4()1264   public void batchCreateEntitiesTest4() throws Exception {
1265     Empty expectedResponse = Empty.newBuilder().build();
1266     Operation resultOperation =
1267         Operation.newBuilder()
1268             .setName("batchCreateEntitiesTest")
1269             .setDone(true)
1270             .setResponse(Any.pack(expectedResponse))
1271             .build();
1272     mockService.addResponse(resultOperation);
1273 
1274     String parent = "projects/project-2105/agent/entityTypes/entityType-2105";
1275     List<EntityType.Entity> entities = new ArrayList<>();
1276     String languageCode = "languageCode-2092349083";
1277 
1278     client.batchCreateEntitiesAsync(parent, entities, languageCode).get();
1279 
1280     List<String> actualRequests = mockService.getRequestPaths();
1281     Assert.assertEquals(1, actualRequests.size());
1282 
1283     String apiClientHeaderKey =
1284         mockService
1285             .getRequestHeaders()
1286             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1287             .iterator()
1288             .next();
1289     Assert.assertTrue(
1290         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1291             .matcher(apiClientHeaderKey)
1292             .matches());
1293   }
1294 
1295   @Test
batchCreateEntitiesExceptionTest4()1296   public void batchCreateEntitiesExceptionTest4() throws Exception {
1297     ApiException exception =
1298         ApiExceptionFactory.createException(
1299             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1300     mockService.addException(exception);
1301 
1302     try {
1303       String parent = "projects/project-2105/agent/entityTypes/entityType-2105";
1304       List<EntityType.Entity> entities = new ArrayList<>();
1305       String languageCode = "languageCode-2092349083";
1306       client.batchCreateEntitiesAsync(parent, entities, languageCode).get();
1307       Assert.fail("No exception raised");
1308     } catch (ExecutionException e) {
1309     }
1310   }
1311 
1312   @Test
batchUpdateEntitiesTest()1313   public void batchUpdateEntitiesTest() throws Exception {
1314     Empty expectedResponse = Empty.newBuilder().build();
1315     Operation resultOperation =
1316         Operation.newBuilder()
1317             .setName("batchUpdateEntitiesTest")
1318             .setDone(true)
1319             .setResponse(Any.pack(expectedResponse))
1320             .build();
1321     mockService.addResponse(resultOperation);
1322 
1323     EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
1324     List<EntityType.Entity> entities = new ArrayList<>();
1325 
1326     client.batchUpdateEntitiesAsync(parent, entities).get();
1327 
1328     List<String> actualRequests = mockService.getRequestPaths();
1329     Assert.assertEquals(1, actualRequests.size());
1330 
1331     String apiClientHeaderKey =
1332         mockService
1333             .getRequestHeaders()
1334             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1335             .iterator()
1336             .next();
1337     Assert.assertTrue(
1338         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1339             .matcher(apiClientHeaderKey)
1340             .matches());
1341   }
1342 
1343   @Test
batchUpdateEntitiesExceptionTest()1344   public void batchUpdateEntitiesExceptionTest() throws Exception {
1345     ApiException exception =
1346         ApiExceptionFactory.createException(
1347             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1348     mockService.addException(exception);
1349 
1350     try {
1351       EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
1352       List<EntityType.Entity> entities = new ArrayList<>();
1353       client.batchUpdateEntitiesAsync(parent, entities).get();
1354       Assert.fail("No exception raised");
1355     } catch (ExecutionException e) {
1356     }
1357   }
1358 
1359   @Test
batchUpdateEntitiesTest2()1360   public void batchUpdateEntitiesTest2() throws Exception {
1361     Empty expectedResponse = Empty.newBuilder().build();
1362     Operation resultOperation =
1363         Operation.newBuilder()
1364             .setName("batchUpdateEntitiesTest")
1365             .setDone(true)
1366             .setResponse(Any.pack(expectedResponse))
1367             .build();
1368     mockService.addResponse(resultOperation);
1369 
1370     String parent = "projects/project-2105/agent/entityTypes/entityType-2105";
1371     List<EntityType.Entity> entities = new ArrayList<>();
1372 
1373     client.batchUpdateEntitiesAsync(parent, entities).get();
1374 
1375     List<String> actualRequests = mockService.getRequestPaths();
1376     Assert.assertEquals(1, actualRequests.size());
1377 
1378     String apiClientHeaderKey =
1379         mockService
1380             .getRequestHeaders()
1381             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1382             .iterator()
1383             .next();
1384     Assert.assertTrue(
1385         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1386             .matcher(apiClientHeaderKey)
1387             .matches());
1388   }
1389 
1390   @Test
batchUpdateEntitiesExceptionTest2()1391   public void batchUpdateEntitiesExceptionTest2() throws Exception {
1392     ApiException exception =
1393         ApiExceptionFactory.createException(
1394             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1395     mockService.addException(exception);
1396 
1397     try {
1398       String parent = "projects/project-2105/agent/entityTypes/entityType-2105";
1399       List<EntityType.Entity> entities = new ArrayList<>();
1400       client.batchUpdateEntitiesAsync(parent, entities).get();
1401       Assert.fail("No exception raised");
1402     } catch (ExecutionException e) {
1403     }
1404   }
1405 
1406   @Test
batchUpdateEntitiesTest3()1407   public void batchUpdateEntitiesTest3() throws Exception {
1408     Empty expectedResponse = Empty.newBuilder().build();
1409     Operation resultOperation =
1410         Operation.newBuilder()
1411             .setName("batchUpdateEntitiesTest")
1412             .setDone(true)
1413             .setResponse(Any.pack(expectedResponse))
1414             .build();
1415     mockService.addResponse(resultOperation);
1416 
1417     EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
1418     List<EntityType.Entity> entities = new ArrayList<>();
1419     String languageCode = "languageCode-2092349083";
1420 
1421     client.batchUpdateEntitiesAsync(parent, entities, languageCode).get();
1422 
1423     List<String> actualRequests = mockService.getRequestPaths();
1424     Assert.assertEquals(1, actualRequests.size());
1425 
1426     String apiClientHeaderKey =
1427         mockService
1428             .getRequestHeaders()
1429             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1430             .iterator()
1431             .next();
1432     Assert.assertTrue(
1433         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1434             .matcher(apiClientHeaderKey)
1435             .matches());
1436   }
1437 
1438   @Test
batchUpdateEntitiesExceptionTest3()1439   public void batchUpdateEntitiesExceptionTest3() throws Exception {
1440     ApiException exception =
1441         ApiExceptionFactory.createException(
1442             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1443     mockService.addException(exception);
1444 
1445     try {
1446       EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
1447       List<EntityType.Entity> entities = new ArrayList<>();
1448       String languageCode = "languageCode-2092349083";
1449       client.batchUpdateEntitiesAsync(parent, entities, languageCode).get();
1450       Assert.fail("No exception raised");
1451     } catch (ExecutionException e) {
1452     }
1453   }
1454 
1455   @Test
batchUpdateEntitiesTest4()1456   public void batchUpdateEntitiesTest4() throws Exception {
1457     Empty expectedResponse = Empty.newBuilder().build();
1458     Operation resultOperation =
1459         Operation.newBuilder()
1460             .setName("batchUpdateEntitiesTest")
1461             .setDone(true)
1462             .setResponse(Any.pack(expectedResponse))
1463             .build();
1464     mockService.addResponse(resultOperation);
1465 
1466     String parent = "projects/project-2105/agent/entityTypes/entityType-2105";
1467     List<EntityType.Entity> entities = new ArrayList<>();
1468     String languageCode = "languageCode-2092349083";
1469 
1470     client.batchUpdateEntitiesAsync(parent, entities, languageCode).get();
1471 
1472     List<String> actualRequests = mockService.getRequestPaths();
1473     Assert.assertEquals(1, actualRequests.size());
1474 
1475     String apiClientHeaderKey =
1476         mockService
1477             .getRequestHeaders()
1478             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1479             .iterator()
1480             .next();
1481     Assert.assertTrue(
1482         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1483             .matcher(apiClientHeaderKey)
1484             .matches());
1485   }
1486 
1487   @Test
batchUpdateEntitiesExceptionTest4()1488   public void batchUpdateEntitiesExceptionTest4() throws Exception {
1489     ApiException exception =
1490         ApiExceptionFactory.createException(
1491             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1492     mockService.addException(exception);
1493 
1494     try {
1495       String parent = "projects/project-2105/agent/entityTypes/entityType-2105";
1496       List<EntityType.Entity> entities = new ArrayList<>();
1497       String languageCode = "languageCode-2092349083";
1498       client.batchUpdateEntitiesAsync(parent, entities, languageCode).get();
1499       Assert.fail("No exception raised");
1500     } catch (ExecutionException e) {
1501     }
1502   }
1503 
1504   @Test
batchDeleteEntitiesTest()1505   public void batchDeleteEntitiesTest() throws Exception {
1506     Empty expectedResponse = Empty.newBuilder().build();
1507     Operation resultOperation =
1508         Operation.newBuilder()
1509             .setName("batchDeleteEntitiesTest")
1510             .setDone(true)
1511             .setResponse(Any.pack(expectedResponse))
1512             .build();
1513     mockService.addResponse(resultOperation);
1514 
1515     EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
1516     List<String> entityValues = new ArrayList<>();
1517 
1518     client.batchDeleteEntitiesAsync(parent, entityValues).get();
1519 
1520     List<String> actualRequests = mockService.getRequestPaths();
1521     Assert.assertEquals(1, actualRequests.size());
1522 
1523     String apiClientHeaderKey =
1524         mockService
1525             .getRequestHeaders()
1526             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1527             .iterator()
1528             .next();
1529     Assert.assertTrue(
1530         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1531             .matcher(apiClientHeaderKey)
1532             .matches());
1533   }
1534 
1535   @Test
batchDeleteEntitiesExceptionTest()1536   public void batchDeleteEntitiesExceptionTest() throws Exception {
1537     ApiException exception =
1538         ApiExceptionFactory.createException(
1539             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1540     mockService.addException(exception);
1541 
1542     try {
1543       EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
1544       List<String> entityValues = new ArrayList<>();
1545       client.batchDeleteEntitiesAsync(parent, entityValues).get();
1546       Assert.fail("No exception raised");
1547     } catch (ExecutionException e) {
1548     }
1549   }
1550 
1551   @Test
batchDeleteEntitiesTest2()1552   public void batchDeleteEntitiesTest2() throws Exception {
1553     Empty expectedResponse = Empty.newBuilder().build();
1554     Operation resultOperation =
1555         Operation.newBuilder()
1556             .setName("batchDeleteEntitiesTest")
1557             .setDone(true)
1558             .setResponse(Any.pack(expectedResponse))
1559             .build();
1560     mockService.addResponse(resultOperation);
1561 
1562     String parent = "projects/project-2105/agent/entityTypes/entityType-2105";
1563     List<String> entityValues = new ArrayList<>();
1564 
1565     client.batchDeleteEntitiesAsync(parent, entityValues).get();
1566 
1567     List<String> actualRequests = mockService.getRequestPaths();
1568     Assert.assertEquals(1, actualRequests.size());
1569 
1570     String apiClientHeaderKey =
1571         mockService
1572             .getRequestHeaders()
1573             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1574             .iterator()
1575             .next();
1576     Assert.assertTrue(
1577         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1578             .matcher(apiClientHeaderKey)
1579             .matches());
1580   }
1581 
1582   @Test
batchDeleteEntitiesExceptionTest2()1583   public void batchDeleteEntitiesExceptionTest2() throws Exception {
1584     ApiException exception =
1585         ApiExceptionFactory.createException(
1586             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1587     mockService.addException(exception);
1588 
1589     try {
1590       String parent = "projects/project-2105/agent/entityTypes/entityType-2105";
1591       List<String> entityValues = new ArrayList<>();
1592       client.batchDeleteEntitiesAsync(parent, entityValues).get();
1593       Assert.fail("No exception raised");
1594     } catch (ExecutionException e) {
1595     }
1596   }
1597 
1598   @Test
batchDeleteEntitiesTest3()1599   public void batchDeleteEntitiesTest3() throws Exception {
1600     Empty expectedResponse = Empty.newBuilder().build();
1601     Operation resultOperation =
1602         Operation.newBuilder()
1603             .setName("batchDeleteEntitiesTest")
1604             .setDone(true)
1605             .setResponse(Any.pack(expectedResponse))
1606             .build();
1607     mockService.addResponse(resultOperation);
1608 
1609     EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
1610     List<String> entityValues = new ArrayList<>();
1611     String languageCode = "languageCode-2092349083";
1612 
1613     client.batchDeleteEntitiesAsync(parent, entityValues, languageCode).get();
1614 
1615     List<String> actualRequests = mockService.getRequestPaths();
1616     Assert.assertEquals(1, actualRequests.size());
1617 
1618     String apiClientHeaderKey =
1619         mockService
1620             .getRequestHeaders()
1621             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1622             .iterator()
1623             .next();
1624     Assert.assertTrue(
1625         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1626             .matcher(apiClientHeaderKey)
1627             .matches());
1628   }
1629 
1630   @Test
batchDeleteEntitiesExceptionTest3()1631   public void batchDeleteEntitiesExceptionTest3() throws Exception {
1632     ApiException exception =
1633         ApiExceptionFactory.createException(
1634             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1635     mockService.addException(exception);
1636 
1637     try {
1638       EntityTypeName parent = EntityTypeName.ofProjectEntityTypeName("[PROJECT]", "[ENTITY_TYPE]");
1639       List<String> entityValues = new ArrayList<>();
1640       String languageCode = "languageCode-2092349083";
1641       client.batchDeleteEntitiesAsync(parent, entityValues, languageCode).get();
1642       Assert.fail("No exception raised");
1643     } catch (ExecutionException e) {
1644     }
1645   }
1646 
1647   @Test
batchDeleteEntitiesTest4()1648   public void batchDeleteEntitiesTest4() throws Exception {
1649     Empty expectedResponse = Empty.newBuilder().build();
1650     Operation resultOperation =
1651         Operation.newBuilder()
1652             .setName("batchDeleteEntitiesTest")
1653             .setDone(true)
1654             .setResponse(Any.pack(expectedResponse))
1655             .build();
1656     mockService.addResponse(resultOperation);
1657 
1658     String parent = "projects/project-2105/agent/entityTypes/entityType-2105";
1659     List<String> entityValues = new ArrayList<>();
1660     String languageCode = "languageCode-2092349083";
1661 
1662     client.batchDeleteEntitiesAsync(parent, entityValues, languageCode).get();
1663 
1664     List<String> actualRequests = mockService.getRequestPaths();
1665     Assert.assertEquals(1, actualRequests.size());
1666 
1667     String apiClientHeaderKey =
1668         mockService
1669             .getRequestHeaders()
1670             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1671             .iterator()
1672             .next();
1673     Assert.assertTrue(
1674         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1675             .matcher(apiClientHeaderKey)
1676             .matches());
1677   }
1678 
1679   @Test
batchDeleteEntitiesExceptionTest4()1680   public void batchDeleteEntitiesExceptionTest4() throws Exception {
1681     ApiException exception =
1682         ApiExceptionFactory.createException(
1683             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1684     mockService.addException(exception);
1685 
1686     try {
1687       String parent = "projects/project-2105/agent/entityTypes/entityType-2105";
1688       List<String> entityValues = new ArrayList<>();
1689       String languageCode = "languageCode-2092349083";
1690       client.batchDeleteEntitiesAsync(parent, entityValues, languageCode).get();
1691       Assert.fail("No exception raised");
1692     } catch (ExecutionException e) {
1693     }
1694   }
1695 
1696   @Test
listLocationsTest()1697   public void listLocationsTest() throws Exception {
1698     Location responsesElement = Location.newBuilder().build();
1699     ListLocationsResponse expectedResponse =
1700         ListLocationsResponse.newBuilder()
1701             .setNextPageToken("")
1702             .addAllLocations(Arrays.asList(responsesElement))
1703             .build();
1704     mockService.addResponse(expectedResponse);
1705 
1706     ListLocationsRequest request =
1707         ListLocationsRequest.newBuilder()
1708             .setName("projects/project-3664")
1709             .setFilter("filter-1274492040")
1710             .setPageSize(883849137)
1711             .setPageToken("pageToken873572522")
1712             .build();
1713 
1714     ListLocationsPagedResponse pagedListResponse = client.listLocations(request);
1715 
1716     List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1717 
1718     Assert.assertEquals(1, resources.size());
1719     Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0));
1720 
1721     List<String> actualRequests = mockService.getRequestPaths();
1722     Assert.assertEquals(1, actualRequests.size());
1723 
1724     String apiClientHeaderKey =
1725         mockService
1726             .getRequestHeaders()
1727             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1728             .iterator()
1729             .next();
1730     Assert.assertTrue(
1731         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1732             .matcher(apiClientHeaderKey)
1733             .matches());
1734   }
1735 
1736   @Test
listLocationsExceptionTest()1737   public void listLocationsExceptionTest() throws Exception {
1738     ApiException exception =
1739         ApiExceptionFactory.createException(
1740             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1741     mockService.addException(exception);
1742 
1743     try {
1744       ListLocationsRequest request =
1745           ListLocationsRequest.newBuilder()
1746               .setName("projects/project-3664")
1747               .setFilter("filter-1274492040")
1748               .setPageSize(883849137)
1749               .setPageToken("pageToken873572522")
1750               .build();
1751       client.listLocations(request);
1752       Assert.fail("No exception raised");
1753     } catch (InvalidArgumentException e) {
1754       // Expected exception.
1755     }
1756   }
1757 
1758   @Test
getLocationTest()1759   public void getLocationTest() throws Exception {
1760     Location expectedResponse =
1761         Location.newBuilder()
1762             .setName("name3373707")
1763             .setLocationId("locationId1541836720")
1764             .setDisplayName("displayName1714148973")
1765             .putAllLabels(new HashMap<String, String>())
1766             .setMetadata(Any.newBuilder().build())
1767             .build();
1768     mockService.addResponse(expectedResponse);
1769 
1770     GetLocationRequest request =
1771         GetLocationRequest.newBuilder()
1772             .setName("projects/project-9062/locations/location-9062")
1773             .build();
1774 
1775     Location actualResponse = client.getLocation(request);
1776     Assert.assertEquals(expectedResponse, actualResponse);
1777 
1778     List<String> actualRequests = mockService.getRequestPaths();
1779     Assert.assertEquals(1, actualRequests.size());
1780 
1781     String apiClientHeaderKey =
1782         mockService
1783             .getRequestHeaders()
1784             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1785             .iterator()
1786             .next();
1787     Assert.assertTrue(
1788         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1789             .matcher(apiClientHeaderKey)
1790             .matches());
1791   }
1792 
1793   @Test
getLocationExceptionTest()1794   public void getLocationExceptionTest() throws Exception {
1795     ApiException exception =
1796         ApiExceptionFactory.createException(
1797             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1798     mockService.addException(exception);
1799 
1800     try {
1801       GetLocationRequest request =
1802           GetLocationRequest.newBuilder()
1803               .setName("projects/project-9062/locations/location-9062")
1804               .build();
1805       client.getLocation(request);
1806       Assert.fail("No exception raised");
1807     } catch (InvalidArgumentException e) {
1808       // Expected exception.
1809     }
1810   }
1811 }
1812