• 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.bigquery.reservation.v1;
18 
19 import static com.google.cloud.bigquery.reservation.v1.ReservationServiceClient.ListAssignmentsPagedResponse;
20 import static com.google.cloud.bigquery.reservation.v1.ReservationServiceClient.ListCapacityCommitmentsPagedResponse;
21 import static com.google.cloud.bigquery.reservation.v1.ReservationServiceClient.ListReservationsPagedResponse;
22 import static com.google.cloud.bigquery.reservation.v1.ReservationServiceClient.SearchAllAssignmentsPagedResponse;
23 import static com.google.cloud.bigquery.reservation.v1.ReservationServiceClient.SearchAssignmentsPagedResponse;
24 
25 import com.google.api.gax.core.NoCredentialsProvider;
26 import com.google.api.gax.httpjson.GaxHttpJsonProperties;
27 import com.google.api.gax.httpjson.testing.MockHttpService;
28 import com.google.api.gax.rpc.ApiClientHeaderProvider;
29 import com.google.api.gax.rpc.ApiException;
30 import com.google.api.gax.rpc.ApiExceptionFactory;
31 import com.google.api.gax.rpc.InvalidArgumentException;
32 import com.google.api.gax.rpc.StatusCode;
33 import com.google.api.gax.rpc.testing.FakeStatusCode;
34 import com.google.cloud.bigquery.reservation.v1.stub.HttpJsonReservationServiceStub;
35 import com.google.common.collect.Lists;
36 import com.google.protobuf.Empty;
37 import com.google.protobuf.FieldMask;
38 import com.google.protobuf.Timestamp;
39 import com.google.rpc.Status;
40 import java.io.IOException;
41 import java.util.ArrayList;
42 import java.util.Arrays;
43 import java.util.List;
44 import javax.annotation.Generated;
45 import org.junit.After;
46 import org.junit.AfterClass;
47 import org.junit.Assert;
48 import org.junit.Before;
49 import org.junit.BeforeClass;
50 import org.junit.Test;
51 
52 @Generated("by gapic-generator-java")
53 public class ReservationServiceClientHttpJsonTest {
54   private static MockHttpService mockService;
55   private static ReservationServiceClient client;
56 
57   @BeforeClass
startStaticServer()58   public static void startStaticServer() throws IOException {
59     mockService =
60         new MockHttpService(
61             HttpJsonReservationServiceStub.getMethodDescriptors(),
62             ReservationServiceSettings.getDefaultEndpoint());
63     ReservationServiceSettings settings =
64         ReservationServiceSettings.newHttpJsonBuilder()
65             .setTransportChannelProvider(
66                 ReservationServiceSettings.defaultHttpJsonTransportProviderBuilder()
67                     .setHttpTransport(mockService)
68                     .build())
69             .setCredentialsProvider(NoCredentialsProvider.create())
70             .build();
71     client = ReservationServiceClient.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
createReservationTest()88   public void createReservationTest() throws Exception {
89     Reservation expectedResponse =
90         Reservation.newBuilder()
91             .setName(ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]").toString())
92             .setSlotCapacity(-1516717605)
93             .setIgnoreIdleSlots(true)
94             .setAutoscale(Reservation.Autoscale.newBuilder().build())
95             .setConcurrency(1476186003)
96             .setCreationTime(Timestamp.newBuilder().build())
97             .setUpdateTime(Timestamp.newBuilder().build())
98             .setMultiRegionAuxiliary(true)
99             .setEdition(Edition.forNumber(0))
100             .build();
101     mockService.addResponse(expectedResponse);
102 
103     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
104     Reservation reservation = Reservation.newBuilder().build();
105     String reservationId = "reservationId1116965383";
106 
107     Reservation actualResponse = client.createReservation(parent, reservation, reservationId);
108     Assert.assertEquals(expectedResponse, actualResponse);
109 
110     List<String> actualRequests = mockService.getRequestPaths();
111     Assert.assertEquals(1, actualRequests.size());
112 
113     String apiClientHeaderKey =
114         mockService
115             .getRequestHeaders()
116             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
117             .iterator()
118             .next();
119     Assert.assertTrue(
120         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
121             .matcher(apiClientHeaderKey)
122             .matches());
123   }
124 
125   @Test
createReservationExceptionTest()126   public void createReservationExceptionTest() throws Exception {
127     ApiException exception =
128         ApiExceptionFactory.createException(
129             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
130     mockService.addException(exception);
131 
132     try {
133       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
134       Reservation reservation = Reservation.newBuilder().build();
135       String reservationId = "reservationId1116965383";
136       client.createReservation(parent, reservation, reservationId);
137       Assert.fail("No exception raised");
138     } catch (InvalidArgumentException e) {
139       // Expected exception.
140     }
141   }
142 
143   @Test
createReservationTest2()144   public void createReservationTest2() throws Exception {
145     Reservation expectedResponse =
146         Reservation.newBuilder()
147             .setName(ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]").toString())
148             .setSlotCapacity(-1516717605)
149             .setIgnoreIdleSlots(true)
150             .setAutoscale(Reservation.Autoscale.newBuilder().build())
151             .setConcurrency(1476186003)
152             .setCreationTime(Timestamp.newBuilder().build())
153             .setUpdateTime(Timestamp.newBuilder().build())
154             .setMultiRegionAuxiliary(true)
155             .setEdition(Edition.forNumber(0))
156             .build();
157     mockService.addResponse(expectedResponse);
158 
159     String parent = "projects/project-5833/locations/location-5833";
160     Reservation reservation = Reservation.newBuilder().build();
161     String reservationId = "reservationId1116965383";
162 
163     Reservation actualResponse = client.createReservation(parent, reservation, reservationId);
164     Assert.assertEquals(expectedResponse, actualResponse);
165 
166     List<String> actualRequests = mockService.getRequestPaths();
167     Assert.assertEquals(1, actualRequests.size());
168 
169     String apiClientHeaderKey =
170         mockService
171             .getRequestHeaders()
172             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
173             .iterator()
174             .next();
175     Assert.assertTrue(
176         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
177             .matcher(apiClientHeaderKey)
178             .matches());
179   }
180 
181   @Test
createReservationExceptionTest2()182   public void createReservationExceptionTest2() throws Exception {
183     ApiException exception =
184         ApiExceptionFactory.createException(
185             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
186     mockService.addException(exception);
187 
188     try {
189       String parent = "projects/project-5833/locations/location-5833";
190       Reservation reservation = Reservation.newBuilder().build();
191       String reservationId = "reservationId1116965383";
192       client.createReservation(parent, reservation, reservationId);
193       Assert.fail("No exception raised");
194     } catch (InvalidArgumentException e) {
195       // Expected exception.
196     }
197   }
198 
199   @Test
listReservationsTest()200   public void listReservationsTest() throws Exception {
201     Reservation responsesElement = Reservation.newBuilder().build();
202     ListReservationsResponse expectedResponse =
203         ListReservationsResponse.newBuilder()
204             .setNextPageToken("")
205             .addAllReservations(Arrays.asList(responsesElement))
206             .build();
207     mockService.addResponse(expectedResponse);
208 
209     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
210 
211     ListReservationsPagedResponse pagedListResponse = client.listReservations(parent);
212 
213     List<Reservation> resources = Lists.newArrayList(pagedListResponse.iterateAll());
214 
215     Assert.assertEquals(1, resources.size());
216     Assert.assertEquals(expectedResponse.getReservationsList().get(0), resources.get(0));
217 
218     List<String> actualRequests = mockService.getRequestPaths();
219     Assert.assertEquals(1, actualRequests.size());
220 
221     String apiClientHeaderKey =
222         mockService
223             .getRequestHeaders()
224             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
225             .iterator()
226             .next();
227     Assert.assertTrue(
228         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
229             .matcher(apiClientHeaderKey)
230             .matches());
231   }
232 
233   @Test
listReservationsExceptionTest()234   public void listReservationsExceptionTest() throws Exception {
235     ApiException exception =
236         ApiExceptionFactory.createException(
237             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
238     mockService.addException(exception);
239 
240     try {
241       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
242       client.listReservations(parent);
243       Assert.fail("No exception raised");
244     } catch (InvalidArgumentException e) {
245       // Expected exception.
246     }
247   }
248 
249   @Test
listReservationsTest2()250   public void listReservationsTest2() throws Exception {
251     Reservation responsesElement = Reservation.newBuilder().build();
252     ListReservationsResponse expectedResponse =
253         ListReservationsResponse.newBuilder()
254             .setNextPageToken("")
255             .addAllReservations(Arrays.asList(responsesElement))
256             .build();
257     mockService.addResponse(expectedResponse);
258 
259     String parent = "projects/project-5833/locations/location-5833";
260 
261     ListReservationsPagedResponse pagedListResponse = client.listReservations(parent);
262 
263     List<Reservation> resources = Lists.newArrayList(pagedListResponse.iterateAll());
264 
265     Assert.assertEquals(1, resources.size());
266     Assert.assertEquals(expectedResponse.getReservationsList().get(0), resources.get(0));
267 
268     List<String> actualRequests = mockService.getRequestPaths();
269     Assert.assertEquals(1, actualRequests.size());
270 
271     String apiClientHeaderKey =
272         mockService
273             .getRequestHeaders()
274             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
275             .iterator()
276             .next();
277     Assert.assertTrue(
278         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
279             .matcher(apiClientHeaderKey)
280             .matches());
281   }
282 
283   @Test
listReservationsExceptionTest2()284   public void listReservationsExceptionTest2() throws Exception {
285     ApiException exception =
286         ApiExceptionFactory.createException(
287             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
288     mockService.addException(exception);
289 
290     try {
291       String parent = "projects/project-5833/locations/location-5833";
292       client.listReservations(parent);
293       Assert.fail("No exception raised");
294     } catch (InvalidArgumentException e) {
295       // Expected exception.
296     }
297   }
298 
299   @Test
getReservationTest()300   public void getReservationTest() throws Exception {
301     Reservation expectedResponse =
302         Reservation.newBuilder()
303             .setName(ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]").toString())
304             .setSlotCapacity(-1516717605)
305             .setIgnoreIdleSlots(true)
306             .setAutoscale(Reservation.Autoscale.newBuilder().build())
307             .setConcurrency(1476186003)
308             .setCreationTime(Timestamp.newBuilder().build())
309             .setUpdateTime(Timestamp.newBuilder().build())
310             .setMultiRegionAuxiliary(true)
311             .setEdition(Edition.forNumber(0))
312             .build();
313     mockService.addResponse(expectedResponse);
314 
315     ReservationName name = ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]");
316 
317     Reservation actualResponse = client.getReservation(name);
318     Assert.assertEquals(expectedResponse, actualResponse);
319 
320     List<String> actualRequests = mockService.getRequestPaths();
321     Assert.assertEquals(1, actualRequests.size());
322 
323     String apiClientHeaderKey =
324         mockService
325             .getRequestHeaders()
326             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
327             .iterator()
328             .next();
329     Assert.assertTrue(
330         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
331             .matcher(apiClientHeaderKey)
332             .matches());
333   }
334 
335   @Test
getReservationExceptionTest()336   public void getReservationExceptionTest() throws Exception {
337     ApiException exception =
338         ApiExceptionFactory.createException(
339             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
340     mockService.addException(exception);
341 
342     try {
343       ReservationName name = ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]");
344       client.getReservation(name);
345       Assert.fail("No exception raised");
346     } catch (InvalidArgumentException e) {
347       // Expected exception.
348     }
349   }
350 
351   @Test
getReservationTest2()352   public void getReservationTest2() throws Exception {
353     Reservation expectedResponse =
354         Reservation.newBuilder()
355             .setName(ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]").toString())
356             .setSlotCapacity(-1516717605)
357             .setIgnoreIdleSlots(true)
358             .setAutoscale(Reservation.Autoscale.newBuilder().build())
359             .setConcurrency(1476186003)
360             .setCreationTime(Timestamp.newBuilder().build())
361             .setUpdateTime(Timestamp.newBuilder().build())
362             .setMultiRegionAuxiliary(true)
363             .setEdition(Edition.forNumber(0))
364             .build();
365     mockService.addResponse(expectedResponse);
366 
367     String name = "projects/project-313/locations/location-313/reservations/reservation-313";
368 
369     Reservation actualResponse = client.getReservation(name);
370     Assert.assertEquals(expectedResponse, actualResponse);
371 
372     List<String> actualRequests = mockService.getRequestPaths();
373     Assert.assertEquals(1, actualRequests.size());
374 
375     String apiClientHeaderKey =
376         mockService
377             .getRequestHeaders()
378             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
379             .iterator()
380             .next();
381     Assert.assertTrue(
382         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
383             .matcher(apiClientHeaderKey)
384             .matches());
385   }
386 
387   @Test
getReservationExceptionTest2()388   public void getReservationExceptionTest2() throws Exception {
389     ApiException exception =
390         ApiExceptionFactory.createException(
391             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
392     mockService.addException(exception);
393 
394     try {
395       String name = "projects/project-313/locations/location-313/reservations/reservation-313";
396       client.getReservation(name);
397       Assert.fail("No exception raised");
398     } catch (InvalidArgumentException e) {
399       // Expected exception.
400     }
401   }
402 
403   @Test
deleteReservationTest()404   public void deleteReservationTest() throws Exception {
405     Empty expectedResponse = Empty.newBuilder().build();
406     mockService.addResponse(expectedResponse);
407 
408     ReservationName name = ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]");
409 
410     client.deleteReservation(name);
411 
412     List<String> actualRequests = mockService.getRequestPaths();
413     Assert.assertEquals(1, actualRequests.size());
414 
415     String apiClientHeaderKey =
416         mockService
417             .getRequestHeaders()
418             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
419             .iterator()
420             .next();
421     Assert.assertTrue(
422         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
423             .matcher(apiClientHeaderKey)
424             .matches());
425   }
426 
427   @Test
deleteReservationExceptionTest()428   public void deleteReservationExceptionTest() throws Exception {
429     ApiException exception =
430         ApiExceptionFactory.createException(
431             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
432     mockService.addException(exception);
433 
434     try {
435       ReservationName name = ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]");
436       client.deleteReservation(name);
437       Assert.fail("No exception raised");
438     } catch (InvalidArgumentException e) {
439       // Expected exception.
440     }
441   }
442 
443   @Test
deleteReservationTest2()444   public void deleteReservationTest2() throws Exception {
445     Empty expectedResponse = Empty.newBuilder().build();
446     mockService.addResponse(expectedResponse);
447 
448     String name = "projects/project-313/locations/location-313/reservations/reservation-313";
449 
450     client.deleteReservation(name);
451 
452     List<String> actualRequests = mockService.getRequestPaths();
453     Assert.assertEquals(1, actualRequests.size());
454 
455     String apiClientHeaderKey =
456         mockService
457             .getRequestHeaders()
458             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
459             .iterator()
460             .next();
461     Assert.assertTrue(
462         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
463             .matcher(apiClientHeaderKey)
464             .matches());
465   }
466 
467   @Test
deleteReservationExceptionTest2()468   public void deleteReservationExceptionTest2() throws Exception {
469     ApiException exception =
470         ApiExceptionFactory.createException(
471             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
472     mockService.addException(exception);
473 
474     try {
475       String name = "projects/project-313/locations/location-313/reservations/reservation-313";
476       client.deleteReservation(name);
477       Assert.fail("No exception raised");
478     } catch (InvalidArgumentException e) {
479       // Expected exception.
480     }
481   }
482 
483   @Test
updateReservationTest()484   public void updateReservationTest() throws Exception {
485     Reservation expectedResponse =
486         Reservation.newBuilder()
487             .setName(ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]").toString())
488             .setSlotCapacity(-1516717605)
489             .setIgnoreIdleSlots(true)
490             .setAutoscale(Reservation.Autoscale.newBuilder().build())
491             .setConcurrency(1476186003)
492             .setCreationTime(Timestamp.newBuilder().build())
493             .setUpdateTime(Timestamp.newBuilder().build())
494             .setMultiRegionAuxiliary(true)
495             .setEdition(Edition.forNumber(0))
496             .build();
497     mockService.addResponse(expectedResponse);
498 
499     Reservation reservation =
500         Reservation.newBuilder()
501             .setName(ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]").toString())
502             .setSlotCapacity(-1516717605)
503             .setIgnoreIdleSlots(true)
504             .setAutoscale(Reservation.Autoscale.newBuilder().build())
505             .setConcurrency(1476186003)
506             .setCreationTime(Timestamp.newBuilder().build())
507             .setUpdateTime(Timestamp.newBuilder().build())
508             .setMultiRegionAuxiliary(true)
509             .setEdition(Edition.forNumber(0))
510             .build();
511     FieldMask updateMask = FieldMask.newBuilder().build();
512 
513     Reservation actualResponse = client.updateReservation(reservation, updateMask);
514     Assert.assertEquals(expectedResponse, actualResponse);
515 
516     List<String> actualRequests = mockService.getRequestPaths();
517     Assert.assertEquals(1, actualRequests.size());
518 
519     String apiClientHeaderKey =
520         mockService
521             .getRequestHeaders()
522             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
523             .iterator()
524             .next();
525     Assert.assertTrue(
526         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
527             .matcher(apiClientHeaderKey)
528             .matches());
529   }
530 
531   @Test
updateReservationExceptionTest()532   public void updateReservationExceptionTest() throws Exception {
533     ApiException exception =
534         ApiExceptionFactory.createException(
535             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
536     mockService.addException(exception);
537 
538     try {
539       Reservation reservation =
540           Reservation.newBuilder()
541               .setName(ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]").toString())
542               .setSlotCapacity(-1516717605)
543               .setIgnoreIdleSlots(true)
544               .setAutoscale(Reservation.Autoscale.newBuilder().build())
545               .setConcurrency(1476186003)
546               .setCreationTime(Timestamp.newBuilder().build())
547               .setUpdateTime(Timestamp.newBuilder().build())
548               .setMultiRegionAuxiliary(true)
549               .setEdition(Edition.forNumber(0))
550               .build();
551       FieldMask updateMask = FieldMask.newBuilder().build();
552       client.updateReservation(reservation, updateMask);
553       Assert.fail("No exception raised");
554     } catch (InvalidArgumentException e) {
555       // Expected exception.
556     }
557   }
558 
559   @Test
createCapacityCommitmentTest()560   public void createCapacityCommitmentTest() throws Exception {
561     CapacityCommitment expectedResponse =
562         CapacityCommitment.newBuilder()
563             .setName(
564                 CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]")
565                     .toString())
566             .setSlotCount(-191518834)
567             .setCommitmentStartTime(Timestamp.newBuilder().build())
568             .setCommitmentEndTime(Timestamp.newBuilder().build())
569             .setFailureStatus(Status.newBuilder().build())
570             .setMultiRegionAuxiliary(true)
571             .setEdition(Edition.forNumber(0))
572             .build();
573     mockService.addResponse(expectedResponse);
574 
575     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
576     CapacityCommitment capacityCommitment = CapacityCommitment.newBuilder().build();
577 
578     CapacityCommitment actualResponse = client.createCapacityCommitment(parent, capacityCommitment);
579     Assert.assertEquals(expectedResponse, actualResponse);
580 
581     List<String> actualRequests = mockService.getRequestPaths();
582     Assert.assertEquals(1, actualRequests.size());
583 
584     String apiClientHeaderKey =
585         mockService
586             .getRequestHeaders()
587             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
588             .iterator()
589             .next();
590     Assert.assertTrue(
591         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
592             .matcher(apiClientHeaderKey)
593             .matches());
594   }
595 
596   @Test
createCapacityCommitmentExceptionTest()597   public void createCapacityCommitmentExceptionTest() throws Exception {
598     ApiException exception =
599         ApiExceptionFactory.createException(
600             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
601     mockService.addException(exception);
602 
603     try {
604       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
605       CapacityCommitment capacityCommitment = CapacityCommitment.newBuilder().build();
606       client.createCapacityCommitment(parent, capacityCommitment);
607       Assert.fail("No exception raised");
608     } catch (InvalidArgumentException e) {
609       // Expected exception.
610     }
611   }
612 
613   @Test
createCapacityCommitmentTest2()614   public void createCapacityCommitmentTest2() throws Exception {
615     CapacityCommitment expectedResponse =
616         CapacityCommitment.newBuilder()
617             .setName(
618                 CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]")
619                     .toString())
620             .setSlotCount(-191518834)
621             .setCommitmentStartTime(Timestamp.newBuilder().build())
622             .setCommitmentEndTime(Timestamp.newBuilder().build())
623             .setFailureStatus(Status.newBuilder().build())
624             .setMultiRegionAuxiliary(true)
625             .setEdition(Edition.forNumber(0))
626             .build();
627     mockService.addResponse(expectedResponse);
628 
629     String parent = "projects/project-5833/locations/location-5833";
630     CapacityCommitment capacityCommitment = CapacityCommitment.newBuilder().build();
631 
632     CapacityCommitment actualResponse = client.createCapacityCommitment(parent, capacityCommitment);
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
createCapacityCommitmentExceptionTest2()651   public void createCapacityCommitmentExceptionTest2() 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       String parent = "projects/project-5833/locations/location-5833";
659       CapacityCommitment capacityCommitment = CapacityCommitment.newBuilder().build();
660       client.createCapacityCommitment(parent, capacityCommitment);
661       Assert.fail("No exception raised");
662     } catch (InvalidArgumentException e) {
663       // Expected exception.
664     }
665   }
666 
667   @Test
listCapacityCommitmentsTest()668   public void listCapacityCommitmentsTest() throws Exception {
669     CapacityCommitment responsesElement = CapacityCommitment.newBuilder().build();
670     ListCapacityCommitmentsResponse expectedResponse =
671         ListCapacityCommitmentsResponse.newBuilder()
672             .setNextPageToken("")
673             .addAllCapacityCommitments(Arrays.asList(responsesElement))
674             .build();
675     mockService.addResponse(expectedResponse);
676 
677     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
678 
679     ListCapacityCommitmentsPagedResponse pagedListResponse = client.listCapacityCommitments(parent);
680 
681     List<CapacityCommitment> resources = Lists.newArrayList(pagedListResponse.iterateAll());
682 
683     Assert.assertEquals(1, resources.size());
684     Assert.assertEquals(expectedResponse.getCapacityCommitmentsList().get(0), resources.get(0));
685 
686     List<String> actualRequests = mockService.getRequestPaths();
687     Assert.assertEquals(1, actualRequests.size());
688 
689     String apiClientHeaderKey =
690         mockService
691             .getRequestHeaders()
692             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
693             .iterator()
694             .next();
695     Assert.assertTrue(
696         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
697             .matcher(apiClientHeaderKey)
698             .matches());
699   }
700 
701   @Test
listCapacityCommitmentsExceptionTest()702   public void listCapacityCommitmentsExceptionTest() throws Exception {
703     ApiException exception =
704         ApiExceptionFactory.createException(
705             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
706     mockService.addException(exception);
707 
708     try {
709       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
710       client.listCapacityCommitments(parent);
711       Assert.fail("No exception raised");
712     } catch (InvalidArgumentException e) {
713       // Expected exception.
714     }
715   }
716 
717   @Test
listCapacityCommitmentsTest2()718   public void listCapacityCommitmentsTest2() throws Exception {
719     CapacityCommitment responsesElement = CapacityCommitment.newBuilder().build();
720     ListCapacityCommitmentsResponse expectedResponse =
721         ListCapacityCommitmentsResponse.newBuilder()
722             .setNextPageToken("")
723             .addAllCapacityCommitments(Arrays.asList(responsesElement))
724             .build();
725     mockService.addResponse(expectedResponse);
726 
727     String parent = "projects/project-5833/locations/location-5833";
728 
729     ListCapacityCommitmentsPagedResponse pagedListResponse = client.listCapacityCommitments(parent);
730 
731     List<CapacityCommitment> resources = Lists.newArrayList(pagedListResponse.iterateAll());
732 
733     Assert.assertEquals(1, resources.size());
734     Assert.assertEquals(expectedResponse.getCapacityCommitmentsList().get(0), resources.get(0));
735 
736     List<String> actualRequests = mockService.getRequestPaths();
737     Assert.assertEquals(1, actualRequests.size());
738 
739     String apiClientHeaderKey =
740         mockService
741             .getRequestHeaders()
742             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
743             .iterator()
744             .next();
745     Assert.assertTrue(
746         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
747             .matcher(apiClientHeaderKey)
748             .matches());
749   }
750 
751   @Test
listCapacityCommitmentsExceptionTest2()752   public void listCapacityCommitmentsExceptionTest2() throws Exception {
753     ApiException exception =
754         ApiExceptionFactory.createException(
755             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
756     mockService.addException(exception);
757 
758     try {
759       String parent = "projects/project-5833/locations/location-5833";
760       client.listCapacityCommitments(parent);
761       Assert.fail("No exception raised");
762     } catch (InvalidArgumentException e) {
763       // Expected exception.
764     }
765   }
766 
767   @Test
getCapacityCommitmentTest()768   public void getCapacityCommitmentTest() throws Exception {
769     CapacityCommitment expectedResponse =
770         CapacityCommitment.newBuilder()
771             .setName(
772                 CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]")
773                     .toString())
774             .setSlotCount(-191518834)
775             .setCommitmentStartTime(Timestamp.newBuilder().build())
776             .setCommitmentEndTime(Timestamp.newBuilder().build())
777             .setFailureStatus(Status.newBuilder().build())
778             .setMultiRegionAuxiliary(true)
779             .setEdition(Edition.forNumber(0))
780             .build();
781     mockService.addResponse(expectedResponse);
782 
783     CapacityCommitmentName name =
784         CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]");
785 
786     CapacityCommitment actualResponse = client.getCapacityCommitment(name);
787     Assert.assertEquals(expectedResponse, actualResponse);
788 
789     List<String> actualRequests = mockService.getRequestPaths();
790     Assert.assertEquals(1, actualRequests.size());
791 
792     String apiClientHeaderKey =
793         mockService
794             .getRequestHeaders()
795             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
796             .iterator()
797             .next();
798     Assert.assertTrue(
799         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
800             .matcher(apiClientHeaderKey)
801             .matches());
802   }
803 
804   @Test
getCapacityCommitmentExceptionTest()805   public void getCapacityCommitmentExceptionTest() throws Exception {
806     ApiException exception =
807         ApiExceptionFactory.createException(
808             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
809     mockService.addException(exception);
810 
811     try {
812       CapacityCommitmentName name =
813           CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]");
814       client.getCapacityCommitment(name);
815       Assert.fail("No exception raised");
816     } catch (InvalidArgumentException e) {
817       // Expected exception.
818     }
819   }
820 
821   @Test
getCapacityCommitmentTest2()822   public void getCapacityCommitmentTest2() throws Exception {
823     CapacityCommitment expectedResponse =
824         CapacityCommitment.newBuilder()
825             .setName(
826                 CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]")
827                     .toString())
828             .setSlotCount(-191518834)
829             .setCommitmentStartTime(Timestamp.newBuilder().build())
830             .setCommitmentEndTime(Timestamp.newBuilder().build())
831             .setFailureStatus(Status.newBuilder().build())
832             .setMultiRegionAuxiliary(true)
833             .setEdition(Edition.forNumber(0))
834             .build();
835     mockService.addResponse(expectedResponse);
836 
837     String name =
838         "projects/project-7354/locations/location-7354/capacityCommitments/capacityCommitment-7354";
839 
840     CapacityCommitment actualResponse = client.getCapacityCommitment(name);
841     Assert.assertEquals(expectedResponse, actualResponse);
842 
843     List<String> actualRequests = mockService.getRequestPaths();
844     Assert.assertEquals(1, actualRequests.size());
845 
846     String apiClientHeaderKey =
847         mockService
848             .getRequestHeaders()
849             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
850             .iterator()
851             .next();
852     Assert.assertTrue(
853         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
854             .matcher(apiClientHeaderKey)
855             .matches());
856   }
857 
858   @Test
getCapacityCommitmentExceptionTest2()859   public void getCapacityCommitmentExceptionTest2() throws Exception {
860     ApiException exception =
861         ApiExceptionFactory.createException(
862             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
863     mockService.addException(exception);
864 
865     try {
866       String name =
867           "projects/project-7354/locations/location-7354/capacityCommitments/capacityCommitment-7354";
868       client.getCapacityCommitment(name);
869       Assert.fail("No exception raised");
870     } catch (InvalidArgumentException e) {
871       // Expected exception.
872     }
873   }
874 
875   @Test
deleteCapacityCommitmentTest()876   public void deleteCapacityCommitmentTest() throws Exception {
877     Empty expectedResponse = Empty.newBuilder().build();
878     mockService.addResponse(expectedResponse);
879 
880     CapacityCommitmentName name =
881         CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]");
882 
883     client.deleteCapacityCommitment(name);
884 
885     List<String> actualRequests = mockService.getRequestPaths();
886     Assert.assertEquals(1, actualRequests.size());
887 
888     String apiClientHeaderKey =
889         mockService
890             .getRequestHeaders()
891             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
892             .iterator()
893             .next();
894     Assert.assertTrue(
895         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
896             .matcher(apiClientHeaderKey)
897             .matches());
898   }
899 
900   @Test
deleteCapacityCommitmentExceptionTest()901   public void deleteCapacityCommitmentExceptionTest() throws Exception {
902     ApiException exception =
903         ApiExceptionFactory.createException(
904             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
905     mockService.addException(exception);
906 
907     try {
908       CapacityCommitmentName name =
909           CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]");
910       client.deleteCapacityCommitment(name);
911       Assert.fail("No exception raised");
912     } catch (InvalidArgumentException e) {
913       // Expected exception.
914     }
915   }
916 
917   @Test
deleteCapacityCommitmentTest2()918   public void deleteCapacityCommitmentTest2() throws Exception {
919     Empty expectedResponse = Empty.newBuilder().build();
920     mockService.addResponse(expectedResponse);
921 
922     String name =
923         "projects/project-7354/locations/location-7354/capacityCommitments/capacityCommitment-7354";
924 
925     client.deleteCapacityCommitment(name);
926 
927     List<String> actualRequests = mockService.getRequestPaths();
928     Assert.assertEquals(1, actualRequests.size());
929 
930     String apiClientHeaderKey =
931         mockService
932             .getRequestHeaders()
933             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
934             .iterator()
935             .next();
936     Assert.assertTrue(
937         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
938             .matcher(apiClientHeaderKey)
939             .matches());
940   }
941 
942   @Test
deleteCapacityCommitmentExceptionTest2()943   public void deleteCapacityCommitmentExceptionTest2() throws Exception {
944     ApiException exception =
945         ApiExceptionFactory.createException(
946             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
947     mockService.addException(exception);
948 
949     try {
950       String name =
951           "projects/project-7354/locations/location-7354/capacityCommitments/capacityCommitment-7354";
952       client.deleteCapacityCommitment(name);
953       Assert.fail("No exception raised");
954     } catch (InvalidArgumentException e) {
955       // Expected exception.
956     }
957   }
958 
959   @Test
updateCapacityCommitmentTest()960   public void updateCapacityCommitmentTest() throws Exception {
961     CapacityCommitment expectedResponse =
962         CapacityCommitment.newBuilder()
963             .setName(
964                 CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]")
965                     .toString())
966             .setSlotCount(-191518834)
967             .setCommitmentStartTime(Timestamp.newBuilder().build())
968             .setCommitmentEndTime(Timestamp.newBuilder().build())
969             .setFailureStatus(Status.newBuilder().build())
970             .setMultiRegionAuxiliary(true)
971             .setEdition(Edition.forNumber(0))
972             .build();
973     mockService.addResponse(expectedResponse);
974 
975     CapacityCommitment capacityCommitment =
976         CapacityCommitment.newBuilder()
977             .setName(
978                 CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]")
979                     .toString())
980             .setSlotCount(-191518834)
981             .setCommitmentStartTime(Timestamp.newBuilder().build())
982             .setCommitmentEndTime(Timestamp.newBuilder().build())
983             .setFailureStatus(Status.newBuilder().build())
984             .setMultiRegionAuxiliary(true)
985             .setEdition(Edition.forNumber(0))
986             .build();
987     FieldMask updateMask = FieldMask.newBuilder().build();
988 
989     CapacityCommitment actualResponse =
990         client.updateCapacityCommitment(capacityCommitment, updateMask);
991     Assert.assertEquals(expectedResponse, actualResponse);
992 
993     List<String> actualRequests = mockService.getRequestPaths();
994     Assert.assertEquals(1, actualRequests.size());
995 
996     String apiClientHeaderKey =
997         mockService
998             .getRequestHeaders()
999             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1000             .iterator()
1001             .next();
1002     Assert.assertTrue(
1003         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1004             .matcher(apiClientHeaderKey)
1005             .matches());
1006   }
1007 
1008   @Test
updateCapacityCommitmentExceptionTest()1009   public void updateCapacityCommitmentExceptionTest() throws Exception {
1010     ApiException exception =
1011         ApiExceptionFactory.createException(
1012             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1013     mockService.addException(exception);
1014 
1015     try {
1016       CapacityCommitment capacityCommitment =
1017           CapacityCommitment.newBuilder()
1018               .setName(
1019                   CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]")
1020                       .toString())
1021               .setSlotCount(-191518834)
1022               .setCommitmentStartTime(Timestamp.newBuilder().build())
1023               .setCommitmentEndTime(Timestamp.newBuilder().build())
1024               .setFailureStatus(Status.newBuilder().build())
1025               .setMultiRegionAuxiliary(true)
1026               .setEdition(Edition.forNumber(0))
1027               .build();
1028       FieldMask updateMask = FieldMask.newBuilder().build();
1029       client.updateCapacityCommitment(capacityCommitment, updateMask);
1030       Assert.fail("No exception raised");
1031     } catch (InvalidArgumentException e) {
1032       // Expected exception.
1033     }
1034   }
1035 
1036   @Test
splitCapacityCommitmentTest()1037   public void splitCapacityCommitmentTest() throws Exception {
1038     SplitCapacityCommitmentResponse expectedResponse =
1039         SplitCapacityCommitmentResponse.newBuilder()
1040             .setFirst(CapacityCommitment.newBuilder().build())
1041             .setSecond(CapacityCommitment.newBuilder().build())
1042             .build();
1043     mockService.addResponse(expectedResponse);
1044 
1045     CapacityCommitmentName name =
1046         CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]");
1047     long slotCount = -191518834;
1048 
1049     SplitCapacityCommitmentResponse actualResponse =
1050         client.splitCapacityCommitment(name, slotCount);
1051     Assert.assertEquals(expectedResponse, actualResponse);
1052 
1053     List<String> actualRequests = mockService.getRequestPaths();
1054     Assert.assertEquals(1, actualRequests.size());
1055 
1056     String apiClientHeaderKey =
1057         mockService
1058             .getRequestHeaders()
1059             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1060             .iterator()
1061             .next();
1062     Assert.assertTrue(
1063         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1064             .matcher(apiClientHeaderKey)
1065             .matches());
1066   }
1067 
1068   @Test
splitCapacityCommitmentExceptionTest()1069   public void splitCapacityCommitmentExceptionTest() throws Exception {
1070     ApiException exception =
1071         ApiExceptionFactory.createException(
1072             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1073     mockService.addException(exception);
1074 
1075     try {
1076       CapacityCommitmentName name =
1077           CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]");
1078       long slotCount = -191518834;
1079       client.splitCapacityCommitment(name, slotCount);
1080       Assert.fail("No exception raised");
1081     } catch (InvalidArgumentException e) {
1082       // Expected exception.
1083     }
1084   }
1085 
1086   @Test
splitCapacityCommitmentTest2()1087   public void splitCapacityCommitmentTest2() throws Exception {
1088     SplitCapacityCommitmentResponse expectedResponse =
1089         SplitCapacityCommitmentResponse.newBuilder()
1090             .setFirst(CapacityCommitment.newBuilder().build())
1091             .setSecond(CapacityCommitment.newBuilder().build())
1092             .build();
1093     mockService.addResponse(expectedResponse);
1094 
1095     String name =
1096         "projects/project-7354/locations/location-7354/capacityCommitments/capacityCommitment-7354";
1097     long slotCount = -191518834;
1098 
1099     SplitCapacityCommitmentResponse actualResponse =
1100         client.splitCapacityCommitment(name, slotCount);
1101     Assert.assertEquals(expectedResponse, actualResponse);
1102 
1103     List<String> actualRequests = mockService.getRequestPaths();
1104     Assert.assertEquals(1, actualRequests.size());
1105 
1106     String apiClientHeaderKey =
1107         mockService
1108             .getRequestHeaders()
1109             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1110             .iterator()
1111             .next();
1112     Assert.assertTrue(
1113         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1114             .matcher(apiClientHeaderKey)
1115             .matches());
1116   }
1117 
1118   @Test
splitCapacityCommitmentExceptionTest2()1119   public void splitCapacityCommitmentExceptionTest2() throws Exception {
1120     ApiException exception =
1121         ApiExceptionFactory.createException(
1122             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1123     mockService.addException(exception);
1124 
1125     try {
1126       String name =
1127           "projects/project-7354/locations/location-7354/capacityCommitments/capacityCommitment-7354";
1128       long slotCount = -191518834;
1129       client.splitCapacityCommitment(name, slotCount);
1130       Assert.fail("No exception raised");
1131     } catch (InvalidArgumentException e) {
1132       // Expected exception.
1133     }
1134   }
1135 
1136   @Test
mergeCapacityCommitmentsTest()1137   public void mergeCapacityCommitmentsTest() throws Exception {
1138     CapacityCommitment expectedResponse =
1139         CapacityCommitment.newBuilder()
1140             .setName(
1141                 CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]")
1142                     .toString())
1143             .setSlotCount(-191518834)
1144             .setCommitmentStartTime(Timestamp.newBuilder().build())
1145             .setCommitmentEndTime(Timestamp.newBuilder().build())
1146             .setFailureStatus(Status.newBuilder().build())
1147             .setMultiRegionAuxiliary(true)
1148             .setEdition(Edition.forNumber(0))
1149             .build();
1150     mockService.addResponse(expectedResponse);
1151 
1152     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1153     List<String> capacityCommitmentIds = new ArrayList<>();
1154 
1155     CapacityCommitment actualResponse =
1156         client.mergeCapacityCommitments(parent, capacityCommitmentIds);
1157     Assert.assertEquals(expectedResponse, actualResponse);
1158 
1159     List<String> actualRequests = mockService.getRequestPaths();
1160     Assert.assertEquals(1, actualRequests.size());
1161 
1162     String apiClientHeaderKey =
1163         mockService
1164             .getRequestHeaders()
1165             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1166             .iterator()
1167             .next();
1168     Assert.assertTrue(
1169         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1170             .matcher(apiClientHeaderKey)
1171             .matches());
1172   }
1173 
1174   @Test
mergeCapacityCommitmentsExceptionTest()1175   public void mergeCapacityCommitmentsExceptionTest() throws Exception {
1176     ApiException exception =
1177         ApiExceptionFactory.createException(
1178             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1179     mockService.addException(exception);
1180 
1181     try {
1182       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1183       List<String> capacityCommitmentIds = new ArrayList<>();
1184       client.mergeCapacityCommitments(parent, capacityCommitmentIds);
1185       Assert.fail("No exception raised");
1186     } catch (InvalidArgumentException e) {
1187       // Expected exception.
1188     }
1189   }
1190 
1191   @Test
mergeCapacityCommitmentsTest2()1192   public void mergeCapacityCommitmentsTest2() throws Exception {
1193     CapacityCommitment expectedResponse =
1194         CapacityCommitment.newBuilder()
1195             .setName(
1196                 CapacityCommitmentName.of("[PROJECT]", "[LOCATION]", "[CAPACITY_COMMITMENT]")
1197                     .toString())
1198             .setSlotCount(-191518834)
1199             .setCommitmentStartTime(Timestamp.newBuilder().build())
1200             .setCommitmentEndTime(Timestamp.newBuilder().build())
1201             .setFailureStatus(Status.newBuilder().build())
1202             .setMultiRegionAuxiliary(true)
1203             .setEdition(Edition.forNumber(0))
1204             .build();
1205     mockService.addResponse(expectedResponse);
1206 
1207     String parent = "projects/project-5833/locations/location-5833";
1208     List<String> capacityCommitmentIds = new ArrayList<>();
1209 
1210     CapacityCommitment actualResponse =
1211         client.mergeCapacityCommitments(parent, capacityCommitmentIds);
1212     Assert.assertEquals(expectedResponse, actualResponse);
1213 
1214     List<String> actualRequests = mockService.getRequestPaths();
1215     Assert.assertEquals(1, actualRequests.size());
1216 
1217     String apiClientHeaderKey =
1218         mockService
1219             .getRequestHeaders()
1220             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1221             .iterator()
1222             .next();
1223     Assert.assertTrue(
1224         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1225             .matcher(apiClientHeaderKey)
1226             .matches());
1227   }
1228 
1229   @Test
mergeCapacityCommitmentsExceptionTest2()1230   public void mergeCapacityCommitmentsExceptionTest2() throws Exception {
1231     ApiException exception =
1232         ApiExceptionFactory.createException(
1233             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1234     mockService.addException(exception);
1235 
1236     try {
1237       String parent = "projects/project-5833/locations/location-5833";
1238       List<String> capacityCommitmentIds = new ArrayList<>();
1239       client.mergeCapacityCommitments(parent, capacityCommitmentIds);
1240       Assert.fail("No exception raised");
1241     } catch (InvalidArgumentException e) {
1242       // Expected exception.
1243     }
1244   }
1245 
1246   @Test
createAssignmentTest()1247   public void createAssignmentTest() throws Exception {
1248     Assignment expectedResponse =
1249         Assignment.newBuilder()
1250             .setName(
1251                 AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]")
1252                     .toString())
1253             .setAssignee("assignee-369881649")
1254             .build();
1255     mockService.addResponse(expectedResponse);
1256 
1257     ReservationName parent = ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]");
1258     Assignment assignment = Assignment.newBuilder().build();
1259 
1260     Assignment actualResponse = client.createAssignment(parent, assignment);
1261     Assert.assertEquals(expectedResponse, actualResponse);
1262 
1263     List<String> actualRequests = mockService.getRequestPaths();
1264     Assert.assertEquals(1, actualRequests.size());
1265 
1266     String apiClientHeaderKey =
1267         mockService
1268             .getRequestHeaders()
1269             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1270             .iterator()
1271             .next();
1272     Assert.assertTrue(
1273         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1274             .matcher(apiClientHeaderKey)
1275             .matches());
1276   }
1277 
1278   @Test
createAssignmentExceptionTest()1279   public void createAssignmentExceptionTest() throws Exception {
1280     ApiException exception =
1281         ApiExceptionFactory.createException(
1282             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1283     mockService.addException(exception);
1284 
1285     try {
1286       ReservationName parent = ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]");
1287       Assignment assignment = Assignment.newBuilder().build();
1288       client.createAssignment(parent, assignment);
1289       Assert.fail("No exception raised");
1290     } catch (InvalidArgumentException e) {
1291       // Expected exception.
1292     }
1293   }
1294 
1295   @Test
createAssignmentTest2()1296   public void createAssignmentTest2() throws Exception {
1297     Assignment expectedResponse =
1298         Assignment.newBuilder()
1299             .setName(
1300                 AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]")
1301                     .toString())
1302             .setAssignee("assignee-369881649")
1303             .build();
1304     mockService.addResponse(expectedResponse);
1305 
1306     String parent = "projects/project-4488/locations/location-4488/reservations/reservation-4488";
1307     Assignment assignment = Assignment.newBuilder().build();
1308 
1309     Assignment actualResponse = client.createAssignment(parent, assignment);
1310     Assert.assertEquals(expectedResponse, actualResponse);
1311 
1312     List<String> actualRequests = mockService.getRequestPaths();
1313     Assert.assertEquals(1, actualRequests.size());
1314 
1315     String apiClientHeaderKey =
1316         mockService
1317             .getRequestHeaders()
1318             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1319             .iterator()
1320             .next();
1321     Assert.assertTrue(
1322         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1323             .matcher(apiClientHeaderKey)
1324             .matches());
1325   }
1326 
1327   @Test
createAssignmentExceptionTest2()1328   public void createAssignmentExceptionTest2() throws Exception {
1329     ApiException exception =
1330         ApiExceptionFactory.createException(
1331             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1332     mockService.addException(exception);
1333 
1334     try {
1335       String parent = "projects/project-4488/locations/location-4488/reservations/reservation-4488";
1336       Assignment assignment = Assignment.newBuilder().build();
1337       client.createAssignment(parent, assignment);
1338       Assert.fail("No exception raised");
1339     } catch (InvalidArgumentException e) {
1340       // Expected exception.
1341     }
1342   }
1343 
1344   @Test
listAssignmentsTest()1345   public void listAssignmentsTest() throws Exception {
1346     Assignment responsesElement = Assignment.newBuilder().build();
1347     ListAssignmentsResponse expectedResponse =
1348         ListAssignmentsResponse.newBuilder()
1349             .setNextPageToken("")
1350             .addAllAssignments(Arrays.asList(responsesElement))
1351             .build();
1352     mockService.addResponse(expectedResponse);
1353 
1354     ReservationName parent = ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]");
1355 
1356     ListAssignmentsPagedResponse pagedListResponse = client.listAssignments(parent);
1357 
1358     List<Assignment> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1359 
1360     Assert.assertEquals(1, resources.size());
1361     Assert.assertEquals(expectedResponse.getAssignmentsList().get(0), resources.get(0));
1362 
1363     List<String> actualRequests = mockService.getRequestPaths();
1364     Assert.assertEquals(1, actualRequests.size());
1365 
1366     String apiClientHeaderKey =
1367         mockService
1368             .getRequestHeaders()
1369             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1370             .iterator()
1371             .next();
1372     Assert.assertTrue(
1373         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1374             .matcher(apiClientHeaderKey)
1375             .matches());
1376   }
1377 
1378   @Test
listAssignmentsExceptionTest()1379   public void listAssignmentsExceptionTest() throws Exception {
1380     ApiException exception =
1381         ApiExceptionFactory.createException(
1382             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1383     mockService.addException(exception);
1384 
1385     try {
1386       ReservationName parent = ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]");
1387       client.listAssignments(parent);
1388       Assert.fail("No exception raised");
1389     } catch (InvalidArgumentException e) {
1390       // Expected exception.
1391     }
1392   }
1393 
1394   @Test
listAssignmentsTest2()1395   public void listAssignmentsTest2() throws Exception {
1396     Assignment responsesElement = Assignment.newBuilder().build();
1397     ListAssignmentsResponse expectedResponse =
1398         ListAssignmentsResponse.newBuilder()
1399             .setNextPageToken("")
1400             .addAllAssignments(Arrays.asList(responsesElement))
1401             .build();
1402     mockService.addResponse(expectedResponse);
1403 
1404     String parent = "projects/project-4488/locations/location-4488/reservations/reservation-4488";
1405 
1406     ListAssignmentsPagedResponse pagedListResponse = client.listAssignments(parent);
1407 
1408     List<Assignment> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1409 
1410     Assert.assertEquals(1, resources.size());
1411     Assert.assertEquals(expectedResponse.getAssignmentsList().get(0), resources.get(0));
1412 
1413     List<String> actualRequests = mockService.getRequestPaths();
1414     Assert.assertEquals(1, actualRequests.size());
1415 
1416     String apiClientHeaderKey =
1417         mockService
1418             .getRequestHeaders()
1419             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1420             .iterator()
1421             .next();
1422     Assert.assertTrue(
1423         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1424             .matcher(apiClientHeaderKey)
1425             .matches());
1426   }
1427 
1428   @Test
listAssignmentsExceptionTest2()1429   public void listAssignmentsExceptionTest2() throws Exception {
1430     ApiException exception =
1431         ApiExceptionFactory.createException(
1432             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1433     mockService.addException(exception);
1434 
1435     try {
1436       String parent = "projects/project-4488/locations/location-4488/reservations/reservation-4488";
1437       client.listAssignments(parent);
1438       Assert.fail("No exception raised");
1439     } catch (InvalidArgumentException e) {
1440       // Expected exception.
1441     }
1442   }
1443 
1444   @Test
deleteAssignmentTest()1445   public void deleteAssignmentTest() throws Exception {
1446     Empty expectedResponse = Empty.newBuilder().build();
1447     mockService.addResponse(expectedResponse);
1448 
1449     AssignmentName name =
1450         AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]");
1451 
1452     client.deleteAssignment(name);
1453 
1454     List<String> actualRequests = mockService.getRequestPaths();
1455     Assert.assertEquals(1, actualRequests.size());
1456 
1457     String apiClientHeaderKey =
1458         mockService
1459             .getRequestHeaders()
1460             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1461             .iterator()
1462             .next();
1463     Assert.assertTrue(
1464         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1465             .matcher(apiClientHeaderKey)
1466             .matches());
1467   }
1468 
1469   @Test
deleteAssignmentExceptionTest()1470   public void deleteAssignmentExceptionTest() throws Exception {
1471     ApiException exception =
1472         ApiExceptionFactory.createException(
1473             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1474     mockService.addException(exception);
1475 
1476     try {
1477       AssignmentName name =
1478           AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]");
1479       client.deleteAssignment(name);
1480       Assert.fail("No exception raised");
1481     } catch (InvalidArgumentException e) {
1482       // Expected exception.
1483     }
1484   }
1485 
1486   @Test
deleteAssignmentTest2()1487   public void deleteAssignmentTest2() throws Exception {
1488     Empty expectedResponse = Empty.newBuilder().build();
1489     mockService.addResponse(expectedResponse);
1490 
1491     String name =
1492         "projects/project-2631/locations/location-2631/reservations/reservation-2631/assignments/assignment-2631";
1493 
1494     client.deleteAssignment(name);
1495 
1496     List<String> actualRequests = mockService.getRequestPaths();
1497     Assert.assertEquals(1, actualRequests.size());
1498 
1499     String apiClientHeaderKey =
1500         mockService
1501             .getRequestHeaders()
1502             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1503             .iterator()
1504             .next();
1505     Assert.assertTrue(
1506         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1507             .matcher(apiClientHeaderKey)
1508             .matches());
1509   }
1510 
1511   @Test
deleteAssignmentExceptionTest2()1512   public void deleteAssignmentExceptionTest2() throws Exception {
1513     ApiException exception =
1514         ApiExceptionFactory.createException(
1515             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1516     mockService.addException(exception);
1517 
1518     try {
1519       String name =
1520           "projects/project-2631/locations/location-2631/reservations/reservation-2631/assignments/assignment-2631";
1521       client.deleteAssignment(name);
1522       Assert.fail("No exception raised");
1523     } catch (InvalidArgumentException e) {
1524       // Expected exception.
1525     }
1526   }
1527 
1528   @Test
searchAssignmentsTest()1529   public void searchAssignmentsTest() throws Exception {
1530     Assignment responsesElement = Assignment.newBuilder().build();
1531     SearchAssignmentsResponse expectedResponse =
1532         SearchAssignmentsResponse.newBuilder()
1533             .setNextPageToken("")
1534             .addAllAssignments(Arrays.asList(responsesElement))
1535             .build();
1536     mockService.addResponse(expectedResponse);
1537 
1538     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1539     String query = "query107944136";
1540 
1541     SearchAssignmentsPagedResponse pagedListResponse = client.searchAssignments(parent, query);
1542 
1543     List<Assignment> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1544 
1545     Assert.assertEquals(1, resources.size());
1546     Assert.assertEquals(expectedResponse.getAssignmentsList().get(0), resources.get(0));
1547 
1548     List<String> actualRequests = mockService.getRequestPaths();
1549     Assert.assertEquals(1, actualRequests.size());
1550 
1551     String apiClientHeaderKey =
1552         mockService
1553             .getRequestHeaders()
1554             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1555             .iterator()
1556             .next();
1557     Assert.assertTrue(
1558         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1559             .matcher(apiClientHeaderKey)
1560             .matches());
1561   }
1562 
1563   @Test
searchAssignmentsExceptionTest()1564   public void searchAssignmentsExceptionTest() throws Exception {
1565     ApiException exception =
1566         ApiExceptionFactory.createException(
1567             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1568     mockService.addException(exception);
1569 
1570     try {
1571       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1572       String query = "query107944136";
1573       client.searchAssignments(parent, query);
1574       Assert.fail("No exception raised");
1575     } catch (InvalidArgumentException e) {
1576       // Expected exception.
1577     }
1578   }
1579 
1580   @Test
searchAssignmentsTest2()1581   public void searchAssignmentsTest2() throws Exception {
1582     Assignment responsesElement = Assignment.newBuilder().build();
1583     SearchAssignmentsResponse expectedResponse =
1584         SearchAssignmentsResponse.newBuilder()
1585             .setNextPageToken("")
1586             .addAllAssignments(Arrays.asList(responsesElement))
1587             .build();
1588     mockService.addResponse(expectedResponse);
1589 
1590     String parent = "projects/project-5833/locations/location-5833";
1591     String query = "query107944136";
1592 
1593     SearchAssignmentsPagedResponse pagedListResponse = client.searchAssignments(parent, query);
1594 
1595     List<Assignment> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1596 
1597     Assert.assertEquals(1, resources.size());
1598     Assert.assertEquals(expectedResponse.getAssignmentsList().get(0), resources.get(0));
1599 
1600     List<String> actualRequests = mockService.getRequestPaths();
1601     Assert.assertEquals(1, actualRequests.size());
1602 
1603     String apiClientHeaderKey =
1604         mockService
1605             .getRequestHeaders()
1606             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1607             .iterator()
1608             .next();
1609     Assert.assertTrue(
1610         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1611             .matcher(apiClientHeaderKey)
1612             .matches());
1613   }
1614 
1615   @Test
searchAssignmentsExceptionTest2()1616   public void searchAssignmentsExceptionTest2() throws Exception {
1617     ApiException exception =
1618         ApiExceptionFactory.createException(
1619             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1620     mockService.addException(exception);
1621 
1622     try {
1623       String parent = "projects/project-5833/locations/location-5833";
1624       String query = "query107944136";
1625       client.searchAssignments(parent, query);
1626       Assert.fail("No exception raised");
1627     } catch (InvalidArgumentException e) {
1628       // Expected exception.
1629     }
1630   }
1631 
1632   @Test
searchAllAssignmentsTest()1633   public void searchAllAssignmentsTest() throws Exception {
1634     Assignment responsesElement = Assignment.newBuilder().build();
1635     SearchAllAssignmentsResponse expectedResponse =
1636         SearchAllAssignmentsResponse.newBuilder()
1637             .setNextPageToken("")
1638             .addAllAssignments(Arrays.asList(responsesElement))
1639             .build();
1640     mockService.addResponse(expectedResponse);
1641 
1642     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1643     String query = "query107944136";
1644 
1645     SearchAllAssignmentsPagedResponse pagedListResponse =
1646         client.searchAllAssignments(parent, query);
1647 
1648     List<Assignment> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1649 
1650     Assert.assertEquals(1, resources.size());
1651     Assert.assertEquals(expectedResponse.getAssignmentsList().get(0), resources.get(0));
1652 
1653     List<String> actualRequests = mockService.getRequestPaths();
1654     Assert.assertEquals(1, actualRequests.size());
1655 
1656     String apiClientHeaderKey =
1657         mockService
1658             .getRequestHeaders()
1659             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1660             .iterator()
1661             .next();
1662     Assert.assertTrue(
1663         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1664             .matcher(apiClientHeaderKey)
1665             .matches());
1666   }
1667 
1668   @Test
searchAllAssignmentsExceptionTest()1669   public void searchAllAssignmentsExceptionTest() throws Exception {
1670     ApiException exception =
1671         ApiExceptionFactory.createException(
1672             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1673     mockService.addException(exception);
1674 
1675     try {
1676       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
1677       String query = "query107944136";
1678       client.searchAllAssignments(parent, query);
1679       Assert.fail("No exception raised");
1680     } catch (InvalidArgumentException e) {
1681       // Expected exception.
1682     }
1683   }
1684 
1685   @Test
searchAllAssignmentsTest2()1686   public void searchAllAssignmentsTest2() throws Exception {
1687     Assignment responsesElement = Assignment.newBuilder().build();
1688     SearchAllAssignmentsResponse expectedResponse =
1689         SearchAllAssignmentsResponse.newBuilder()
1690             .setNextPageToken("")
1691             .addAllAssignments(Arrays.asList(responsesElement))
1692             .build();
1693     mockService.addResponse(expectedResponse);
1694 
1695     String parent = "projects/project-5833/locations/location-5833";
1696     String query = "query107944136";
1697 
1698     SearchAllAssignmentsPagedResponse pagedListResponse =
1699         client.searchAllAssignments(parent, query);
1700 
1701     List<Assignment> resources = Lists.newArrayList(pagedListResponse.iterateAll());
1702 
1703     Assert.assertEquals(1, resources.size());
1704     Assert.assertEquals(expectedResponse.getAssignmentsList().get(0), resources.get(0));
1705 
1706     List<String> actualRequests = mockService.getRequestPaths();
1707     Assert.assertEquals(1, actualRequests.size());
1708 
1709     String apiClientHeaderKey =
1710         mockService
1711             .getRequestHeaders()
1712             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1713             .iterator()
1714             .next();
1715     Assert.assertTrue(
1716         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1717             .matcher(apiClientHeaderKey)
1718             .matches());
1719   }
1720 
1721   @Test
searchAllAssignmentsExceptionTest2()1722   public void searchAllAssignmentsExceptionTest2() throws Exception {
1723     ApiException exception =
1724         ApiExceptionFactory.createException(
1725             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1726     mockService.addException(exception);
1727 
1728     try {
1729       String parent = "projects/project-5833/locations/location-5833";
1730       String query = "query107944136";
1731       client.searchAllAssignments(parent, query);
1732       Assert.fail("No exception raised");
1733     } catch (InvalidArgumentException e) {
1734       // Expected exception.
1735     }
1736   }
1737 
1738   @Test
moveAssignmentTest()1739   public void moveAssignmentTest() throws Exception {
1740     Assignment expectedResponse =
1741         Assignment.newBuilder()
1742             .setName(
1743                 AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]")
1744                     .toString())
1745             .setAssignee("assignee-369881649")
1746             .build();
1747     mockService.addResponse(expectedResponse);
1748 
1749     AssignmentName name =
1750         AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]");
1751     ReservationName destinationId = ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]");
1752 
1753     Assignment actualResponse = client.moveAssignment(name, destinationId);
1754     Assert.assertEquals(expectedResponse, actualResponse);
1755 
1756     List<String> actualRequests = mockService.getRequestPaths();
1757     Assert.assertEquals(1, actualRequests.size());
1758 
1759     String apiClientHeaderKey =
1760         mockService
1761             .getRequestHeaders()
1762             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1763             .iterator()
1764             .next();
1765     Assert.assertTrue(
1766         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1767             .matcher(apiClientHeaderKey)
1768             .matches());
1769   }
1770 
1771   @Test
moveAssignmentExceptionTest()1772   public void moveAssignmentExceptionTest() throws Exception {
1773     ApiException exception =
1774         ApiExceptionFactory.createException(
1775             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1776     mockService.addException(exception);
1777 
1778     try {
1779       AssignmentName name =
1780           AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]");
1781       ReservationName destinationId =
1782           ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]");
1783       client.moveAssignment(name, destinationId);
1784       Assert.fail("No exception raised");
1785     } catch (InvalidArgumentException e) {
1786       // Expected exception.
1787     }
1788   }
1789 
1790   @Test
moveAssignmentTest2()1791   public void moveAssignmentTest2() throws Exception {
1792     Assignment expectedResponse =
1793         Assignment.newBuilder()
1794             .setName(
1795                 AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]")
1796                     .toString())
1797             .setAssignee("assignee-369881649")
1798             .build();
1799     mockService.addResponse(expectedResponse);
1800 
1801     AssignmentName name =
1802         AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]");
1803     String destinationId = "destinationId306545097";
1804 
1805     Assignment actualResponse = client.moveAssignment(name, destinationId);
1806     Assert.assertEquals(expectedResponse, actualResponse);
1807 
1808     List<String> actualRequests = mockService.getRequestPaths();
1809     Assert.assertEquals(1, actualRequests.size());
1810 
1811     String apiClientHeaderKey =
1812         mockService
1813             .getRequestHeaders()
1814             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1815             .iterator()
1816             .next();
1817     Assert.assertTrue(
1818         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1819             .matcher(apiClientHeaderKey)
1820             .matches());
1821   }
1822 
1823   @Test
moveAssignmentExceptionTest2()1824   public void moveAssignmentExceptionTest2() throws Exception {
1825     ApiException exception =
1826         ApiExceptionFactory.createException(
1827             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1828     mockService.addException(exception);
1829 
1830     try {
1831       AssignmentName name =
1832           AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]");
1833       String destinationId = "destinationId306545097";
1834       client.moveAssignment(name, destinationId);
1835       Assert.fail("No exception raised");
1836     } catch (InvalidArgumentException e) {
1837       // Expected exception.
1838     }
1839   }
1840 
1841   @Test
moveAssignmentTest3()1842   public void moveAssignmentTest3() throws Exception {
1843     Assignment expectedResponse =
1844         Assignment.newBuilder()
1845             .setName(
1846                 AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]")
1847                     .toString())
1848             .setAssignee("assignee-369881649")
1849             .build();
1850     mockService.addResponse(expectedResponse);
1851 
1852     String name =
1853         "projects/project-2631/locations/location-2631/reservations/reservation-2631/assignments/assignment-2631";
1854     ReservationName destinationId = ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]");
1855 
1856     Assignment actualResponse = client.moveAssignment(name, destinationId);
1857     Assert.assertEquals(expectedResponse, actualResponse);
1858 
1859     List<String> actualRequests = mockService.getRequestPaths();
1860     Assert.assertEquals(1, actualRequests.size());
1861 
1862     String apiClientHeaderKey =
1863         mockService
1864             .getRequestHeaders()
1865             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1866             .iterator()
1867             .next();
1868     Assert.assertTrue(
1869         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1870             .matcher(apiClientHeaderKey)
1871             .matches());
1872   }
1873 
1874   @Test
moveAssignmentExceptionTest3()1875   public void moveAssignmentExceptionTest3() throws Exception {
1876     ApiException exception =
1877         ApiExceptionFactory.createException(
1878             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1879     mockService.addException(exception);
1880 
1881     try {
1882       String name =
1883           "projects/project-2631/locations/location-2631/reservations/reservation-2631/assignments/assignment-2631";
1884       ReservationName destinationId =
1885           ReservationName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]");
1886       client.moveAssignment(name, destinationId);
1887       Assert.fail("No exception raised");
1888     } catch (InvalidArgumentException e) {
1889       // Expected exception.
1890     }
1891   }
1892 
1893   @Test
moveAssignmentTest4()1894   public void moveAssignmentTest4() throws Exception {
1895     Assignment expectedResponse =
1896         Assignment.newBuilder()
1897             .setName(
1898                 AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]")
1899                     .toString())
1900             .setAssignee("assignee-369881649")
1901             .build();
1902     mockService.addResponse(expectedResponse);
1903 
1904     String name =
1905         "projects/project-2631/locations/location-2631/reservations/reservation-2631/assignments/assignment-2631";
1906     String destinationId = "destinationId306545097";
1907 
1908     Assignment actualResponse = client.moveAssignment(name, destinationId);
1909     Assert.assertEquals(expectedResponse, actualResponse);
1910 
1911     List<String> actualRequests = mockService.getRequestPaths();
1912     Assert.assertEquals(1, actualRequests.size());
1913 
1914     String apiClientHeaderKey =
1915         mockService
1916             .getRequestHeaders()
1917             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1918             .iterator()
1919             .next();
1920     Assert.assertTrue(
1921         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1922             .matcher(apiClientHeaderKey)
1923             .matches());
1924   }
1925 
1926   @Test
moveAssignmentExceptionTest4()1927   public void moveAssignmentExceptionTest4() throws Exception {
1928     ApiException exception =
1929         ApiExceptionFactory.createException(
1930             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1931     mockService.addException(exception);
1932 
1933     try {
1934       String name =
1935           "projects/project-2631/locations/location-2631/reservations/reservation-2631/assignments/assignment-2631";
1936       String destinationId = "destinationId306545097";
1937       client.moveAssignment(name, destinationId);
1938       Assert.fail("No exception raised");
1939     } catch (InvalidArgumentException e) {
1940       // Expected exception.
1941     }
1942   }
1943 
1944   @Test
updateAssignmentTest()1945   public void updateAssignmentTest() throws Exception {
1946     Assignment expectedResponse =
1947         Assignment.newBuilder()
1948             .setName(
1949                 AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]")
1950                     .toString())
1951             .setAssignee("assignee-369881649")
1952             .build();
1953     mockService.addResponse(expectedResponse);
1954 
1955     Assignment assignment =
1956         Assignment.newBuilder()
1957             .setName(
1958                 AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]")
1959                     .toString())
1960             .setAssignee("assignee-369881649")
1961             .build();
1962     FieldMask updateMask = FieldMask.newBuilder().build();
1963 
1964     Assignment actualResponse = client.updateAssignment(assignment, updateMask);
1965     Assert.assertEquals(expectedResponse, actualResponse);
1966 
1967     List<String> actualRequests = mockService.getRequestPaths();
1968     Assert.assertEquals(1, actualRequests.size());
1969 
1970     String apiClientHeaderKey =
1971         mockService
1972             .getRequestHeaders()
1973             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
1974             .iterator()
1975             .next();
1976     Assert.assertTrue(
1977         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
1978             .matcher(apiClientHeaderKey)
1979             .matches());
1980   }
1981 
1982   @Test
updateAssignmentExceptionTest()1983   public void updateAssignmentExceptionTest() throws Exception {
1984     ApiException exception =
1985         ApiExceptionFactory.createException(
1986             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
1987     mockService.addException(exception);
1988 
1989     try {
1990       Assignment assignment =
1991           Assignment.newBuilder()
1992               .setName(
1993                   AssignmentName.of("[PROJECT]", "[LOCATION]", "[RESERVATION]", "[ASSIGNMENT]")
1994                       .toString())
1995               .setAssignee("assignee-369881649")
1996               .build();
1997       FieldMask updateMask = FieldMask.newBuilder().build();
1998       client.updateAssignment(assignment, updateMask);
1999       Assert.fail("No exception raised");
2000     } catch (InvalidArgumentException e) {
2001       // Expected exception.
2002     }
2003   }
2004 
2005   @Test
getBiReservationTest()2006   public void getBiReservationTest() throws Exception {
2007     BiReservation expectedResponse =
2008         BiReservation.newBuilder()
2009             .setName(BiReservationName.of("[PROJECT]", "[LOCATION]").toString())
2010             .setUpdateTime(Timestamp.newBuilder().build())
2011             .setSize(3530753)
2012             .addAllPreferredTables(new ArrayList<TableReference>())
2013             .build();
2014     mockService.addResponse(expectedResponse);
2015 
2016     BiReservationName name = BiReservationName.of("[PROJECT]", "[LOCATION]");
2017 
2018     BiReservation actualResponse = client.getBiReservation(name);
2019     Assert.assertEquals(expectedResponse, actualResponse);
2020 
2021     List<String> actualRequests = mockService.getRequestPaths();
2022     Assert.assertEquals(1, actualRequests.size());
2023 
2024     String apiClientHeaderKey =
2025         mockService
2026             .getRequestHeaders()
2027             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2028             .iterator()
2029             .next();
2030     Assert.assertTrue(
2031         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2032             .matcher(apiClientHeaderKey)
2033             .matches());
2034   }
2035 
2036   @Test
getBiReservationExceptionTest()2037   public void getBiReservationExceptionTest() throws Exception {
2038     ApiException exception =
2039         ApiExceptionFactory.createException(
2040             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2041     mockService.addException(exception);
2042 
2043     try {
2044       BiReservationName name = BiReservationName.of("[PROJECT]", "[LOCATION]");
2045       client.getBiReservation(name);
2046       Assert.fail("No exception raised");
2047     } catch (InvalidArgumentException e) {
2048       // Expected exception.
2049     }
2050   }
2051 
2052   @Test
getBiReservationTest2()2053   public void getBiReservationTest2() throws Exception {
2054     BiReservation expectedResponse =
2055         BiReservation.newBuilder()
2056             .setName(BiReservationName.of("[PROJECT]", "[LOCATION]").toString())
2057             .setUpdateTime(Timestamp.newBuilder().build())
2058             .setSize(3530753)
2059             .addAllPreferredTables(new ArrayList<TableReference>())
2060             .build();
2061     mockService.addResponse(expectedResponse);
2062 
2063     String name = "projects/project-4752/locations/location-4752/biReservation";
2064 
2065     BiReservation actualResponse = client.getBiReservation(name);
2066     Assert.assertEquals(expectedResponse, actualResponse);
2067 
2068     List<String> actualRequests = mockService.getRequestPaths();
2069     Assert.assertEquals(1, actualRequests.size());
2070 
2071     String apiClientHeaderKey =
2072         mockService
2073             .getRequestHeaders()
2074             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2075             .iterator()
2076             .next();
2077     Assert.assertTrue(
2078         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2079             .matcher(apiClientHeaderKey)
2080             .matches());
2081   }
2082 
2083   @Test
getBiReservationExceptionTest2()2084   public void getBiReservationExceptionTest2() throws Exception {
2085     ApiException exception =
2086         ApiExceptionFactory.createException(
2087             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2088     mockService.addException(exception);
2089 
2090     try {
2091       String name = "projects/project-4752/locations/location-4752/biReservation";
2092       client.getBiReservation(name);
2093       Assert.fail("No exception raised");
2094     } catch (InvalidArgumentException e) {
2095       // Expected exception.
2096     }
2097   }
2098 
2099   @Test
updateBiReservationTest()2100   public void updateBiReservationTest() throws Exception {
2101     BiReservation expectedResponse =
2102         BiReservation.newBuilder()
2103             .setName(BiReservationName.of("[PROJECT]", "[LOCATION]").toString())
2104             .setUpdateTime(Timestamp.newBuilder().build())
2105             .setSize(3530753)
2106             .addAllPreferredTables(new ArrayList<TableReference>())
2107             .build();
2108     mockService.addResponse(expectedResponse);
2109 
2110     BiReservation biReservation =
2111         BiReservation.newBuilder()
2112             .setName(BiReservationName.of("[PROJECT]", "[LOCATION]").toString())
2113             .setUpdateTime(Timestamp.newBuilder().build())
2114             .setSize(3530753)
2115             .addAllPreferredTables(new ArrayList<TableReference>())
2116             .build();
2117     FieldMask updateMask = FieldMask.newBuilder().build();
2118 
2119     BiReservation actualResponse = client.updateBiReservation(biReservation, updateMask);
2120     Assert.assertEquals(expectedResponse, actualResponse);
2121 
2122     List<String> actualRequests = mockService.getRequestPaths();
2123     Assert.assertEquals(1, actualRequests.size());
2124 
2125     String apiClientHeaderKey =
2126         mockService
2127             .getRequestHeaders()
2128             .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
2129             .iterator()
2130             .next();
2131     Assert.assertTrue(
2132         GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
2133             .matcher(apiClientHeaderKey)
2134             .matches());
2135   }
2136 
2137   @Test
updateBiReservationExceptionTest()2138   public void updateBiReservationExceptionTest() throws Exception {
2139     ApiException exception =
2140         ApiExceptionFactory.createException(
2141             new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
2142     mockService.addException(exception);
2143 
2144     try {
2145       BiReservation biReservation =
2146           BiReservation.newBuilder()
2147               .setName(BiReservationName.of("[PROJECT]", "[LOCATION]").toString())
2148               .setUpdateTime(Timestamp.newBuilder().build())
2149               .setSize(3530753)
2150               .addAllPreferredTables(new ArrayList<TableReference>())
2151               .build();
2152       FieldMask updateMask = FieldMask.newBuilder().build();
2153       client.updateBiReservation(biReservation, updateMask);
2154       Assert.fail("No exception raised");
2155     } catch (InvalidArgumentException e) {
2156       // Expected exception.
2157     }
2158   }
2159 }
2160