• 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.batch.v1alpha;
18 
19 import static com.google.cloud.batch.v1alpha.BatchServiceClient.ListJobsPagedResponse;
20 import static com.google.cloud.batch.v1alpha.BatchServiceClient.ListLocationsPagedResponse;
21 import static com.google.cloud.batch.v1alpha.BatchServiceClient.ListTasksPagedResponse;
22 
23 import com.google.api.gax.core.NoCredentialsProvider;
24 import com.google.api.gax.httpjson.GaxHttpJsonProperties;
25 import com.google.api.gax.httpjson.testing.MockHttpService;
26 import com.google.api.gax.rpc.ApiClientHeaderProvider;
27 import com.google.api.gax.rpc.ApiException;
28 import com.google.api.gax.rpc.ApiExceptionFactory;
29 import com.google.api.gax.rpc.InvalidArgumentException;
30 import com.google.api.gax.rpc.StatusCode;
31 import com.google.api.gax.rpc.testing.FakeStatusCode;
32 import com.google.cloud.batch.v1alpha.stub.HttpJsonBatchServiceStub;
33 import com.google.cloud.location.GetLocationRequest;
34 import com.google.cloud.location.ListLocationsRequest;
35 import com.google.cloud.location.ListLocationsResponse;
36 import com.google.cloud.location.Location;
37 import com.google.common.collect.Lists;
38 import com.google.longrunning.Operation;
39 import com.google.protobuf.Any;
40 import com.google.protobuf.Empty;
41 import com.google.protobuf.Timestamp;
42 import java.io.IOException;
43 import java.util.ArrayList;
44 import java.util.Arrays;
45 import java.util.HashMap;
46 import java.util.List;
47 import java.util.concurrent.ExecutionException;
48 import javax.annotation.Generated;
49 import org.junit.After;
50 import org.junit.AfterClass;
51 import org.junit.Assert;
52 import org.junit.Before;
53 import org.junit.BeforeClass;
54 import org.junit.Test;
55 
56 @Generated("by gapic-generator-java")
57 public class BatchServiceClientHttpJsonTest {
58   private static MockHttpService mockService;
59   private static BatchServiceClient client;
60 
61   @BeforeClass
startStaticServer()62   public static void startStaticServer() throws IOException {
63     mockService =
64         new MockHttpService(
65             HttpJsonBatchServiceStub.getMethodDescriptors(),
66             BatchServiceSettings.getDefaultEndpoint());
67     BatchServiceSettings settings =
68         BatchServiceSettings.newHttpJsonBuilder()
69             .setTransportChannelProvider(
70                 BatchServiceSettings.defaultHttpJsonTransportProviderBuilder()
71                     .setHttpTransport(mockService)
72                     .build())
73             .setCredentialsProvider(NoCredentialsProvider.create())
74             .build();
75     client = BatchServiceClient.create(settings);
76   }
77 
78   @AfterClass
stopServer()79   public static void stopServer() {
80     client.close();
81   }
82 
83   @Before
setUp()84   public void setUp() {}
85 
86   @After
tearDown()87   public void tearDown() throws Exception {
88     mockService.reset();
89   }
90 
91   @Test
createJobTest()92   public void createJobTest() throws Exception {
93     Job expectedResponse =
94         Job.newBuilder()
95             .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString())
96             .setUid("uid115792")
97             .setPriority(-1165461084)
98             .addAllTaskGroups(new ArrayList<TaskGroup>())
99             .addAllDependencies(new ArrayList<JobDependency>())
100             .setAllocationPolicy(AllocationPolicy.newBuilder().build())
101             .putAllLabels(new HashMap<String, String>())
102             .setStatus(JobStatus.newBuilder().build())
103             .setNotification(JobNotification.newBuilder().build())
104             .setCreateTime(Timestamp.newBuilder().build())
105             .setUpdateTime(Timestamp.newBuilder().build())
106             .setLogsPolicy(LogsPolicy.newBuilder().build())
107             .addAllNotifications(new ArrayList<JobNotification>())
108             .build();
109     mockService.addResponse(expectedResponse);
110 
111     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
112     Job job = Job.newBuilder().build();
113     String jobId = "jobId101296568";
114 
115     Job actualResponse = client.createJob(parent, job, jobId);
116     Assert.assertEquals(expectedResponse, actualResponse);
117 
118     List<String> actualRequests = mockService.getRequestPaths();
119     Assert.assertEquals(1, actualRequests.size());
120 
121     String apiClientHeaderKey =
122         mockService
123             .getRequestHeaders()
124             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
125             .iterator()
126             .next();
127     Assert.assertTrue(
128         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
129             .matcher(apiClientHeaderKey)
130             .matches());
131   }
132 
133   @Test
createJobExceptionTest()134   public void createJobExceptionTest() throws Exception {
135     ApiException exception =
136         ApiExceptionFactory.createException(
137             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
138     mockService.addException(exception);
139 
140     try {
141       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
142       Job job = Job.newBuilder().build();
143       String jobId = "jobId101296568";
144       client.createJob(parent, job, jobId);
145       Assert.fail("No exception raised");
146     } catch (InvalidArgumentException e) {
147       // Expected exception.
148     }
149   }
150 
151   @Test
createJobTest2()152   public void createJobTest2() throws Exception {
153     Job expectedResponse =
154         Job.newBuilder()
155             .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString())
156             .setUid("uid115792")
157             .setPriority(-1165461084)
158             .addAllTaskGroups(new ArrayList<TaskGroup>())
159             .addAllDependencies(new ArrayList<JobDependency>())
160             .setAllocationPolicy(AllocationPolicy.newBuilder().build())
161             .putAllLabels(new HashMap<String, String>())
162             .setStatus(JobStatus.newBuilder().build())
163             .setNotification(JobNotification.newBuilder().build())
164             .setCreateTime(Timestamp.newBuilder().build())
165             .setUpdateTime(Timestamp.newBuilder().build())
166             .setLogsPolicy(LogsPolicy.newBuilder().build())
167             .addAllNotifications(new ArrayList<JobNotification>())
168             .build();
169     mockService.addResponse(expectedResponse);
170 
171     String parent = "projects/project-5833/locations/location-5833";
172     Job job = Job.newBuilder().build();
173     String jobId = "jobId101296568";
174 
175     Job actualResponse = client.createJob(parent, job, jobId);
176     Assert.assertEquals(expectedResponse, actualResponse);
177 
178     List<String> actualRequests = mockService.getRequestPaths();
179     Assert.assertEquals(1, actualRequests.size());
180 
181     String apiClientHeaderKey =
182         mockService
183             .getRequestHeaders()
184             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
185             .iterator()
186             .next();
187     Assert.assertTrue(
188         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
189             .matcher(apiClientHeaderKey)
190             .matches());
191   }
192 
193   @Test
createJobExceptionTest2()194   public void createJobExceptionTest2() throws Exception {
195     ApiException exception =
196         ApiExceptionFactory.createException(
197             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
198     mockService.addException(exception);
199 
200     try {
201       String parent = "projects/project-5833/locations/location-5833";
202       Job job = Job.newBuilder().build();
203       String jobId = "jobId101296568";
204       client.createJob(parent, job, jobId);
205       Assert.fail("No exception raised");
206     } catch (InvalidArgumentException e) {
207       // Expected exception.
208     }
209   }
210 
211   @Test
getJobTest()212   public void getJobTest() throws Exception {
213     Job expectedResponse =
214         Job.newBuilder()
215             .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString())
216             .setUid("uid115792")
217             .setPriority(-1165461084)
218             .addAllTaskGroups(new ArrayList<TaskGroup>())
219             .addAllDependencies(new ArrayList<JobDependency>())
220             .setAllocationPolicy(AllocationPolicy.newBuilder().build())
221             .putAllLabels(new HashMap<String, String>())
222             .setStatus(JobStatus.newBuilder().build())
223             .setNotification(JobNotification.newBuilder().build())
224             .setCreateTime(Timestamp.newBuilder().build())
225             .setUpdateTime(Timestamp.newBuilder().build())
226             .setLogsPolicy(LogsPolicy.newBuilder().build())
227             .addAllNotifications(new ArrayList<JobNotification>())
228             .build();
229     mockService.addResponse(expectedResponse);
230 
231     JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]");
232 
233     Job actualResponse = client.getJob(name);
234     Assert.assertEquals(expectedResponse, actualResponse);
235 
236     List<String> actualRequests = mockService.getRequestPaths();
237     Assert.assertEquals(1, actualRequests.size());
238 
239     String apiClientHeaderKey =
240         mockService
241             .getRequestHeaders()
242             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
243             .iterator()
244             .next();
245     Assert.assertTrue(
246         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
247             .matcher(apiClientHeaderKey)
248             .matches());
249   }
250 
251   @Test
getJobExceptionTest()252   public void getJobExceptionTest() throws Exception {
253     ApiException exception =
254         ApiExceptionFactory.createException(
255             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
256     mockService.addException(exception);
257 
258     try {
259       JobName name = JobName.of("[PROJECT]", "[LOCATION]", "[JOB]");
260       client.getJob(name);
261       Assert.fail("No exception raised");
262     } catch (InvalidArgumentException e) {
263       // Expected exception.
264     }
265   }
266 
267   @Test
getJobTest2()268   public void getJobTest2() throws Exception {
269     Job expectedResponse =
270         Job.newBuilder()
271             .setName(JobName.of("[PROJECT]", "[LOCATION]", "[JOB]").toString())
272             .setUid("uid115792")
273             .setPriority(-1165461084)
274             .addAllTaskGroups(new ArrayList<TaskGroup>())
275             .addAllDependencies(new ArrayList<JobDependency>())
276             .setAllocationPolicy(AllocationPolicy.newBuilder().build())
277             .putAllLabels(new HashMap<String, String>())
278             .setStatus(JobStatus.newBuilder().build())
279             .setNotification(JobNotification.newBuilder().build())
280             .setCreateTime(Timestamp.newBuilder().build())
281             .setUpdateTime(Timestamp.newBuilder().build())
282             .setLogsPolicy(LogsPolicy.newBuilder().build())
283             .addAllNotifications(new ArrayList<JobNotification>())
284             .build();
285     mockService.addResponse(expectedResponse);
286 
287     String name = "projects/project-3306/locations/location-3306/jobs/job-3306";
288 
289     Job actualResponse = client.getJob(name);
290     Assert.assertEquals(expectedResponse, actualResponse);
291 
292     List<String> actualRequests = mockService.getRequestPaths();
293     Assert.assertEquals(1, actualRequests.size());
294 
295     String apiClientHeaderKey =
296         mockService
297             .getRequestHeaders()
298             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
299             .iterator()
300             .next();
301     Assert.assertTrue(
302         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
303             .matcher(apiClientHeaderKey)
304             .matches());
305   }
306 
307   @Test
getJobExceptionTest2()308   public void getJobExceptionTest2() throws Exception {
309     ApiException exception =
310         ApiExceptionFactory.createException(
311             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
312     mockService.addException(exception);
313 
314     try {
315       String name = "projects/project-3306/locations/location-3306/jobs/job-3306";
316       client.getJob(name);
317       Assert.fail("No exception raised");
318     } catch (InvalidArgumentException e) {
319       // Expected exception.
320     }
321   }
322 
323   @Test
deleteJobTest()324   public void deleteJobTest() throws Exception {
325     Empty expectedResponse = Empty.newBuilder().build();
326     Operation resultOperation =
327         Operation.newBuilder()
328             .setName("deleteJobTest")
329             .setDone(true)
330             .setResponse(Any.pack(expectedResponse))
331             .build();
332     mockService.addResponse(resultOperation);
333 
334     String name = "projects/project-3306/locations/location-3306/jobs/job-3306";
335 
336     client.deleteJobAsync(name).get();
337 
338     List<String> actualRequests = mockService.getRequestPaths();
339     Assert.assertEquals(1, actualRequests.size());
340 
341     String apiClientHeaderKey =
342         mockService
343             .getRequestHeaders()
344             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
345             .iterator()
346             .next();
347     Assert.assertTrue(
348         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
349             .matcher(apiClientHeaderKey)
350             .matches());
351   }
352 
353   @Test
deleteJobExceptionTest()354   public void deleteJobExceptionTest() throws Exception {
355     ApiException exception =
356         ApiExceptionFactory.createException(
357             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
358     mockService.addException(exception);
359 
360     try {
361       String name = "projects/project-3306/locations/location-3306/jobs/job-3306";
362       client.deleteJobAsync(name).get();
363       Assert.fail("No exception raised");
364     } catch (ExecutionException e) {
365     }
366   }
367 
368   @Test
listJobsTest()369   public void listJobsTest() throws Exception {
370     Job responsesElement = Job.newBuilder().build();
371     ListJobsResponse expectedResponse =
372         ListJobsResponse.newBuilder()
373             .setNextPageToken("")
374             .addAllJobs(Arrays.asList(responsesElement))
375             .build();
376     mockService.addResponse(expectedResponse);
377 
378     String parent = "projects/project-5833/locations/location-5833";
379 
380     ListJobsPagedResponse pagedListResponse = client.listJobs(parent);
381 
382     List<Job> resources = Lists.newArrayList(pagedListResponse.iterateAll());
383 
384     Assert.assertEquals(1, resources.size());
385     Assert.assertEquals(expectedResponse.getJobsList().get(0), resources.get(0));
386 
387     List<String> actualRequests = mockService.getRequestPaths();
388     Assert.assertEquals(1, actualRequests.size());
389 
390     String apiClientHeaderKey =
391         mockService
392             .getRequestHeaders()
393             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
394             .iterator()
395             .next();
396     Assert.assertTrue(
397         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
398             .matcher(apiClientHeaderKey)
399             .matches());
400   }
401 
402   @Test
listJobsExceptionTest()403   public void listJobsExceptionTest() throws Exception {
404     ApiException exception =
405         ApiExceptionFactory.createException(
406             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
407     mockService.addException(exception);
408 
409     try {
410       String parent = "projects/project-5833/locations/location-5833";
411       client.listJobs(parent);
412       Assert.fail("No exception raised");
413     } catch (InvalidArgumentException e) {
414       // Expected exception.
415     }
416   }
417 
418   @Test
getTaskTest()419   public void getTaskTest() throws Exception {
420     Task expectedResponse =
421         Task.newBuilder()
422             .setName(
423                 TaskName.of("[PROJECT]", "[LOCATION]", "[JOB]", "[TASK_GROUP]", "[TASK]")
424                     .toString())
425             .setStatus(TaskStatus.newBuilder().build())
426             .build();
427     mockService.addResponse(expectedResponse);
428 
429     TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[JOB]", "[TASK_GROUP]", "[TASK]");
430 
431     Task actualResponse = client.getTask(name);
432     Assert.assertEquals(expectedResponse, actualResponse);
433 
434     List<String> actualRequests = mockService.getRequestPaths();
435     Assert.assertEquals(1, actualRequests.size());
436 
437     String apiClientHeaderKey =
438         mockService
439             .getRequestHeaders()
440             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
441             .iterator()
442             .next();
443     Assert.assertTrue(
444         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
445             .matcher(apiClientHeaderKey)
446             .matches());
447   }
448 
449   @Test
getTaskExceptionTest()450   public void getTaskExceptionTest() throws Exception {
451     ApiException exception =
452         ApiExceptionFactory.createException(
453             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
454     mockService.addException(exception);
455 
456     try {
457       TaskName name = TaskName.of("[PROJECT]", "[LOCATION]", "[JOB]", "[TASK_GROUP]", "[TASK]");
458       client.getTask(name);
459       Assert.fail("No exception raised");
460     } catch (InvalidArgumentException e) {
461       // Expected exception.
462     }
463   }
464 
465   @Test
getTaskTest2()466   public void getTaskTest2() throws Exception {
467     Task expectedResponse =
468         Task.newBuilder()
469             .setName(
470                 TaskName.of("[PROJECT]", "[LOCATION]", "[JOB]", "[TASK_GROUP]", "[TASK]")
471                     .toString())
472             .setStatus(TaskStatus.newBuilder().build())
473             .build();
474     mockService.addResponse(expectedResponse);
475 
476     String name =
477         "projects/project-5433/locations/location-5433/jobs/job-5433/taskGroups/taskGroup-5433/tasks/task-5433";
478 
479     Task actualResponse = client.getTask(name);
480     Assert.assertEquals(expectedResponse, actualResponse);
481 
482     List<String> actualRequests = mockService.getRequestPaths();
483     Assert.assertEquals(1, actualRequests.size());
484 
485     String apiClientHeaderKey =
486         mockService
487             .getRequestHeaders()
488             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
489             .iterator()
490             .next();
491     Assert.assertTrue(
492         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
493             .matcher(apiClientHeaderKey)
494             .matches());
495   }
496 
497   @Test
getTaskExceptionTest2()498   public void getTaskExceptionTest2() throws Exception {
499     ApiException exception =
500         ApiExceptionFactory.createException(
501             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
502     mockService.addException(exception);
503 
504     try {
505       String name =
506           "projects/project-5433/locations/location-5433/jobs/job-5433/taskGroups/taskGroup-5433/tasks/task-5433";
507       client.getTask(name);
508       Assert.fail("No exception raised");
509     } catch (InvalidArgumentException e) {
510       // Expected exception.
511     }
512   }
513 
514   @Test
listTasksTest()515   public void listTasksTest() throws Exception {
516     Task responsesElement = Task.newBuilder().build();
517     ListTasksResponse expectedResponse =
518         ListTasksResponse.newBuilder()
519             .setNextPageToken("")
520             .addAllTasks(Arrays.asList(responsesElement))
521             .build();
522     mockService.addResponse(expectedResponse);
523 
524     TaskGroupName parent = TaskGroupName.of("[PROJECT]", "[LOCATION]", "[JOB]", "[TASK_GROUP]");
525 
526     ListTasksPagedResponse pagedListResponse = client.listTasks(parent);
527 
528     List<Task> resources = Lists.newArrayList(pagedListResponse.iterateAll());
529 
530     Assert.assertEquals(1, resources.size());
531     Assert.assertEquals(expectedResponse.getTasksList().get(0), resources.get(0));
532 
533     List<String> actualRequests = mockService.getRequestPaths();
534     Assert.assertEquals(1, actualRequests.size());
535 
536     String apiClientHeaderKey =
537         mockService
538             .getRequestHeaders()
539             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
540             .iterator()
541             .next();
542     Assert.assertTrue(
543         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
544             .matcher(apiClientHeaderKey)
545             .matches());
546   }
547 
548   @Test
listTasksExceptionTest()549   public void listTasksExceptionTest() throws Exception {
550     ApiException exception =
551         ApiExceptionFactory.createException(
552             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
553     mockService.addException(exception);
554 
555     try {
556       TaskGroupName parent = TaskGroupName.of("[PROJECT]", "[LOCATION]", "[JOB]", "[TASK_GROUP]");
557       client.listTasks(parent);
558       Assert.fail("No exception raised");
559     } catch (InvalidArgumentException e) {
560       // Expected exception.
561     }
562   }
563 
564   @Test
listTasksTest2()565   public void listTasksTest2() throws Exception {
566     Task responsesElement = Task.newBuilder().build();
567     ListTasksResponse expectedResponse =
568         ListTasksResponse.newBuilder()
569             .setNextPageToken("")
570             .addAllTasks(Arrays.asList(responsesElement))
571             .build();
572     mockService.addResponse(expectedResponse);
573 
574     String parent =
575         "projects/project-6196/locations/location-6196/jobs/job-6196/taskGroups/taskGroup-6196";
576 
577     ListTasksPagedResponse pagedListResponse = client.listTasks(parent);
578 
579     List<Task> resources = Lists.newArrayList(pagedListResponse.iterateAll());
580 
581     Assert.assertEquals(1, resources.size());
582     Assert.assertEquals(expectedResponse.getTasksList().get(0), resources.get(0));
583 
584     List<String> actualRequests = mockService.getRequestPaths();
585     Assert.assertEquals(1, actualRequests.size());
586 
587     String apiClientHeaderKey =
588         mockService
589             .getRequestHeaders()
590             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
591             .iterator()
592             .next();
593     Assert.assertTrue(
594         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
595             .matcher(apiClientHeaderKey)
596             .matches());
597   }
598 
599   @Test
listTasksExceptionTest2()600   public void listTasksExceptionTest2() throws Exception {
601     ApiException exception =
602         ApiExceptionFactory.createException(
603             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
604     mockService.addException(exception);
605 
606     try {
607       String parent =
608           "projects/project-6196/locations/location-6196/jobs/job-6196/taskGroups/taskGroup-6196";
609       client.listTasks(parent);
610       Assert.fail("No exception raised");
611     } catch (InvalidArgumentException e) {
612       // Expected exception.
613     }
614   }
615 
616   @Test
listLocationsTest()617   public void listLocationsTest() throws Exception {
618     Location responsesElement = Location.newBuilder().build();
619     ListLocationsResponse expectedResponse =
620         ListLocationsResponse.newBuilder()
621             .setNextPageToken("")
622             .addAllLocations(Arrays.asList(responsesElement))
623             .build();
624     mockService.addResponse(expectedResponse);
625 
626     ListLocationsRequest request =
627         ListLocationsRequest.newBuilder()
628             .setName("projects/project-3664")
629             .setFilter("filter-1274492040")
630             .setPageSize(883849137)
631             .setPageToken("pageToken873572522")
632             .build();
633 
634     ListLocationsPagedResponse pagedListResponse = client.listLocations(request);
635 
636     List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll());
637 
638     Assert.assertEquals(1, resources.size());
639     Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0));
640 
641     List<String> actualRequests = mockService.getRequestPaths();
642     Assert.assertEquals(1, actualRequests.size());
643 
644     String apiClientHeaderKey =
645         mockService
646             .getRequestHeaders()
647             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
648             .iterator()
649             .next();
650     Assert.assertTrue(
651         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
652             .matcher(apiClientHeaderKey)
653             .matches());
654   }
655 
656   @Test
listLocationsExceptionTest()657   public void listLocationsExceptionTest() throws Exception {
658     ApiException exception =
659         ApiExceptionFactory.createException(
660             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
661     mockService.addException(exception);
662 
663     try {
664       ListLocationsRequest request =
665           ListLocationsRequest.newBuilder()
666               .setName("projects/project-3664")
667               .setFilter("filter-1274492040")
668               .setPageSize(883849137)
669               .setPageToken("pageToken873572522")
670               .build();
671       client.listLocations(request);
672       Assert.fail("No exception raised");
673     } catch (InvalidArgumentException e) {
674       // Expected exception.
675     }
676   }
677 
678   @Test
getLocationTest()679   public void getLocationTest() throws Exception {
680     Location expectedResponse =
681         Location.newBuilder()
682             .setName("name3373707")
683             .setLocationId("locationId1541836720")
684             .setDisplayName("displayName1714148973")
685             .putAllLabels(new HashMap<String, String>())
686             .setMetadata(Any.newBuilder().build())
687             .build();
688     mockService.addResponse(expectedResponse);
689 
690     GetLocationRequest request =
691         GetLocationRequest.newBuilder()
692             .setName("projects/project-9062/locations/location-9062")
693             .build();
694 
695     Location actualResponse = client.getLocation(request);
696     Assert.assertEquals(expectedResponse, actualResponse);
697 
698     List<String> actualRequests = mockService.getRequestPaths();
699     Assert.assertEquals(1, actualRequests.size());
700 
701     String apiClientHeaderKey =
702         mockService
703             .getRequestHeaders()
704             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
705             .iterator()
706             .next();
707     Assert.assertTrue(
708         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
709             .matcher(apiClientHeaderKey)
710             .matches());
711   }
712 
713   @Test
getLocationExceptionTest()714   public void getLocationExceptionTest() throws Exception {
715     ApiException exception =
716         ApiExceptionFactory.createException(
717             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
718     mockService.addException(exception);
719 
720     try {
721       GetLocationRequest request =
722           GetLocationRequest.newBuilder()
723               .setName("projects/project-9062/locations/location-9062")
724               .build();
725       client.getLocation(request);
726       Assert.fail("No exception raised");
727     } catch (InvalidArgumentException e) {
728       // Expected exception.
729     }
730   }
731 }
732