• 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.IntentsClient.ListIntentsPagedResponse;
20 import static com.google.cloud.dialogflow.cx.v3.IntentsClient.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.HttpJsonIntentsStub;
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 IntentsClientHttpJsonTest {
55   private static MockHttpService mockService;
56   private static IntentsClient client;
57 
58   @BeforeClass
startStaticServer()59   public static void startStaticServer() throws IOException {
60     mockService =
61         new MockHttpService(
62             HttpJsonIntentsStub.getMethodDescriptors(), IntentsSettings.getDefaultEndpoint());
63     IntentsSettings settings =
64         IntentsSettings.newHttpJsonBuilder()
65             .setTransportChannelProvider(
66                 IntentsSettings.defaultHttpJsonTransportProviderBuilder()
67                     .setHttpTransport(mockService)
68                     .build())
69             .setCredentialsProvider(NoCredentialsProvider.create())
70             .build();
71     client = IntentsClient.create(settings);
72   }
73 
74   @AfterClass
stopServer()75   public static void stopServer() {
76     client.close();
77   }
78 
79   @Before
setUp()80   public void setUp() {}
81 
82   @After
tearDown()83   public void tearDown() throws Exception {
84     mockService.reset();
85   }
86 
87   @Test
listIntentsTest()88   public void listIntentsTest() throws Exception {
89     Intent responsesElement = Intent.newBuilder().build();
90     ListIntentsResponse expectedResponse =
91         ListIntentsResponse.newBuilder()
92             .setNextPageToken("")
93             .addAllIntents(Arrays.asList(responsesElement))
94             .build();
95     mockService.addResponse(expectedResponse);
96 
97     AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
98 
99     ListIntentsPagedResponse pagedListResponse = client.listIntents(parent);
100 
101     List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll());
102 
103     Assert.assertEquals(1, resources.size());
104     Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0));
105 
106     List<String> actualRequests = mockService.getRequestPaths();
107     Assert.assertEquals(1, actualRequests.size());
108 
109     String apiClientHeaderKey =
110         mockService
111             .getRequestHeaders()
112             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
113             .iterator()
114             .next();
115     Assert.assertTrue(
116         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
117             .matcher(apiClientHeaderKey)
118             .matches());
119   }
120 
121   @Test
listIntentsExceptionTest()122   public void listIntentsExceptionTest() throws Exception {
123     ApiException exception =
124         ApiExceptionFactory.createException(
125             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
126     mockService.addException(exception);
127 
128     try {
129       AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
130       client.listIntents(parent);
131       Assert.fail("No exception raised");
132     } catch (InvalidArgumentException e) {
133       // Expected exception.
134     }
135   }
136 
137   @Test
listIntentsTest2()138   public void listIntentsTest2() throws Exception {
139     Intent responsesElement = Intent.newBuilder().build();
140     ListIntentsResponse expectedResponse =
141         ListIntentsResponse.newBuilder()
142             .setNextPageToken("")
143             .addAllIntents(Arrays.asList(responsesElement))
144             .build();
145     mockService.addResponse(expectedResponse);
146 
147     String parent = "projects/project-1167/locations/location-1167/agents/agent-1167";
148 
149     ListIntentsPagedResponse pagedListResponse = client.listIntents(parent);
150 
151     List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll());
152 
153     Assert.assertEquals(1, resources.size());
154     Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0));
155 
156     List<String> actualRequests = mockService.getRequestPaths();
157     Assert.assertEquals(1, actualRequests.size());
158 
159     String apiClientHeaderKey =
160         mockService
161             .getRequestHeaders()
162             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
163             .iterator()
164             .next();
165     Assert.assertTrue(
166         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
167             .matcher(apiClientHeaderKey)
168             .matches());
169   }
170 
171   @Test
listIntentsExceptionTest2()172   public void listIntentsExceptionTest2() throws Exception {
173     ApiException exception =
174         ApiExceptionFactory.createException(
175             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
176     mockService.addException(exception);
177 
178     try {
179       String parent = "projects/project-1167/locations/location-1167/agents/agent-1167";
180       client.listIntents(parent);
181       Assert.fail("No exception raised");
182     } catch (InvalidArgumentException e) {
183       // Expected exception.
184     }
185   }
186 
187   @Test
getIntentTest()188   public void getIntentTest() throws Exception {
189     Intent expectedResponse =
190         Intent.newBuilder()
191             .setName(IntentName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[INTENT]").toString())
192             .setDisplayName("displayName1714148973")
193             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
194             .addAllParameters(new ArrayList<Intent.Parameter>())
195             .setPriority(-1165461084)
196             .setIsFallback(true)
197             .putAllLabels(new HashMap<String, String>())
198             .setDescription("description-1724546052")
199             .build();
200     mockService.addResponse(expectedResponse);
201 
202     IntentName name = IntentName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[INTENT]");
203 
204     Intent actualResponse = client.getIntent(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
getIntentExceptionTest()223   public void getIntentExceptionTest() 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       IntentName name = IntentName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[INTENT]");
231       client.getIntent(name);
232       Assert.fail("No exception raised");
233     } catch (InvalidArgumentException e) {
234       // Expected exception.
235     }
236   }
237 
238   @Test
getIntentTest2()239   public void getIntentTest2() throws Exception {
240     Intent expectedResponse =
241         Intent.newBuilder()
242             .setName(IntentName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[INTENT]").toString())
243             .setDisplayName("displayName1714148973")
244             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
245             .addAllParameters(new ArrayList<Intent.Parameter>())
246             .setPriority(-1165461084)
247             .setIsFallback(true)
248             .putAllLabels(new HashMap<String, String>())
249             .setDescription("description-1724546052")
250             .build();
251     mockService.addResponse(expectedResponse);
252 
253     String name =
254         "projects/project-9121/locations/location-9121/agents/agent-9121/intents/intent-9121";
255 
256     Intent actualResponse = client.getIntent(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
getIntentExceptionTest2()275   public void getIntentExceptionTest2() 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-9121/locations/location-9121/agents/agent-9121/intents/intent-9121";
284       client.getIntent(name);
285       Assert.fail("No exception raised");
286     } catch (InvalidArgumentException e) {
287       // Expected exception.
288     }
289   }
290 
291   @Test
createIntentTest()292   public void createIntentTest() throws Exception {
293     Intent expectedResponse =
294         Intent.newBuilder()
295             .setName(IntentName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[INTENT]").toString())
296             .setDisplayName("displayName1714148973")
297             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
298             .addAllParameters(new ArrayList<Intent.Parameter>())
299             .setPriority(-1165461084)
300             .setIsFallback(true)
301             .putAllLabels(new HashMap<String, String>())
302             .setDescription("description-1724546052")
303             .build();
304     mockService.addResponse(expectedResponse);
305 
306     AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
307     Intent intent = Intent.newBuilder().build();
308 
309     Intent actualResponse = client.createIntent(parent, intent);
310     Assert.assertEquals(expectedResponse, actualResponse);
311 
312     List<String> actualRequests = mockService.getRequestPaths();
313     Assert.assertEquals(1, actualRequests.size());
314 
315     String apiClientHeaderKey =
316         mockService
317             .getRequestHeaders()
318             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
319             .iterator()
320             .next();
321     Assert.assertTrue(
322         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
323             .matcher(apiClientHeaderKey)
324             .matches());
325   }
326 
327   @Test
createIntentExceptionTest()328   public void createIntentExceptionTest() throws Exception {
329     ApiException exception =
330         ApiExceptionFactory.createException(
331             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
332     mockService.addException(exception);
333 
334     try {
335       AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
336       Intent intent = Intent.newBuilder().build();
337       client.createIntent(parent, intent);
338       Assert.fail("No exception raised");
339     } catch (InvalidArgumentException e) {
340       // Expected exception.
341     }
342   }
343 
344   @Test
createIntentTest2()345   public void createIntentTest2() throws Exception {
346     Intent expectedResponse =
347         Intent.newBuilder()
348             .setName(IntentName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[INTENT]").toString())
349             .setDisplayName("displayName1714148973")
350             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
351             .addAllParameters(new ArrayList<Intent.Parameter>())
352             .setPriority(-1165461084)
353             .setIsFallback(true)
354             .putAllLabels(new HashMap<String, String>())
355             .setDescription("description-1724546052")
356             .build();
357     mockService.addResponse(expectedResponse);
358 
359     String parent = "projects/project-1167/locations/location-1167/agents/agent-1167";
360     Intent intent = Intent.newBuilder().build();
361 
362     Intent actualResponse = client.createIntent(parent, intent);
363     Assert.assertEquals(expectedResponse, actualResponse);
364 
365     List<String> actualRequests = mockService.getRequestPaths();
366     Assert.assertEquals(1, actualRequests.size());
367 
368     String apiClientHeaderKey =
369         mockService
370             .getRequestHeaders()
371             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
372             .iterator()
373             .next();
374     Assert.assertTrue(
375         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
376             .matcher(apiClientHeaderKey)
377             .matches());
378   }
379 
380   @Test
createIntentExceptionTest2()381   public void createIntentExceptionTest2() throws Exception {
382     ApiException exception =
383         ApiExceptionFactory.createException(
384             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
385     mockService.addException(exception);
386 
387     try {
388       String parent = "projects/project-1167/locations/location-1167/agents/agent-1167";
389       Intent intent = Intent.newBuilder().build();
390       client.createIntent(parent, intent);
391       Assert.fail("No exception raised");
392     } catch (InvalidArgumentException e) {
393       // Expected exception.
394     }
395   }
396 
397   @Test
updateIntentTest()398   public void updateIntentTest() throws Exception {
399     Intent expectedResponse =
400         Intent.newBuilder()
401             .setName(IntentName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[INTENT]").toString())
402             .setDisplayName("displayName1714148973")
403             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
404             .addAllParameters(new ArrayList<Intent.Parameter>())
405             .setPriority(-1165461084)
406             .setIsFallback(true)
407             .putAllLabels(new HashMap<String, String>())
408             .setDescription("description-1724546052")
409             .build();
410     mockService.addResponse(expectedResponse);
411 
412     Intent intent =
413         Intent.newBuilder()
414             .setName(IntentName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[INTENT]").toString())
415             .setDisplayName("displayName1714148973")
416             .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
417             .addAllParameters(new ArrayList<Intent.Parameter>())
418             .setPriority(-1165461084)
419             .setIsFallback(true)
420             .putAllLabels(new HashMap<String, String>())
421             .setDescription("description-1724546052")
422             .build();
423     FieldMask updateMask = FieldMask.newBuilder().build();
424 
425     Intent actualResponse = client.updateIntent(intent, updateMask);
426     Assert.assertEquals(expectedResponse, actualResponse);
427 
428     List<String> actualRequests = mockService.getRequestPaths();
429     Assert.assertEquals(1, actualRequests.size());
430 
431     String apiClientHeaderKey =
432         mockService
433             .getRequestHeaders()
434             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
435             .iterator()
436             .next();
437     Assert.assertTrue(
438         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
439             .matcher(apiClientHeaderKey)
440             .matches());
441   }
442 
443   @Test
updateIntentExceptionTest()444   public void updateIntentExceptionTest() throws Exception {
445     ApiException exception =
446         ApiExceptionFactory.createException(
447             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
448     mockService.addException(exception);
449 
450     try {
451       Intent intent =
452           Intent.newBuilder()
453               .setName(IntentName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[INTENT]").toString())
454               .setDisplayName("displayName1714148973")
455               .addAllTrainingPhrases(new ArrayList<Intent.TrainingPhrase>())
456               .addAllParameters(new ArrayList<Intent.Parameter>())
457               .setPriority(-1165461084)
458               .setIsFallback(true)
459               .putAllLabels(new HashMap<String, String>())
460               .setDescription("description-1724546052")
461               .build();
462       FieldMask updateMask = FieldMask.newBuilder().build();
463       client.updateIntent(intent, updateMask);
464       Assert.fail("No exception raised");
465     } catch (InvalidArgumentException e) {
466       // Expected exception.
467     }
468   }
469 
470   @Test
deleteIntentTest()471   public void deleteIntentTest() throws Exception {
472     Empty expectedResponse = Empty.newBuilder().build();
473     mockService.addResponse(expectedResponse);
474 
475     IntentName name = IntentName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[INTENT]");
476 
477     client.deleteIntent(name);
478 
479     List<String> actualRequests = mockService.getRequestPaths();
480     Assert.assertEquals(1, actualRequests.size());
481 
482     String apiClientHeaderKey =
483         mockService
484             .getRequestHeaders()
485             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
486             .iterator()
487             .next();
488     Assert.assertTrue(
489         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
490             .matcher(apiClientHeaderKey)
491             .matches());
492   }
493 
494   @Test
deleteIntentExceptionTest()495   public void deleteIntentExceptionTest() throws Exception {
496     ApiException exception =
497         ApiExceptionFactory.createException(
498             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
499     mockService.addException(exception);
500 
501     try {
502       IntentName name = IntentName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[INTENT]");
503       client.deleteIntent(name);
504       Assert.fail("No exception raised");
505     } catch (InvalidArgumentException e) {
506       // Expected exception.
507     }
508   }
509 
510   @Test
deleteIntentTest2()511   public void deleteIntentTest2() throws Exception {
512     Empty expectedResponse = Empty.newBuilder().build();
513     mockService.addResponse(expectedResponse);
514 
515     String name =
516         "projects/project-9121/locations/location-9121/agents/agent-9121/intents/intent-9121";
517 
518     client.deleteIntent(name);
519 
520     List<String> actualRequests = mockService.getRequestPaths();
521     Assert.assertEquals(1, actualRequests.size());
522 
523     String apiClientHeaderKey =
524         mockService
525             .getRequestHeaders()
526             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
527             .iterator()
528             .next();
529     Assert.assertTrue(
530         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
531             .matcher(apiClientHeaderKey)
532             .matches());
533   }
534 
535   @Test
deleteIntentExceptionTest2()536   public void deleteIntentExceptionTest2() throws Exception {
537     ApiException exception =
538         ApiExceptionFactory.createException(
539             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
540     mockService.addException(exception);
541 
542     try {
543       String name =
544           "projects/project-9121/locations/location-9121/agents/agent-9121/intents/intent-9121";
545       client.deleteIntent(name);
546       Assert.fail("No exception raised");
547     } catch (InvalidArgumentException e) {
548       // Expected exception.
549     }
550   }
551 
552   @Test
listLocationsTest()553   public void listLocationsTest() throws Exception {
554     Location responsesElement = Location.newBuilder().build();
555     ListLocationsResponse expectedResponse =
556         ListLocationsResponse.newBuilder()
557             .setNextPageToken("")
558             .addAllLocations(Arrays.asList(responsesElement))
559             .build();
560     mockService.addResponse(expectedResponse);
561 
562     ListLocationsRequest request =
563         ListLocationsRequest.newBuilder()
564             .setName("projects/project-3664")
565             .setFilter("filter-1274492040")
566             .setPageSize(883849137)
567             .setPageToken("pageToken873572522")
568             .build();
569 
570     ListLocationsPagedResponse pagedListResponse = client.listLocations(request);
571 
572     List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll());
573 
574     Assert.assertEquals(1, resources.size());
575     Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0));
576 
577     List<String> actualRequests = mockService.getRequestPaths();
578     Assert.assertEquals(1, actualRequests.size());
579 
580     String apiClientHeaderKey =
581         mockService
582             .getRequestHeaders()
583             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
584             .iterator()
585             .next();
586     Assert.assertTrue(
587         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
588             .matcher(apiClientHeaderKey)
589             .matches());
590   }
591 
592   @Test
listLocationsExceptionTest()593   public void listLocationsExceptionTest() throws Exception {
594     ApiException exception =
595         ApiExceptionFactory.createException(
596             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
597     mockService.addException(exception);
598 
599     try {
600       ListLocationsRequest request =
601           ListLocationsRequest.newBuilder()
602               .setName("projects/project-3664")
603               .setFilter("filter-1274492040")
604               .setPageSize(883849137)
605               .setPageToken("pageToken873572522")
606               .build();
607       client.listLocations(request);
608       Assert.fail("No exception raised");
609     } catch (InvalidArgumentException e) {
610       // Expected exception.
611     }
612   }
613 
614   @Test
getLocationTest()615   public void getLocationTest() throws Exception {
616     Location expectedResponse =
617         Location.newBuilder()
618             .setName("name3373707")
619             .setLocationId("locationId1541836720")
620             .setDisplayName("displayName1714148973")
621             .putAllLabels(new HashMap<String, String>())
622             .setMetadata(Any.newBuilder().build())
623             .build();
624     mockService.addResponse(expectedResponse);
625 
626     GetLocationRequest request =
627         GetLocationRequest.newBuilder()
628             .setName("projects/project-9062/locations/location-9062")
629             .build();
630 
631     Location actualResponse = client.getLocation(request);
632     Assert.assertEquals(expectedResponse, actualResponse);
633 
634     List<String> actualRequests = mockService.getRequestPaths();
635     Assert.assertEquals(1, actualRequests.size());
636 
637     String apiClientHeaderKey =
638         mockService
639             .getRequestHeaders()
640             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
641             .iterator()
642             .next();
643     Assert.assertTrue(
644         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
645             .matcher(apiClientHeaderKey)
646             .matches());
647   }
648 
649   @Test
getLocationExceptionTest()650   public void getLocationExceptionTest() throws Exception {
651     ApiException exception =
652         ApiExceptionFactory.createException(
653             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
654     mockService.addException(exception);
655 
656     try {
657       GetLocationRequest request =
658           GetLocationRequest.newBuilder()
659               .setName("projects/project-9062/locations/location-9062")
660               .build();
661       client.getLocation(request);
662       Assert.fail("No exception raised");
663     } catch (InvalidArgumentException e) {
664       // Expected exception.
665     }
666   }
667 }
668