• 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.cx.v3;
18 
19 import static com.google.cloud.dialogflow.cx.v3.EntityTypesClient.ListEntityTypesPagedResponse;
20 import static com.google.cloud.dialogflow.cx.v3.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.cx.v3.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.protobuf.Any;
38 import com.google.protobuf.Empty;
39 import com.google.protobuf.FieldMask;
40 import java.io.IOException;
41 import java.util.ArrayList;
42 import java.util.Arrays;
43 import java.util.HashMap;
44 import java.util.List;
45 import javax.annotation.Generated;
46 import org.junit.After;
47 import org.junit.AfterClass;
48 import org.junit.Assert;
49 import org.junit.Before;
50 import org.junit.BeforeClass;
51 import org.junit.Test;
52 
53 @Generated("by gapic-generator-java")
54 public class EntityTypesClientHttpJsonTest {
55   private static MockHttpService mockService;
56   private static EntityTypesClient client;
57 
58   @BeforeClass
startStaticServer()59   public static void startStaticServer() throws IOException {
60     mockService =
61         new MockHttpService(
62             HttpJsonEntityTypesStub.getMethodDescriptors(),
63             EntityTypesSettings.getDefaultEndpoint());
64     EntityTypesSettings settings =
65         EntityTypesSettings.newHttpJsonBuilder()
66             .setTransportChannelProvider(
67                 EntityTypesSettings.defaultHttpJsonTransportProviderBuilder()
68                     .setHttpTransport(mockService)
69                     .build())
70             .setCredentialsProvider(NoCredentialsProvider.create())
71             .build();
72     client = EntityTypesClient.create(settings);
73   }
74 
75   @AfterClass
stopServer()76   public static void stopServer() {
77     client.close();
78   }
79 
80   @Before
setUp()81   public void setUp() {}
82 
83   @After
tearDown()84   public void tearDown() throws Exception {
85     mockService.reset();
86   }
87 
88   @Test
listEntityTypesTest()89   public void listEntityTypesTest() throws Exception {
90     EntityType responsesElement = EntityType.newBuilder().build();
91     ListEntityTypesResponse expectedResponse =
92         ListEntityTypesResponse.newBuilder()
93             .setNextPageToken("")
94             .addAllEntityTypes(Arrays.asList(responsesElement))
95             .build();
96     mockService.addResponse(expectedResponse);
97 
98     AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
99 
100     ListEntityTypesPagedResponse pagedListResponse = client.listEntityTypes(parent);
101 
102     List<EntityType> resources = Lists.newArrayList(pagedListResponse.iterateAll());
103 
104     Assert.assertEquals(1, resources.size());
105     Assert.assertEquals(expectedResponse.getEntityTypesList().get(0), resources.get(0));
106 
107     List<String> actualRequests = mockService.getRequestPaths();
108     Assert.assertEquals(1, actualRequests.size());
109 
110     String apiClientHeaderKey =
111         mockService
112             .getRequestHeaders()
113             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
114             .iterator()
115             .next();
116     Assert.assertTrue(
117         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
118             .matcher(apiClientHeaderKey)
119             .matches());
120   }
121 
122   @Test
listEntityTypesExceptionTest()123   public void listEntityTypesExceptionTest() throws Exception {
124     ApiException exception =
125         ApiExceptionFactory.createException(
126             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
127     mockService.addException(exception);
128 
129     try {
130       AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
131       client.listEntityTypes(parent);
132       Assert.fail("No exception raised");
133     } catch (InvalidArgumentException e) {
134       // Expected exception.
135     }
136   }
137 
138   @Test
listEntityTypesTest2()139   public void listEntityTypesTest2() throws Exception {
140     EntityType responsesElement = EntityType.newBuilder().build();
141     ListEntityTypesResponse expectedResponse =
142         ListEntityTypesResponse.newBuilder()
143             .setNextPageToken("")
144             .addAllEntityTypes(Arrays.asList(responsesElement))
145             .build();
146     mockService.addResponse(expectedResponse);
147 
148     String parent = "projects/project-1167/locations/location-1167/agents/agent-1167";
149 
150     ListEntityTypesPagedResponse pagedListResponse = client.listEntityTypes(parent);
151 
152     List<EntityType> resources = Lists.newArrayList(pagedListResponse.iterateAll());
153 
154     Assert.assertEquals(1, resources.size());
155     Assert.assertEquals(expectedResponse.getEntityTypesList().get(0), resources.get(0));
156 
157     List<String> actualRequests = mockService.getRequestPaths();
158     Assert.assertEquals(1, actualRequests.size());
159 
160     String apiClientHeaderKey =
161         mockService
162             .getRequestHeaders()
163             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
164             .iterator()
165             .next();
166     Assert.assertTrue(
167         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
168             .matcher(apiClientHeaderKey)
169             .matches());
170   }
171 
172   @Test
listEntityTypesExceptionTest2()173   public void listEntityTypesExceptionTest2() throws Exception {
174     ApiException exception =
175         ApiExceptionFactory.createException(
176             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
177     mockService.addException(exception);
178 
179     try {
180       String parent = "projects/project-1167/locations/location-1167/agents/agent-1167";
181       client.listEntityTypes(parent);
182       Assert.fail("No exception raised");
183     } catch (InvalidArgumentException e) {
184       // Expected exception.
185     }
186   }
187 
188   @Test
getEntityTypeTest()189   public void getEntityTypeTest() throws Exception {
190     EntityType expectedResponse =
191         EntityType.newBuilder()
192             .setName(
193                 EntityTypeName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[ENTITY_TYPE]").toString())
194             .setDisplayName("displayName1714148973")
195             .addAllEntities(new ArrayList<EntityType.Entity>())
196             .addAllExcludedPhrases(new ArrayList<EntityType.ExcludedPhrase>())
197             .setEnableFuzzyExtraction(true)
198             .setRedact(true)
199             .build();
200     mockService.addResponse(expectedResponse);
201 
202     EntityTypeName name = EntityTypeName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[ENTITY_TYPE]");
203 
204     EntityType actualResponse = client.getEntityType(name);
205     Assert.assertEquals(expectedResponse, actualResponse);
206 
207     List<String> actualRequests = mockService.getRequestPaths();
208     Assert.assertEquals(1, actualRequests.size());
209 
210     String apiClientHeaderKey =
211         mockService
212             .getRequestHeaders()
213             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
214             .iterator()
215             .next();
216     Assert.assertTrue(
217         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
218             .matcher(apiClientHeaderKey)
219             .matches());
220   }
221 
222   @Test
getEntityTypeExceptionTest()223   public void getEntityTypeExceptionTest() throws Exception {
224     ApiException exception =
225         ApiExceptionFactory.createException(
226             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
227     mockService.addException(exception);
228 
229     try {
230       EntityTypeName name =
231           EntityTypeName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[ENTITY_TYPE]");
232       client.getEntityType(name);
233       Assert.fail("No exception raised");
234     } catch (InvalidArgumentException e) {
235       // Expected exception.
236     }
237   }
238 
239   @Test
getEntityTypeTest2()240   public void getEntityTypeTest2() throws Exception {
241     EntityType expectedResponse =
242         EntityType.newBuilder()
243             .setName(
244                 EntityTypeName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[ENTITY_TYPE]").toString())
245             .setDisplayName("displayName1714148973")
246             .addAllEntities(new ArrayList<EntityType.Entity>())
247             .addAllExcludedPhrases(new ArrayList<EntityType.ExcludedPhrase>())
248             .setEnableFuzzyExtraction(true)
249             .setRedact(true)
250             .build();
251     mockService.addResponse(expectedResponse);
252 
253     String name =
254         "projects/project-4320/locations/location-4320/agents/agent-4320/entityTypes/entityType-4320";
255 
256     EntityType actualResponse = client.getEntityType(name);
257     Assert.assertEquals(expectedResponse, actualResponse);
258 
259     List<String> actualRequests = mockService.getRequestPaths();
260     Assert.assertEquals(1, actualRequests.size());
261 
262     String apiClientHeaderKey =
263         mockService
264             .getRequestHeaders()
265             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
266             .iterator()
267             .next();
268     Assert.assertTrue(
269         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
270             .matcher(apiClientHeaderKey)
271             .matches());
272   }
273 
274   @Test
getEntityTypeExceptionTest2()275   public void getEntityTypeExceptionTest2() throws Exception {
276     ApiException exception =
277         ApiExceptionFactory.createException(
278             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
279     mockService.addException(exception);
280 
281     try {
282       String name =
283           "projects/project-4320/locations/location-4320/agents/agent-4320/entityTypes/entityType-4320";
284       client.getEntityType(name);
285       Assert.fail("No exception raised");
286     } catch (InvalidArgumentException e) {
287       // Expected exception.
288     }
289   }
290 
291   @Test
createEntityTypeTest()292   public void createEntityTypeTest() throws Exception {
293     EntityType expectedResponse =
294         EntityType.newBuilder()
295             .setName(
296                 EntityTypeName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[ENTITY_TYPE]").toString())
297             .setDisplayName("displayName1714148973")
298             .addAllEntities(new ArrayList<EntityType.Entity>())
299             .addAllExcludedPhrases(new ArrayList<EntityType.ExcludedPhrase>())
300             .setEnableFuzzyExtraction(true)
301             .setRedact(true)
302             .build();
303     mockService.addResponse(expectedResponse);
304 
305     AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
306     EntityType entityType = EntityType.newBuilder().build();
307 
308     EntityType actualResponse = client.createEntityType(parent, entityType);
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
createEntityTypeExceptionTest()327   public void createEntityTypeExceptionTest() 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       AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
335       EntityType entityType = EntityType.newBuilder().build();
336       client.createEntityType(parent, entityType);
337       Assert.fail("No exception raised");
338     } catch (InvalidArgumentException e) {
339       // Expected exception.
340     }
341   }
342 
343   @Test
createEntityTypeTest2()344   public void createEntityTypeTest2() throws Exception {
345     EntityType expectedResponse =
346         EntityType.newBuilder()
347             .setName(
348                 EntityTypeName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[ENTITY_TYPE]").toString())
349             .setDisplayName("displayName1714148973")
350             .addAllEntities(new ArrayList<EntityType.Entity>())
351             .addAllExcludedPhrases(new ArrayList<EntityType.ExcludedPhrase>())
352             .setEnableFuzzyExtraction(true)
353             .setRedact(true)
354             .build();
355     mockService.addResponse(expectedResponse);
356 
357     String parent = "projects/project-1167/locations/location-1167/agents/agent-1167";
358     EntityType entityType = EntityType.newBuilder().build();
359 
360     EntityType actualResponse = client.createEntityType(parent, entityType);
361     Assert.assertEquals(expectedResponse, actualResponse);
362 
363     List<String> actualRequests = mockService.getRequestPaths();
364     Assert.assertEquals(1, actualRequests.size());
365 
366     String apiClientHeaderKey =
367         mockService
368             .getRequestHeaders()
369             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
370             .iterator()
371             .next();
372     Assert.assertTrue(
373         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
374             .matcher(apiClientHeaderKey)
375             .matches());
376   }
377 
378   @Test
createEntityTypeExceptionTest2()379   public void createEntityTypeExceptionTest2() throws Exception {
380     ApiException exception =
381         ApiExceptionFactory.createException(
382             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
383     mockService.addException(exception);
384 
385     try {
386       String parent = "projects/project-1167/locations/location-1167/agents/agent-1167";
387       EntityType entityType = EntityType.newBuilder().build();
388       client.createEntityType(parent, entityType);
389       Assert.fail("No exception raised");
390     } catch (InvalidArgumentException e) {
391       // Expected exception.
392     }
393   }
394 
395   @Test
updateEntityTypeTest()396   public void updateEntityTypeTest() throws Exception {
397     EntityType expectedResponse =
398         EntityType.newBuilder()
399             .setName(
400                 EntityTypeName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[ENTITY_TYPE]").toString())
401             .setDisplayName("displayName1714148973")
402             .addAllEntities(new ArrayList<EntityType.Entity>())
403             .addAllExcludedPhrases(new ArrayList<EntityType.ExcludedPhrase>())
404             .setEnableFuzzyExtraction(true)
405             .setRedact(true)
406             .build();
407     mockService.addResponse(expectedResponse);
408 
409     EntityType entityType =
410         EntityType.newBuilder()
411             .setName(
412                 EntityTypeName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[ENTITY_TYPE]").toString())
413             .setDisplayName("displayName1714148973")
414             .addAllEntities(new ArrayList<EntityType.Entity>())
415             .addAllExcludedPhrases(new ArrayList<EntityType.ExcludedPhrase>())
416             .setEnableFuzzyExtraction(true)
417             .setRedact(true)
418             .build();
419     FieldMask updateMask = FieldMask.newBuilder().build();
420 
421     EntityType actualResponse = client.updateEntityType(entityType, updateMask);
422     Assert.assertEquals(expectedResponse, actualResponse);
423 
424     List<String> actualRequests = mockService.getRequestPaths();
425     Assert.assertEquals(1, actualRequests.size());
426 
427     String apiClientHeaderKey =
428         mockService
429             .getRequestHeaders()
430             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
431             .iterator()
432             .next();
433     Assert.assertTrue(
434         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
435             .matcher(apiClientHeaderKey)
436             .matches());
437   }
438 
439   @Test
updateEntityTypeExceptionTest()440   public void updateEntityTypeExceptionTest() throws Exception {
441     ApiException exception =
442         ApiExceptionFactory.createException(
443             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
444     mockService.addException(exception);
445 
446     try {
447       EntityType entityType =
448           EntityType.newBuilder()
449               .setName(
450                   EntityTypeName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[ENTITY_TYPE]")
451                       .toString())
452               .setDisplayName("displayName1714148973")
453               .addAllEntities(new ArrayList<EntityType.Entity>())
454               .addAllExcludedPhrases(new ArrayList<EntityType.ExcludedPhrase>())
455               .setEnableFuzzyExtraction(true)
456               .setRedact(true)
457               .build();
458       FieldMask updateMask = FieldMask.newBuilder().build();
459       client.updateEntityType(entityType, updateMask);
460       Assert.fail("No exception raised");
461     } catch (InvalidArgumentException e) {
462       // Expected exception.
463     }
464   }
465 
466   @Test
deleteEntityTypeTest()467   public void deleteEntityTypeTest() throws Exception {
468     Empty expectedResponse = Empty.newBuilder().build();
469     mockService.addResponse(expectedResponse);
470 
471     EntityTypeName name = EntityTypeName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[ENTITY_TYPE]");
472 
473     client.deleteEntityType(name);
474 
475     List<String> actualRequests = mockService.getRequestPaths();
476     Assert.assertEquals(1, actualRequests.size());
477 
478     String apiClientHeaderKey =
479         mockService
480             .getRequestHeaders()
481             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
482             .iterator()
483             .next();
484     Assert.assertTrue(
485         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
486             .matcher(apiClientHeaderKey)
487             .matches());
488   }
489 
490   @Test
deleteEntityTypeExceptionTest()491   public void deleteEntityTypeExceptionTest() throws Exception {
492     ApiException exception =
493         ApiExceptionFactory.createException(
494             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
495     mockService.addException(exception);
496 
497     try {
498       EntityTypeName name =
499           EntityTypeName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[ENTITY_TYPE]");
500       client.deleteEntityType(name);
501       Assert.fail("No exception raised");
502     } catch (InvalidArgumentException e) {
503       // Expected exception.
504     }
505   }
506 
507   @Test
deleteEntityTypeTest2()508   public void deleteEntityTypeTest2() throws Exception {
509     Empty expectedResponse = Empty.newBuilder().build();
510     mockService.addResponse(expectedResponse);
511 
512     String name =
513         "projects/project-4320/locations/location-4320/agents/agent-4320/entityTypes/entityType-4320";
514 
515     client.deleteEntityType(name);
516 
517     List<String> actualRequests = mockService.getRequestPaths();
518     Assert.assertEquals(1, actualRequests.size());
519 
520     String apiClientHeaderKey =
521         mockService
522             .getRequestHeaders()
523             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
524             .iterator()
525             .next();
526     Assert.assertTrue(
527         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
528             .matcher(apiClientHeaderKey)
529             .matches());
530   }
531 
532   @Test
deleteEntityTypeExceptionTest2()533   public void deleteEntityTypeExceptionTest2() throws Exception {
534     ApiException exception =
535         ApiExceptionFactory.createException(
536             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
537     mockService.addException(exception);
538 
539     try {
540       String name =
541           "projects/project-4320/locations/location-4320/agents/agent-4320/entityTypes/entityType-4320";
542       client.deleteEntityType(name);
543       Assert.fail("No exception raised");
544     } catch (InvalidArgumentException e) {
545       // Expected exception.
546     }
547   }
548 
549   @Test
listLocationsTest()550   public void listLocationsTest() throws Exception {
551     Location responsesElement = Location.newBuilder().build();
552     ListLocationsResponse expectedResponse =
553         ListLocationsResponse.newBuilder()
554             .setNextPageToken("")
555             .addAllLocations(Arrays.asList(responsesElement))
556             .build();
557     mockService.addResponse(expectedResponse);
558 
559     ListLocationsRequest request =
560         ListLocationsRequest.newBuilder()
561             .setName("projects/project-3664")
562             .setFilter("filter-1274492040")
563             .setPageSize(883849137)
564             .setPageToken("pageToken873572522")
565             .build();
566 
567     ListLocationsPagedResponse pagedListResponse = client.listLocations(request);
568 
569     List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll());
570 
571     Assert.assertEquals(1, resources.size());
572     Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0));
573 
574     List<String> actualRequests = mockService.getRequestPaths();
575     Assert.assertEquals(1, actualRequests.size());
576 
577     String apiClientHeaderKey =
578         mockService
579             .getRequestHeaders()
580             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
581             .iterator()
582             .next();
583     Assert.assertTrue(
584         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
585             .matcher(apiClientHeaderKey)
586             .matches());
587   }
588 
589   @Test
listLocationsExceptionTest()590   public void listLocationsExceptionTest() throws Exception {
591     ApiException exception =
592         ApiExceptionFactory.createException(
593             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
594     mockService.addException(exception);
595 
596     try {
597       ListLocationsRequest request =
598           ListLocationsRequest.newBuilder()
599               .setName("projects/project-3664")
600               .setFilter("filter-1274492040")
601               .setPageSize(883849137)
602               .setPageToken("pageToken873572522")
603               .build();
604       client.listLocations(request);
605       Assert.fail("No exception raised");
606     } catch (InvalidArgumentException e) {
607       // Expected exception.
608     }
609   }
610 
611   @Test
getLocationTest()612   public void getLocationTest() throws Exception {
613     Location expectedResponse =
614         Location.newBuilder()
615             .setName("name3373707")
616             .setLocationId("locationId1541836720")
617             .setDisplayName("displayName1714148973")
618             .putAllLabels(new HashMap<String, String>())
619             .setMetadata(Any.newBuilder().build())
620             .build();
621     mockService.addResponse(expectedResponse);
622 
623     GetLocationRequest request =
624         GetLocationRequest.newBuilder()
625             .setName("projects/project-9062/locations/location-9062")
626             .build();
627 
628     Location actualResponse = client.getLocation(request);
629     Assert.assertEquals(expectedResponse, actualResponse);
630 
631     List<String> actualRequests = mockService.getRequestPaths();
632     Assert.assertEquals(1, actualRequests.size());
633 
634     String apiClientHeaderKey =
635         mockService
636             .getRequestHeaders()
637             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
638             .iterator()
639             .next();
640     Assert.assertTrue(
641         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
642             .matcher(apiClientHeaderKey)
643             .matches());
644   }
645 
646   @Test
getLocationExceptionTest()647   public void getLocationExceptionTest() throws Exception {
648     ApiException exception =
649         ApiExceptionFactory.createException(
650             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
651     mockService.addException(exception);
652 
653     try {
654       GetLocationRequest request =
655           GetLocationRequest.newBuilder()
656               .setName("projects/project-9062/locations/location-9062")
657               .build();
658       client.getLocation(request);
659       Assert.fail("No exception raised");
660     } catch (InvalidArgumentException e) {
661       // Expected exception.
662     }
663   }
664 }
665