• 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.SessionEntityTypesClient.ListLocationsPagedResponse;
20 import static com.google.cloud.dialogflow.cx.v3.SessionEntityTypesClient.ListSessionEntityTypesPagedResponse;
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.HttpJsonSessionEntityTypesStub;
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 SessionEntityTypesClientHttpJsonTest {
55   private static MockHttpService mockService;
56   private static SessionEntityTypesClient client;
57 
58   @BeforeClass
startStaticServer()59   public static void startStaticServer() throws IOException {
60     mockService =
61         new MockHttpService(
62             HttpJsonSessionEntityTypesStub.getMethodDescriptors(),
63             SessionEntityTypesSettings.getDefaultEndpoint());
64     SessionEntityTypesSettings settings =
65         SessionEntityTypesSettings.newHttpJsonBuilder()
66             .setTransportChannelProvider(
67                 SessionEntityTypesSettings.defaultHttpJsonTransportProviderBuilder()
68                     .setHttpTransport(mockService)
69                     .build())
70             .setCredentialsProvider(NoCredentialsProvider.create())
71             .build();
72     client = SessionEntityTypesClient.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
listSessionEntityTypesTest()89   public void listSessionEntityTypesTest() throws Exception {
90     SessionEntityType responsesElement = SessionEntityType.newBuilder().build();
91     ListSessionEntityTypesResponse expectedResponse =
92         ListSessionEntityTypesResponse.newBuilder()
93             .setNextPageToken("")
94             .addAllSessionEntityTypes(Arrays.asList(responsesElement))
95             .build();
96     mockService.addResponse(expectedResponse);
97 
98     SessionName parent =
99         SessionName.ofProjectLocationAgentSessionName(
100             "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]");
101 
102     ListSessionEntityTypesPagedResponse pagedListResponse = client.listSessionEntityTypes(parent);
103 
104     List<SessionEntityType> resources = Lists.newArrayList(pagedListResponse.iterateAll());
105 
106     Assert.assertEquals(1, resources.size());
107     Assert.assertEquals(expectedResponse.getSessionEntityTypesList().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
listSessionEntityTypesExceptionTest()125   public void listSessionEntityTypesExceptionTest() 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       SessionName parent =
133           SessionName.ofProjectLocationAgentSessionName(
134               "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]");
135       client.listSessionEntityTypes(parent);
136       Assert.fail("No exception raised");
137     } catch (InvalidArgumentException e) {
138       // Expected exception.
139     }
140   }
141 
142   @Test
listSessionEntityTypesTest2()143   public void listSessionEntityTypesTest2() throws Exception {
144     SessionEntityType responsesElement = SessionEntityType.newBuilder().build();
145     ListSessionEntityTypesResponse expectedResponse =
146         ListSessionEntityTypesResponse.newBuilder()
147             .setNextPageToken("")
148             .addAllSessionEntityTypes(Arrays.asList(responsesElement))
149             .build();
150     mockService.addResponse(expectedResponse);
151 
152     String parent =
153         "projects/project-6792/locations/location-6792/agents/agent-6792/sessions/session-6792";
154 
155     ListSessionEntityTypesPagedResponse pagedListResponse = client.listSessionEntityTypes(parent);
156 
157     List<SessionEntityType> resources = Lists.newArrayList(pagedListResponse.iterateAll());
158 
159     Assert.assertEquals(1, resources.size());
160     Assert.assertEquals(expectedResponse.getSessionEntityTypesList().get(0), resources.get(0));
161 
162     List<String> actualRequests = mockService.getRequestPaths();
163     Assert.assertEquals(1, actualRequests.size());
164 
165     String apiClientHeaderKey =
166         mockService
167             .getRequestHeaders()
168             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
169             .iterator()
170             .next();
171     Assert.assertTrue(
172         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
173             .matcher(apiClientHeaderKey)
174             .matches());
175   }
176 
177   @Test
listSessionEntityTypesExceptionTest2()178   public void listSessionEntityTypesExceptionTest2() throws Exception {
179     ApiException exception =
180         ApiExceptionFactory.createException(
181             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
182     mockService.addException(exception);
183 
184     try {
185       String parent =
186           "projects/project-6792/locations/location-6792/agents/agent-6792/sessions/session-6792";
187       client.listSessionEntityTypes(parent);
188       Assert.fail("No exception raised");
189     } catch (InvalidArgumentException e) {
190       // Expected exception.
191     }
192   }
193 
194   @Test
getSessionEntityTypeTest()195   public void getSessionEntityTypeTest() throws Exception {
196     SessionEntityType expectedResponse =
197         SessionEntityType.newBuilder()
198             .setName(
199                 SessionEntityTypeName.ofProjectLocationAgentSessionEntityTypeName(
200                         "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]", "[ENTITY_TYPE]")
201                     .toString())
202             .addAllEntities(new ArrayList<EntityType.Entity>())
203             .build();
204     mockService.addResponse(expectedResponse);
205 
206     SessionEntityTypeName name =
207         SessionEntityTypeName.ofProjectLocationAgentSessionEntityTypeName(
208             "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]", "[ENTITY_TYPE]");
209 
210     SessionEntityType actualResponse = client.getSessionEntityType(name);
211     Assert.assertEquals(expectedResponse, actualResponse);
212 
213     List<String> actualRequests = mockService.getRequestPaths();
214     Assert.assertEquals(1, actualRequests.size());
215 
216     String apiClientHeaderKey =
217         mockService
218             .getRequestHeaders()
219             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
220             .iterator()
221             .next();
222     Assert.assertTrue(
223         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
224             .matcher(apiClientHeaderKey)
225             .matches());
226   }
227 
228   @Test
getSessionEntityTypeExceptionTest()229   public void getSessionEntityTypeExceptionTest() throws Exception {
230     ApiException exception =
231         ApiExceptionFactory.createException(
232             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
233     mockService.addException(exception);
234 
235     try {
236       SessionEntityTypeName name =
237           SessionEntityTypeName.ofProjectLocationAgentSessionEntityTypeName(
238               "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]", "[ENTITY_TYPE]");
239       client.getSessionEntityType(name);
240       Assert.fail("No exception raised");
241     } catch (InvalidArgumentException e) {
242       // Expected exception.
243     }
244   }
245 
246   @Test
getSessionEntityTypeTest2()247   public void getSessionEntityTypeTest2() throws Exception {
248     SessionEntityType expectedResponse =
249         SessionEntityType.newBuilder()
250             .setName(
251                 SessionEntityTypeName.ofProjectLocationAgentSessionEntityTypeName(
252                         "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]", "[ENTITY_TYPE]")
253                     .toString())
254             .addAllEntities(new ArrayList<EntityType.Entity>())
255             .build();
256     mockService.addResponse(expectedResponse);
257 
258     String name =
259         "projects/project-1499/locations/location-1499/agents/agent-1499/sessions/session-1499/entityTypes/entityType-1499";
260 
261     SessionEntityType actualResponse = client.getSessionEntityType(name);
262     Assert.assertEquals(expectedResponse, actualResponse);
263 
264     List<String> actualRequests = mockService.getRequestPaths();
265     Assert.assertEquals(1, actualRequests.size());
266 
267     String apiClientHeaderKey =
268         mockService
269             .getRequestHeaders()
270             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
271             .iterator()
272             .next();
273     Assert.assertTrue(
274         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
275             .matcher(apiClientHeaderKey)
276             .matches());
277   }
278 
279   @Test
getSessionEntityTypeExceptionTest2()280   public void getSessionEntityTypeExceptionTest2() throws Exception {
281     ApiException exception =
282         ApiExceptionFactory.createException(
283             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
284     mockService.addException(exception);
285 
286     try {
287       String name =
288           "projects/project-1499/locations/location-1499/agents/agent-1499/sessions/session-1499/entityTypes/entityType-1499";
289       client.getSessionEntityType(name);
290       Assert.fail("No exception raised");
291     } catch (InvalidArgumentException e) {
292       // Expected exception.
293     }
294   }
295 
296   @Test
createSessionEntityTypeTest()297   public void createSessionEntityTypeTest() throws Exception {
298     SessionEntityType expectedResponse =
299         SessionEntityType.newBuilder()
300             .setName(
301                 SessionEntityTypeName.ofProjectLocationAgentSessionEntityTypeName(
302                         "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]", "[ENTITY_TYPE]")
303                     .toString())
304             .addAllEntities(new ArrayList<EntityType.Entity>())
305             .build();
306     mockService.addResponse(expectedResponse);
307 
308     SessionName parent =
309         SessionName.ofProjectLocationAgentSessionName(
310             "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]");
311     SessionEntityType sessionEntityType = SessionEntityType.newBuilder().build();
312 
313     SessionEntityType actualResponse = client.createSessionEntityType(parent, sessionEntityType);
314     Assert.assertEquals(expectedResponse, actualResponse);
315 
316     List<String> actualRequests = mockService.getRequestPaths();
317     Assert.assertEquals(1, actualRequests.size());
318 
319     String apiClientHeaderKey =
320         mockService
321             .getRequestHeaders()
322             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
323             .iterator()
324             .next();
325     Assert.assertTrue(
326         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
327             .matcher(apiClientHeaderKey)
328             .matches());
329   }
330 
331   @Test
createSessionEntityTypeExceptionTest()332   public void createSessionEntityTypeExceptionTest() throws Exception {
333     ApiException exception =
334         ApiExceptionFactory.createException(
335             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
336     mockService.addException(exception);
337 
338     try {
339       SessionName parent =
340           SessionName.ofProjectLocationAgentSessionName(
341               "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]");
342       SessionEntityType sessionEntityType = SessionEntityType.newBuilder().build();
343       client.createSessionEntityType(parent, sessionEntityType);
344       Assert.fail("No exception raised");
345     } catch (InvalidArgumentException e) {
346       // Expected exception.
347     }
348   }
349 
350   @Test
createSessionEntityTypeTest2()351   public void createSessionEntityTypeTest2() throws Exception {
352     SessionEntityType expectedResponse =
353         SessionEntityType.newBuilder()
354             .setName(
355                 SessionEntityTypeName.ofProjectLocationAgentSessionEntityTypeName(
356                         "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]", "[ENTITY_TYPE]")
357                     .toString())
358             .addAllEntities(new ArrayList<EntityType.Entity>())
359             .build();
360     mockService.addResponse(expectedResponse);
361 
362     String parent =
363         "projects/project-6792/locations/location-6792/agents/agent-6792/sessions/session-6792";
364     SessionEntityType sessionEntityType = SessionEntityType.newBuilder().build();
365 
366     SessionEntityType actualResponse = client.createSessionEntityType(parent, sessionEntityType);
367     Assert.assertEquals(expectedResponse, actualResponse);
368 
369     List<String> actualRequests = mockService.getRequestPaths();
370     Assert.assertEquals(1, actualRequests.size());
371 
372     String apiClientHeaderKey =
373         mockService
374             .getRequestHeaders()
375             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
376             .iterator()
377             .next();
378     Assert.assertTrue(
379         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
380             .matcher(apiClientHeaderKey)
381             .matches());
382   }
383 
384   @Test
createSessionEntityTypeExceptionTest2()385   public void createSessionEntityTypeExceptionTest2() throws Exception {
386     ApiException exception =
387         ApiExceptionFactory.createException(
388             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
389     mockService.addException(exception);
390 
391     try {
392       String parent =
393           "projects/project-6792/locations/location-6792/agents/agent-6792/sessions/session-6792";
394       SessionEntityType sessionEntityType = SessionEntityType.newBuilder().build();
395       client.createSessionEntityType(parent, sessionEntityType);
396       Assert.fail("No exception raised");
397     } catch (InvalidArgumentException e) {
398       // Expected exception.
399     }
400   }
401 
402   @Test
updateSessionEntityTypeTest()403   public void updateSessionEntityTypeTest() throws Exception {
404     SessionEntityType expectedResponse =
405         SessionEntityType.newBuilder()
406             .setName(
407                 SessionEntityTypeName.ofProjectLocationAgentSessionEntityTypeName(
408                         "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]", "[ENTITY_TYPE]")
409                     .toString())
410             .addAllEntities(new ArrayList<EntityType.Entity>())
411             .build();
412     mockService.addResponse(expectedResponse);
413 
414     SessionEntityType sessionEntityType =
415         SessionEntityType.newBuilder()
416             .setName(
417                 SessionEntityTypeName.ofProjectLocationAgentSessionEntityTypeName(
418                         "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]", "[ENTITY_TYPE]")
419                     .toString())
420             .addAllEntities(new ArrayList<EntityType.Entity>())
421             .build();
422     FieldMask updateMask = FieldMask.newBuilder().build();
423 
424     SessionEntityType actualResponse =
425         client.updateSessionEntityType(sessionEntityType, 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
updateSessionEntityTypeExceptionTest()444   public void updateSessionEntityTypeExceptionTest() 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       SessionEntityType sessionEntityType =
452           SessionEntityType.newBuilder()
453               .setName(
454                   SessionEntityTypeName.ofProjectLocationAgentSessionEntityTypeName(
455                           "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]", "[ENTITY_TYPE]")
456                       .toString())
457               .addAllEntities(new ArrayList<EntityType.Entity>())
458               .build();
459       FieldMask updateMask = FieldMask.newBuilder().build();
460       client.updateSessionEntityType(sessionEntityType, updateMask);
461       Assert.fail("No exception raised");
462     } catch (InvalidArgumentException e) {
463       // Expected exception.
464     }
465   }
466 
467   @Test
deleteSessionEntityTypeTest()468   public void deleteSessionEntityTypeTest() throws Exception {
469     Empty expectedResponse = Empty.newBuilder().build();
470     mockService.addResponse(expectedResponse);
471 
472     SessionEntityTypeName name =
473         SessionEntityTypeName.ofProjectLocationAgentSessionEntityTypeName(
474             "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]", "[ENTITY_TYPE]");
475 
476     client.deleteSessionEntityType(name);
477 
478     List<String> actualRequests = mockService.getRequestPaths();
479     Assert.assertEquals(1, actualRequests.size());
480 
481     String apiClientHeaderKey =
482         mockService
483             .getRequestHeaders()
484             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
485             .iterator()
486             .next();
487     Assert.assertTrue(
488         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
489             .matcher(apiClientHeaderKey)
490             .matches());
491   }
492 
493   @Test
deleteSessionEntityTypeExceptionTest()494   public void deleteSessionEntityTypeExceptionTest() throws Exception {
495     ApiException exception =
496         ApiExceptionFactory.createException(
497             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
498     mockService.addException(exception);
499 
500     try {
501       SessionEntityTypeName name =
502           SessionEntityTypeName.ofProjectLocationAgentSessionEntityTypeName(
503               "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]", "[ENTITY_TYPE]");
504       client.deleteSessionEntityType(name);
505       Assert.fail("No exception raised");
506     } catch (InvalidArgumentException e) {
507       // Expected exception.
508     }
509   }
510 
511   @Test
deleteSessionEntityTypeTest2()512   public void deleteSessionEntityTypeTest2() throws Exception {
513     Empty expectedResponse = Empty.newBuilder().build();
514     mockService.addResponse(expectedResponse);
515 
516     String name =
517         "projects/project-1499/locations/location-1499/agents/agent-1499/sessions/session-1499/entityTypes/entityType-1499";
518 
519     client.deleteSessionEntityType(name);
520 
521     List<String> actualRequests = mockService.getRequestPaths();
522     Assert.assertEquals(1, actualRequests.size());
523 
524     String apiClientHeaderKey =
525         mockService
526             .getRequestHeaders()
527             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
528             .iterator()
529             .next();
530     Assert.assertTrue(
531         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
532             .matcher(apiClientHeaderKey)
533             .matches());
534   }
535 
536   @Test
deleteSessionEntityTypeExceptionTest2()537   public void deleteSessionEntityTypeExceptionTest2() throws Exception {
538     ApiException exception =
539         ApiExceptionFactory.createException(
540             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
541     mockService.addException(exception);
542 
543     try {
544       String name =
545           "projects/project-1499/locations/location-1499/agents/agent-1499/sessions/session-1499/entityTypes/entityType-1499";
546       client.deleteSessionEntityType(name);
547       Assert.fail("No exception raised");
548     } catch (InvalidArgumentException e) {
549       // Expected exception.
550     }
551   }
552 
553   @Test
listLocationsTest()554   public void listLocationsTest() throws Exception {
555     Location responsesElement = Location.newBuilder().build();
556     ListLocationsResponse expectedResponse =
557         ListLocationsResponse.newBuilder()
558             .setNextPageToken("")
559             .addAllLocations(Arrays.asList(responsesElement))
560             .build();
561     mockService.addResponse(expectedResponse);
562 
563     ListLocationsRequest request =
564         ListLocationsRequest.newBuilder()
565             .setName("projects/project-3664")
566             .setFilter("filter-1274492040")
567             .setPageSize(883849137)
568             .setPageToken("pageToken873572522")
569             .build();
570 
571     ListLocationsPagedResponse pagedListResponse = client.listLocations(request);
572 
573     List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll());
574 
575     Assert.assertEquals(1, resources.size());
576     Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0));
577 
578     List<String> actualRequests = mockService.getRequestPaths();
579     Assert.assertEquals(1, actualRequests.size());
580 
581     String apiClientHeaderKey =
582         mockService
583             .getRequestHeaders()
584             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
585             .iterator()
586             .next();
587     Assert.assertTrue(
588         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
589             .matcher(apiClientHeaderKey)
590             .matches());
591   }
592 
593   @Test
listLocationsExceptionTest()594   public void listLocationsExceptionTest() throws Exception {
595     ApiException exception =
596         ApiExceptionFactory.createException(
597             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
598     mockService.addException(exception);
599 
600     try {
601       ListLocationsRequest request =
602           ListLocationsRequest.newBuilder()
603               .setName("projects/project-3664")
604               .setFilter("filter-1274492040")
605               .setPageSize(883849137)
606               .setPageToken("pageToken873572522")
607               .build();
608       client.listLocations(request);
609       Assert.fail("No exception raised");
610     } catch (InvalidArgumentException e) {
611       // Expected exception.
612     }
613   }
614 
615   @Test
getLocationTest()616   public void getLocationTest() throws Exception {
617     Location expectedResponse =
618         Location.newBuilder()
619             .setName("name3373707")
620             .setLocationId("locationId1541836720")
621             .setDisplayName("displayName1714148973")
622             .putAllLabels(new HashMap<String, String>())
623             .setMetadata(Any.newBuilder().build())
624             .build();
625     mockService.addResponse(expectedResponse);
626 
627     GetLocationRequest request =
628         GetLocationRequest.newBuilder()
629             .setName("projects/project-9062/locations/location-9062")
630             .build();
631 
632     Location actualResponse = client.getLocation(request);
633     Assert.assertEquals(expectedResponse, actualResponse);
634 
635     List<String> actualRequests = mockService.getRequestPaths();
636     Assert.assertEquals(1, actualRequests.size());
637 
638     String apiClientHeaderKey =
639         mockService
640             .getRequestHeaders()
641             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
642             .iterator()
643             .next();
644     Assert.assertTrue(
645         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
646             .matcher(apiClientHeaderKey)
647             .matches());
648   }
649 
650   @Test
getLocationExceptionTest()651   public void getLocationExceptionTest() throws Exception {
652     ApiException exception =
653         ApiExceptionFactory.createException(
654             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
655     mockService.addException(exception);
656 
657     try {
658       GetLocationRequest request =
659           GetLocationRequest.newBuilder()
660               .setName("projects/project-9062/locations/location-9062")
661               .build();
662       client.getLocation(request);
663       Assert.fail("No exception raised");
664     } catch (InvalidArgumentException e) {
665       // Expected exception.
666     }
667   }
668 }
669