• 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.beyondcorp.appgateways.v1;
18 
19 import static com.google.cloud.beyondcorp.appgateways.v1.AppGatewaysServiceClient.ListAppGatewaysPagedResponse;
20 import static com.google.cloud.beyondcorp.appgateways.v1.AppGatewaysServiceClient.ListLocationsPagedResponse;
21 
22 import com.google.api.gax.core.NoCredentialsProvider;
23 import com.google.api.gax.grpc.GaxGrpcProperties;
24 import com.google.api.gax.grpc.testing.LocalChannelProvider;
25 import com.google.api.gax.grpc.testing.MockGrpcService;
26 import com.google.api.gax.grpc.testing.MockServiceHelper;
27 import com.google.api.gax.rpc.ApiClientHeaderProvider;
28 import com.google.api.gax.rpc.InvalidArgumentException;
29 import com.google.api.gax.rpc.StatusCode;
30 import com.google.cloud.location.GetLocationRequest;
31 import com.google.cloud.location.ListLocationsRequest;
32 import com.google.cloud.location.ListLocationsResponse;
33 import com.google.cloud.location.Location;
34 import com.google.common.collect.Lists;
35 import com.google.iam.v1.AuditConfig;
36 import com.google.iam.v1.Binding;
37 import com.google.iam.v1.GetIamPolicyRequest;
38 import com.google.iam.v1.GetPolicyOptions;
39 import com.google.iam.v1.Policy;
40 import com.google.iam.v1.SetIamPolicyRequest;
41 import com.google.iam.v1.TestIamPermissionsRequest;
42 import com.google.iam.v1.TestIamPermissionsResponse;
43 import com.google.longrunning.Operation;
44 import com.google.protobuf.AbstractMessage;
45 import com.google.protobuf.Any;
46 import com.google.protobuf.ByteString;
47 import com.google.protobuf.Empty;
48 import com.google.protobuf.FieldMask;
49 import com.google.protobuf.Timestamp;
50 import io.grpc.StatusRuntimeException;
51 import java.io.IOException;
52 import java.util.ArrayList;
53 import java.util.Arrays;
54 import java.util.HashMap;
55 import java.util.List;
56 import java.util.UUID;
57 import java.util.concurrent.ExecutionException;
58 import javax.annotation.Generated;
59 import org.junit.After;
60 import org.junit.AfterClass;
61 import org.junit.Assert;
62 import org.junit.Before;
63 import org.junit.BeforeClass;
64 import org.junit.Test;
65 
66 @Generated("by gapic-generator-java")
67 public class AppGatewaysServiceClientTest {
68   private static MockAppGatewaysService mockAppGatewaysService;
69   private static MockIAMPolicy mockIAMPolicy;
70   private static MockLocations mockLocations;
71   private static MockServiceHelper mockServiceHelper;
72   private LocalChannelProvider channelProvider;
73   private AppGatewaysServiceClient client;
74 
75   @BeforeClass
startStaticServer()76   public static void startStaticServer() {
77     mockAppGatewaysService = new MockAppGatewaysService();
78     mockLocations = new MockLocations();
79     mockIAMPolicy = new MockIAMPolicy();
80     mockServiceHelper =
81         new MockServiceHelper(
82             UUID.randomUUID().toString(),
83             Arrays.<MockGrpcService>asList(mockAppGatewaysService, mockLocations, mockIAMPolicy));
84     mockServiceHelper.start();
85   }
86 
87   @AfterClass
stopServer()88   public static void stopServer() {
89     mockServiceHelper.stop();
90   }
91 
92   @Before
setUp()93   public void setUp() throws IOException {
94     mockServiceHelper.reset();
95     channelProvider = mockServiceHelper.createChannelProvider();
96     AppGatewaysServiceSettings settings =
97         AppGatewaysServiceSettings.newBuilder()
98             .setTransportChannelProvider(channelProvider)
99             .setCredentialsProvider(NoCredentialsProvider.create())
100             .build();
101     client = AppGatewaysServiceClient.create(settings);
102   }
103 
104   @After
tearDown()105   public void tearDown() throws Exception {
106     client.close();
107   }
108 
109   @Test
listAppGatewaysTest()110   public void listAppGatewaysTest() throws Exception {
111     AppGateway responsesElement = AppGateway.newBuilder().build();
112     ListAppGatewaysResponse expectedResponse =
113         ListAppGatewaysResponse.newBuilder()
114             .setNextPageToken("")
115             .addAllAppGateways(Arrays.asList(responsesElement))
116             .build();
117     mockAppGatewaysService.addResponse(expectedResponse);
118 
119     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
120 
121     ListAppGatewaysPagedResponse pagedListResponse = client.listAppGateways(parent);
122 
123     List<AppGateway> resources = Lists.newArrayList(pagedListResponse.iterateAll());
124 
125     Assert.assertEquals(1, resources.size());
126     Assert.assertEquals(expectedResponse.getAppGatewaysList().get(0), resources.get(0));
127 
128     List<AbstractMessage> actualRequests = mockAppGatewaysService.getRequests();
129     Assert.assertEquals(1, actualRequests.size());
130     ListAppGatewaysRequest actualRequest = ((ListAppGatewaysRequest) actualRequests.get(0));
131 
132     Assert.assertEquals(parent.toString(), actualRequest.getParent());
133     Assert.assertTrue(
134         channelProvider.isHeaderSent(
135             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
136             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
137   }
138 
139   @Test
listAppGatewaysExceptionTest()140   public void listAppGatewaysExceptionTest() throws Exception {
141     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
142     mockAppGatewaysService.addException(exception);
143 
144     try {
145       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
146       client.listAppGateways(parent);
147       Assert.fail("No exception raised");
148     } catch (InvalidArgumentException e) {
149       // Expected exception.
150     }
151   }
152 
153   @Test
listAppGatewaysTest2()154   public void listAppGatewaysTest2() throws Exception {
155     AppGateway responsesElement = AppGateway.newBuilder().build();
156     ListAppGatewaysResponse expectedResponse =
157         ListAppGatewaysResponse.newBuilder()
158             .setNextPageToken("")
159             .addAllAppGateways(Arrays.asList(responsesElement))
160             .build();
161     mockAppGatewaysService.addResponse(expectedResponse);
162 
163     String parent = "parent-995424086";
164 
165     ListAppGatewaysPagedResponse pagedListResponse = client.listAppGateways(parent);
166 
167     List<AppGateway> resources = Lists.newArrayList(pagedListResponse.iterateAll());
168 
169     Assert.assertEquals(1, resources.size());
170     Assert.assertEquals(expectedResponse.getAppGatewaysList().get(0), resources.get(0));
171 
172     List<AbstractMessage> actualRequests = mockAppGatewaysService.getRequests();
173     Assert.assertEquals(1, actualRequests.size());
174     ListAppGatewaysRequest actualRequest = ((ListAppGatewaysRequest) actualRequests.get(0));
175 
176     Assert.assertEquals(parent, actualRequest.getParent());
177     Assert.assertTrue(
178         channelProvider.isHeaderSent(
179             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
180             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
181   }
182 
183   @Test
listAppGatewaysExceptionTest2()184   public void listAppGatewaysExceptionTest2() throws Exception {
185     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
186     mockAppGatewaysService.addException(exception);
187 
188     try {
189       String parent = "parent-995424086";
190       client.listAppGateways(parent);
191       Assert.fail("No exception raised");
192     } catch (InvalidArgumentException e) {
193       // Expected exception.
194     }
195   }
196 
197   @Test
getAppGatewayTest()198   public void getAppGatewayTest() throws Exception {
199     AppGateway expectedResponse =
200         AppGateway.newBuilder()
201             .setName(AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]").toString())
202             .setCreateTime(Timestamp.newBuilder().build())
203             .setUpdateTime(Timestamp.newBuilder().build())
204             .putAllLabels(new HashMap<String, String>())
205             .setDisplayName("displayName1714148973")
206             .setUid("uid115792")
207             .setUri("uri116076")
208             .addAllAllocatedConnections(new ArrayList<AppGateway.AllocatedConnection>())
209             .build();
210     mockAppGatewaysService.addResponse(expectedResponse);
211 
212     AppGatewayName name = AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]");
213 
214     AppGateway actualResponse = client.getAppGateway(name);
215     Assert.assertEquals(expectedResponse, actualResponse);
216 
217     List<AbstractMessage> actualRequests = mockAppGatewaysService.getRequests();
218     Assert.assertEquals(1, actualRequests.size());
219     GetAppGatewayRequest actualRequest = ((GetAppGatewayRequest) actualRequests.get(0));
220 
221     Assert.assertEquals(name.toString(), actualRequest.getName());
222     Assert.assertTrue(
223         channelProvider.isHeaderSent(
224             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
225             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
226   }
227 
228   @Test
getAppGatewayExceptionTest()229   public void getAppGatewayExceptionTest() throws Exception {
230     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
231     mockAppGatewaysService.addException(exception);
232 
233     try {
234       AppGatewayName name = AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]");
235       client.getAppGateway(name);
236       Assert.fail("No exception raised");
237     } catch (InvalidArgumentException e) {
238       // Expected exception.
239     }
240   }
241 
242   @Test
getAppGatewayTest2()243   public void getAppGatewayTest2() throws Exception {
244     AppGateway expectedResponse =
245         AppGateway.newBuilder()
246             .setName(AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]").toString())
247             .setCreateTime(Timestamp.newBuilder().build())
248             .setUpdateTime(Timestamp.newBuilder().build())
249             .putAllLabels(new HashMap<String, String>())
250             .setDisplayName("displayName1714148973")
251             .setUid("uid115792")
252             .setUri("uri116076")
253             .addAllAllocatedConnections(new ArrayList<AppGateway.AllocatedConnection>())
254             .build();
255     mockAppGatewaysService.addResponse(expectedResponse);
256 
257     String name = "name3373707";
258 
259     AppGateway actualResponse = client.getAppGateway(name);
260     Assert.assertEquals(expectedResponse, actualResponse);
261 
262     List<AbstractMessage> actualRequests = mockAppGatewaysService.getRequests();
263     Assert.assertEquals(1, actualRequests.size());
264     GetAppGatewayRequest actualRequest = ((GetAppGatewayRequest) actualRequests.get(0));
265 
266     Assert.assertEquals(name, actualRequest.getName());
267     Assert.assertTrue(
268         channelProvider.isHeaderSent(
269             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
270             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
271   }
272 
273   @Test
getAppGatewayExceptionTest2()274   public void getAppGatewayExceptionTest2() throws Exception {
275     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
276     mockAppGatewaysService.addException(exception);
277 
278     try {
279       String name = "name3373707";
280       client.getAppGateway(name);
281       Assert.fail("No exception raised");
282     } catch (InvalidArgumentException e) {
283       // Expected exception.
284     }
285   }
286 
287   @Test
createAppGatewayTest()288   public void createAppGatewayTest() throws Exception {
289     AppGateway expectedResponse =
290         AppGateway.newBuilder()
291             .setName(AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]").toString())
292             .setCreateTime(Timestamp.newBuilder().build())
293             .setUpdateTime(Timestamp.newBuilder().build())
294             .putAllLabels(new HashMap<String, String>())
295             .setDisplayName("displayName1714148973")
296             .setUid("uid115792")
297             .setUri("uri116076")
298             .addAllAllocatedConnections(new ArrayList<AppGateway.AllocatedConnection>())
299             .build();
300     Operation resultOperation =
301         Operation.newBuilder()
302             .setName("createAppGatewayTest")
303             .setDone(true)
304             .setResponse(Any.pack(expectedResponse))
305             .build();
306     mockAppGatewaysService.addResponse(resultOperation);
307 
308     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
309     AppGateway appGateway = AppGateway.newBuilder().build();
310     String appGatewayId = "appGatewayId355682654";
311 
312     AppGateway actualResponse =
313         client.createAppGatewayAsync(parent, appGateway, appGatewayId).get();
314     Assert.assertEquals(expectedResponse, actualResponse);
315 
316     List<AbstractMessage> actualRequests = mockAppGatewaysService.getRequests();
317     Assert.assertEquals(1, actualRequests.size());
318     CreateAppGatewayRequest actualRequest = ((CreateAppGatewayRequest) actualRequests.get(0));
319 
320     Assert.assertEquals(parent.toString(), actualRequest.getParent());
321     Assert.assertEquals(appGateway, actualRequest.getAppGateway());
322     Assert.assertEquals(appGatewayId, actualRequest.getAppGatewayId());
323     Assert.assertTrue(
324         channelProvider.isHeaderSent(
325             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
326             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
327   }
328 
329   @Test
createAppGatewayExceptionTest()330   public void createAppGatewayExceptionTest() throws Exception {
331     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
332     mockAppGatewaysService.addException(exception);
333 
334     try {
335       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
336       AppGateway appGateway = AppGateway.newBuilder().build();
337       String appGatewayId = "appGatewayId355682654";
338       client.createAppGatewayAsync(parent, appGateway, appGatewayId).get();
339       Assert.fail("No exception raised");
340     } catch (ExecutionException e) {
341       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
342       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
343       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
344     }
345   }
346 
347   @Test
createAppGatewayTest2()348   public void createAppGatewayTest2() throws Exception {
349     AppGateway expectedResponse =
350         AppGateway.newBuilder()
351             .setName(AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]").toString())
352             .setCreateTime(Timestamp.newBuilder().build())
353             .setUpdateTime(Timestamp.newBuilder().build())
354             .putAllLabels(new HashMap<String, String>())
355             .setDisplayName("displayName1714148973")
356             .setUid("uid115792")
357             .setUri("uri116076")
358             .addAllAllocatedConnections(new ArrayList<AppGateway.AllocatedConnection>())
359             .build();
360     Operation resultOperation =
361         Operation.newBuilder()
362             .setName("createAppGatewayTest")
363             .setDone(true)
364             .setResponse(Any.pack(expectedResponse))
365             .build();
366     mockAppGatewaysService.addResponse(resultOperation);
367 
368     String parent = "parent-995424086";
369     AppGateway appGateway = AppGateway.newBuilder().build();
370     String appGatewayId = "appGatewayId355682654";
371 
372     AppGateway actualResponse =
373         client.createAppGatewayAsync(parent, appGateway, appGatewayId).get();
374     Assert.assertEquals(expectedResponse, actualResponse);
375 
376     List<AbstractMessage> actualRequests = mockAppGatewaysService.getRequests();
377     Assert.assertEquals(1, actualRequests.size());
378     CreateAppGatewayRequest actualRequest = ((CreateAppGatewayRequest) actualRequests.get(0));
379 
380     Assert.assertEquals(parent, actualRequest.getParent());
381     Assert.assertEquals(appGateway, actualRequest.getAppGateway());
382     Assert.assertEquals(appGatewayId, actualRequest.getAppGatewayId());
383     Assert.assertTrue(
384         channelProvider.isHeaderSent(
385             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
386             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
387   }
388 
389   @Test
createAppGatewayExceptionTest2()390   public void createAppGatewayExceptionTest2() throws Exception {
391     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
392     mockAppGatewaysService.addException(exception);
393 
394     try {
395       String parent = "parent-995424086";
396       AppGateway appGateway = AppGateway.newBuilder().build();
397       String appGatewayId = "appGatewayId355682654";
398       client.createAppGatewayAsync(parent, appGateway, appGatewayId).get();
399       Assert.fail("No exception raised");
400     } catch (ExecutionException e) {
401       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
402       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
403       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
404     }
405   }
406 
407   @Test
deleteAppGatewayTest()408   public void deleteAppGatewayTest() throws Exception {
409     Empty expectedResponse = Empty.newBuilder().build();
410     Operation resultOperation =
411         Operation.newBuilder()
412             .setName("deleteAppGatewayTest")
413             .setDone(true)
414             .setResponse(Any.pack(expectedResponse))
415             .build();
416     mockAppGatewaysService.addResponse(resultOperation);
417 
418     AppGatewayName name = AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]");
419 
420     client.deleteAppGatewayAsync(name).get();
421 
422     List<AbstractMessage> actualRequests = mockAppGatewaysService.getRequests();
423     Assert.assertEquals(1, actualRequests.size());
424     DeleteAppGatewayRequest actualRequest = ((DeleteAppGatewayRequest) actualRequests.get(0));
425 
426     Assert.assertEquals(name.toString(), actualRequest.getName());
427     Assert.assertTrue(
428         channelProvider.isHeaderSent(
429             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
430             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
431   }
432 
433   @Test
deleteAppGatewayExceptionTest()434   public void deleteAppGatewayExceptionTest() throws Exception {
435     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
436     mockAppGatewaysService.addException(exception);
437 
438     try {
439       AppGatewayName name = AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]");
440       client.deleteAppGatewayAsync(name).get();
441       Assert.fail("No exception raised");
442     } catch (ExecutionException e) {
443       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
444       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
445       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
446     }
447   }
448 
449   @Test
deleteAppGatewayTest2()450   public void deleteAppGatewayTest2() throws Exception {
451     Empty expectedResponse = Empty.newBuilder().build();
452     Operation resultOperation =
453         Operation.newBuilder()
454             .setName("deleteAppGatewayTest")
455             .setDone(true)
456             .setResponse(Any.pack(expectedResponse))
457             .build();
458     mockAppGatewaysService.addResponse(resultOperation);
459 
460     String name = "name3373707";
461 
462     client.deleteAppGatewayAsync(name).get();
463 
464     List<AbstractMessage> actualRequests = mockAppGatewaysService.getRequests();
465     Assert.assertEquals(1, actualRequests.size());
466     DeleteAppGatewayRequest actualRequest = ((DeleteAppGatewayRequest) actualRequests.get(0));
467 
468     Assert.assertEquals(name, actualRequest.getName());
469     Assert.assertTrue(
470         channelProvider.isHeaderSent(
471             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
472             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
473   }
474 
475   @Test
deleteAppGatewayExceptionTest2()476   public void deleteAppGatewayExceptionTest2() throws Exception {
477     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
478     mockAppGatewaysService.addException(exception);
479 
480     try {
481       String name = "name3373707";
482       client.deleteAppGatewayAsync(name).get();
483       Assert.fail("No exception raised");
484     } catch (ExecutionException e) {
485       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
486       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
487       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
488     }
489   }
490 
491   @Test
listLocationsTest()492   public void listLocationsTest() throws Exception {
493     Location responsesElement = Location.newBuilder().build();
494     ListLocationsResponse expectedResponse =
495         ListLocationsResponse.newBuilder()
496             .setNextPageToken("")
497             .addAllLocations(Arrays.asList(responsesElement))
498             .build();
499     mockLocations.addResponse(expectedResponse);
500 
501     ListLocationsRequest request =
502         ListLocationsRequest.newBuilder()
503             .setName("name3373707")
504             .setFilter("filter-1274492040")
505             .setPageSize(883849137)
506             .setPageToken("pageToken873572522")
507             .build();
508 
509     ListLocationsPagedResponse pagedListResponse = client.listLocations(request);
510 
511     List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll());
512 
513     Assert.assertEquals(1, resources.size());
514     Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0));
515 
516     List<AbstractMessage> actualRequests = mockLocations.getRequests();
517     Assert.assertEquals(1, actualRequests.size());
518     ListLocationsRequest actualRequest = ((ListLocationsRequest) actualRequests.get(0));
519 
520     Assert.assertEquals(request.getName(), actualRequest.getName());
521     Assert.assertEquals(request.getFilter(), actualRequest.getFilter());
522     Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
523     Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
524     Assert.assertTrue(
525         channelProvider.isHeaderSent(
526             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
527             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
528   }
529 
530   @Test
listLocationsExceptionTest()531   public void listLocationsExceptionTest() throws Exception {
532     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
533     mockLocations.addException(exception);
534 
535     try {
536       ListLocationsRequest request =
537           ListLocationsRequest.newBuilder()
538               .setName("name3373707")
539               .setFilter("filter-1274492040")
540               .setPageSize(883849137)
541               .setPageToken("pageToken873572522")
542               .build();
543       client.listLocations(request);
544       Assert.fail("No exception raised");
545     } catch (InvalidArgumentException e) {
546       // Expected exception.
547     }
548   }
549 
550   @Test
getLocationTest()551   public void getLocationTest() throws Exception {
552     Location expectedResponse =
553         Location.newBuilder()
554             .setName("name3373707")
555             .setLocationId("locationId1541836720")
556             .setDisplayName("displayName1714148973")
557             .putAllLabels(new HashMap<String, String>())
558             .setMetadata(Any.newBuilder().build())
559             .build();
560     mockLocations.addResponse(expectedResponse);
561 
562     GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
563 
564     Location actualResponse = client.getLocation(request);
565     Assert.assertEquals(expectedResponse, actualResponse);
566 
567     List<AbstractMessage> actualRequests = mockLocations.getRequests();
568     Assert.assertEquals(1, actualRequests.size());
569     GetLocationRequest actualRequest = ((GetLocationRequest) actualRequests.get(0));
570 
571     Assert.assertEquals(request.getName(), actualRequest.getName());
572     Assert.assertTrue(
573         channelProvider.isHeaderSent(
574             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
575             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
576   }
577 
578   @Test
getLocationExceptionTest()579   public void getLocationExceptionTest() throws Exception {
580     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
581     mockLocations.addException(exception);
582 
583     try {
584       GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
585       client.getLocation(request);
586       Assert.fail("No exception raised");
587     } catch (InvalidArgumentException e) {
588       // Expected exception.
589     }
590   }
591 
592   @Test
setIamPolicyTest()593   public void setIamPolicyTest() throws Exception {
594     Policy expectedResponse =
595         Policy.newBuilder()
596             .setVersion(351608024)
597             .addAllBindings(new ArrayList<Binding>())
598             .addAllAuditConfigs(new ArrayList<AuditConfig>())
599             .setEtag(ByteString.EMPTY)
600             .build();
601     mockIAMPolicy.addResponse(expectedResponse);
602 
603     SetIamPolicyRequest request =
604         SetIamPolicyRequest.newBuilder()
605             .setResource(AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]").toString())
606             .setPolicy(Policy.newBuilder().build())
607             .setUpdateMask(FieldMask.newBuilder().build())
608             .build();
609 
610     Policy actualResponse = client.setIamPolicy(request);
611     Assert.assertEquals(expectedResponse, actualResponse);
612 
613     List<AbstractMessage> actualRequests = mockIAMPolicy.getRequests();
614     Assert.assertEquals(1, actualRequests.size());
615     SetIamPolicyRequest actualRequest = ((SetIamPolicyRequest) actualRequests.get(0));
616 
617     Assert.assertEquals(request.getResource(), actualRequest.getResource());
618     Assert.assertEquals(request.getPolicy(), actualRequest.getPolicy());
619     Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask());
620     Assert.assertTrue(
621         channelProvider.isHeaderSent(
622             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
623             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
624   }
625 
626   @Test
setIamPolicyExceptionTest()627   public void setIamPolicyExceptionTest() throws Exception {
628     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
629     mockIAMPolicy.addException(exception);
630 
631     try {
632       SetIamPolicyRequest request =
633           SetIamPolicyRequest.newBuilder()
634               .setResource(AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]").toString())
635               .setPolicy(Policy.newBuilder().build())
636               .setUpdateMask(FieldMask.newBuilder().build())
637               .build();
638       client.setIamPolicy(request);
639       Assert.fail("No exception raised");
640     } catch (InvalidArgumentException e) {
641       // Expected exception.
642     }
643   }
644 
645   @Test
getIamPolicyTest()646   public void getIamPolicyTest() throws Exception {
647     Policy expectedResponse =
648         Policy.newBuilder()
649             .setVersion(351608024)
650             .addAllBindings(new ArrayList<Binding>())
651             .addAllAuditConfigs(new ArrayList<AuditConfig>())
652             .setEtag(ByteString.EMPTY)
653             .build();
654     mockIAMPolicy.addResponse(expectedResponse);
655 
656     GetIamPolicyRequest request =
657         GetIamPolicyRequest.newBuilder()
658             .setResource(AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]").toString())
659             .setOptions(GetPolicyOptions.newBuilder().build())
660             .build();
661 
662     Policy actualResponse = client.getIamPolicy(request);
663     Assert.assertEquals(expectedResponse, actualResponse);
664 
665     List<AbstractMessage> actualRequests = mockIAMPolicy.getRequests();
666     Assert.assertEquals(1, actualRequests.size());
667     GetIamPolicyRequest actualRequest = ((GetIamPolicyRequest) actualRequests.get(0));
668 
669     Assert.assertEquals(request.getResource(), actualRequest.getResource());
670     Assert.assertEquals(request.getOptions(), actualRequest.getOptions());
671     Assert.assertTrue(
672         channelProvider.isHeaderSent(
673             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
674             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
675   }
676 
677   @Test
getIamPolicyExceptionTest()678   public void getIamPolicyExceptionTest() throws Exception {
679     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
680     mockIAMPolicy.addException(exception);
681 
682     try {
683       GetIamPolicyRequest request =
684           GetIamPolicyRequest.newBuilder()
685               .setResource(AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]").toString())
686               .setOptions(GetPolicyOptions.newBuilder().build())
687               .build();
688       client.getIamPolicy(request);
689       Assert.fail("No exception raised");
690     } catch (InvalidArgumentException e) {
691       // Expected exception.
692     }
693   }
694 
695   @Test
testIamPermissionsTest()696   public void testIamPermissionsTest() throws Exception {
697     TestIamPermissionsResponse expectedResponse =
698         TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList<String>()).build();
699     mockIAMPolicy.addResponse(expectedResponse);
700 
701     TestIamPermissionsRequest request =
702         TestIamPermissionsRequest.newBuilder()
703             .setResource(AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]").toString())
704             .addAllPermissions(new ArrayList<String>())
705             .build();
706 
707     TestIamPermissionsResponse actualResponse = client.testIamPermissions(request);
708     Assert.assertEquals(expectedResponse, actualResponse);
709 
710     List<AbstractMessage> actualRequests = mockIAMPolicy.getRequests();
711     Assert.assertEquals(1, actualRequests.size());
712     TestIamPermissionsRequest actualRequest = ((TestIamPermissionsRequest) actualRequests.get(0));
713 
714     Assert.assertEquals(request.getResource(), actualRequest.getResource());
715     Assert.assertEquals(request.getPermissionsList(), actualRequest.getPermissionsList());
716     Assert.assertTrue(
717         channelProvider.isHeaderSent(
718             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
719             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
720   }
721 
722   @Test
testIamPermissionsExceptionTest()723   public void testIamPermissionsExceptionTest() throws Exception {
724     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
725     mockIAMPolicy.addException(exception);
726 
727     try {
728       TestIamPermissionsRequest request =
729           TestIamPermissionsRequest.newBuilder()
730               .setResource(AppGatewayName.of("[PROJECT]", "[LOCATION]", "[APP_GATEWAY]").toString())
731               .addAllPermissions(new ArrayList<String>())
732               .build();
733       client.testIamPermissions(request);
734       Assert.fail("No exception raised");
735     } catch (InvalidArgumentException e) {
736       // Expected exception.
737     }
738   }
739 }
740