• 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.aiplatform.v1beta1;
18 
19 import static com.google.cloud.aiplatform.v1beta1.IndexEndpointServiceClient.ListIndexEndpointsPagedResponse;
20 import static com.google.cloud.aiplatform.v1beta1.IndexEndpointServiceClient.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 IndexEndpointServiceClientTest {
68   private static MockIAMPolicy mockIAMPolicy;
69   private static MockIndexEndpointService mockIndexEndpointService;
70   private static MockLocations mockLocations;
71   private static MockServiceHelper mockServiceHelper;
72   private LocalChannelProvider channelProvider;
73   private IndexEndpointServiceClient client;
74 
75   @BeforeClass
startStaticServer()76   public static void startStaticServer() {
77     mockIndexEndpointService = new MockIndexEndpointService();
78     mockLocations = new MockLocations();
79     mockIAMPolicy = new MockIAMPolicy();
80     mockServiceHelper =
81         new MockServiceHelper(
82             UUID.randomUUID().toString(),
83             Arrays.<MockGrpcService>asList(mockIndexEndpointService, 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     IndexEndpointServiceSettings settings =
97         IndexEndpointServiceSettings.newBuilder()
98             .setTransportChannelProvider(channelProvider)
99             .setCredentialsProvider(NoCredentialsProvider.create())
100             .build();
101     client = IndexEndpointServiceClient.create(settings);
102   }
103 
104   @After
tearDown()105   public void tearDown() throws Exception {
106     client.close();
107   }
108 
109   @Test
createIndexEndpointTest()110   public void createIndexEndpointTest() throws Exception {
111     IndexEndpoint expectedResponse =
112         IndexEndpoint.newBuilder()
113             .setName(IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]").toString())
114             .setDisplayName("displayName1714148973")
115             .setDescription("description-1724546052")
116             .addAllDeployedIndexes(new ArrayList<DeployedIndex>())
117             .setEtag("etag3123477")
118             .putAllLabels(new HashMap<String, String>())
119             .setCreateTime(Timestamp.newBuilder().build())
120             .setUpdateTime(Timestamp.newBuilder().build())
121             .setNetwork("network1843485230")
122             .setEnablePrivateServiceConnect(true)
123             .setPrivateServiceConnectConfig(PrivateServiceConnectConfig.newBuilder().build())
124             .setPublicEndpointEnabled(true)
125             .setPublicEndpointDomainName("publicEndpointDomainName1244171053")
126             .build();
127     Operation resultOperation =
128         Operation.newBuilder()
129             .setName("createIndexEndpointTest")
130             .setDone(true)
131             .setResponse(Any.pack(expectedResponse))
132             .build();
133     mockIndexEndpointService.addResponse(resultOperation);
134 
135     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
136     IndexEndpoint indexEndpoint = IndexEndpoint.newBuilder().build();
137 
138     IndexEndpoint actualResponse = client.createIndexEndpointAsync(parent, indexEndpoint).get();
139     Assert.assertEquals(expectedResponse, actualResponse);
140 
141     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
142     Assert.assertEquals(1, actualRequests.size());
143     CreateIndexEndpointRequest actualRequest = ((CreateIndexEndpointRequest) actualRequests.get(0));
144 
145     Assert.assertEquals(parent.toString(), actualRequest.getParent());
146     Assert.assertEquals(indexEndpoint, actualRequest.getIndexEndpoint());
147     Assert.assertTrue(
148         channelProvider.isHeaderSent(
149             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
150             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
151   }
152 
153   @Test
createIndexEndpointExceptionTest()154   public void createIndexEndpointExceptionTest() throws Exception {
155     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
156     mockIndexEndpointService.addException(exception);
157 
158     try {
159       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
160       IndexEndpoint indexEndpoint = IndexEndpoint.newBuilder().build();
161       client.createIndexEndpointAsync(parent, indexEndpoint).get();
162       Assert.fail("No exception raised");
163     } catch (ExecutionException e) {
164       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
165       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
166       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
167     }
168   }
169 
170   @Test
createIndexEndpointTest2()171   public void createIndexEndpointTest2() throws Exception {
172     IndexEndpoint expectedResponse =
173         IndexEndpoint.newBuilder()
174             .setName(IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]").toString())
175             .setDisplayName("displayName1714148973")
176             .setDescription("description-1724546052")
177             .addAllDeployedIndexes(new ArrayList<DeployedIndex>())
178             .setEtag("etag3123477")
179             .putAllLabels(new HashMap<String, String>())
180             .setCreateTime(Timestamp.newBuilder().build())
181             .setUpdateTime(Timestamp.newBuilder().build())
182             .setNetwork("network1843485230")
183             .setEnablePrivateServiceConnect(true)
184             .setPrivateServiceConnectConfig(PrivateServiceConnectConfig.newBuilder().build())
185             .setPublicEndpointEnabled(true)
186             .setPublicEndpointDomainName("publicEndpointDomainName1244171053")
187             .build();
188     Operation resultOperation =
189         Operation.newBuilder()
190             .setName("createIndexEndpointTest")
191             .setDone(true)
192             .setResponse(Any.pack(expectedResponse))
193             .build();
194     mockIndexEndpointService.addResponse(resultOperation);
195 
196     String parent = "parent-995424086";
197     IndexEndpoint indexEndpoint = IndexEndpoint.newBuilder().build();
198 
199     IndexEndpoint actualResponse = client.createIndexEndpointAsync(parent, indexEndpoint).get();
200     Assert.assertEquals(expectedResponse, actualResponse);
201 
202     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
203     Assert.assertEquals(1, actualRequests.size());
204     CreateIndexEndpointRequest actualRequest = ((CreateIndexEndpointRequest) actualRequests.get(0));
205 
206     Assert.assertEquals(parent, actualRequest.getParent());
207     Assert.assertEquals(indexEndpoint, actualRequest.getIndexEndpoint());
208     Assert.assertTrue(
209         channelProvider.isHeaderSent(
210             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
211             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
212   }
213 
214   @Test
createIndexEndpointExceptionTest2()215   public void createIndexEndpointExceptionTest2() throws Exception {
216     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
217     mockIndexEndpointService.addException(exception);
218 
219     try {
220       String parent = "parent-995424086";
221       IndexEndpoint indexEndpoint = IndexEndpoint.newBuilder().build();
222       client.createIndexEndpointAsync(parent, indexEndpoint).get();
223       Assert.fail("No exception raised");
224     } catch (ExecutionException e) {
225       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
226       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
227       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
228     }
229   }
230 
231   @Test
getIndexEndpointTest()232   public void getIndexEndpointTest() throws Exception {
233     IndexEndpoint expectedResponse =
234         IndexEndpoint.newBuilder()
235             .setName(IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]").toString())
236             .setDisplayName("displayName1714148973")
237             .setDescription("description-1724546052")
238             .addAllDeployedIndexes(new ArrayList<DeployedIndex>())
239             .setEtag("etag3123477")
240             .putAllLabels(new HashMap<String, String>())
241             .setCreateTime(Timestamp.newBuilder().build())
242             .setUpdateTime(Timestamp.newBuilder().build())
243             .setNetwork("network1843485230")
244             .setEnablePrivateServiceConnect(true)
245             .setPrivateServiceConnectConfig(PrivateServiceConnectConfig.newBuilder().build())
246             .setPublicEndpointEnabled(true)
247             .setPublicEndpointDomainName("publicEndpointDomainName1244171053")
248             .build();
249     mockIndexEndpointService.addResponse(expectedResponse);
250 
251     IndexEndpointName name = IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]");
252 
253     IndexEndpoint actualResponse = client.getIndexEndpoint(name);
254     Assert.assertEquals(expectedResponse, actualResponse);
255 
256     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
257     Assert.assertEquals(1, actualRequests.size());
258     GetIndexEndpointRequest actualRequest = ((GetIndexEndpointRequest) actualRequests.get(0));
259 
260     Assert.assertEquals(name.toString(), actualRequest.getName());
261     Assert.assertTrue(
262         channelProvider.isHeaderSent(
263             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
264             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
265   }
266 
267   @Test
getIndexEndpointExceptionTest()268   public void getIndexEndpointExceptionTest() throws Exception {
269     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
270     mockIndexEndpointService.addException(exception);
271 
272     try {
273       IndexEndpointName name = IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]");
274       client.getIndexEndpoint(name);
275       Assert.fail("No exception raised");
276     } catch (InvalidArgumentException e) {
277       // Expected exception.
278     }
279   }
280 
281   @Test
getIndexEndpointTest2()282   public void getIndexEndpointTest2() throws Exception {
283     IndexEndpoint expectedResponse =
284         IndexEndpoint.newBuilder()
285             .setName(IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]").toString())
286             .setDisplayName("displayName1714148973")
287             .setDescription("description-1724546052")
288             .addAllDeployedIndexes(new ArrayList<DeployedIndex>())
289             .setEtag("etag3123477")
290             .putAllLabels(new HashMap<String, String>())
291             .setCreateTime(Timestamp.newBuilder().build())
292             .setUpdateTime(Timestamp.newBuilder().build())
293             .setNetwork("network1843485230")
294             .setEnablePrivateServiceConnect(true)
295             .setPrivateServiceConnectConfig(PrivateServiceConnectConfig.newBuilder().build())
296             .setPublicEndpointEnabled(true)
297             .setPublicEndpointDomainName("publicEndpointDomainName1244171053")
298             .build();
299     mockIndexEndpointService.addResponse(expectedResponse);
300 
301     String name = "name3373707";
302 
303     IndexEndpoint actualResponse = client.getIndexEndpoint(name);
304     Assert.assertEquals(expectedResponse, actualResponse);
305 
306     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
307     Assert.assertEquals(1, actualRequests.size());
308     GetIndexEndpointRequest actualRequest = ((GetIndexEndpointRequest) actualRequests.get(0));
309 
310     Assert.assertEquals(name, actualRequest.getName());
311     Assert.assertTrue(
312         channelProvider.isHeaderSent(
313             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
314             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
315   }
316 
317   @Test
getIndexEndpointExceptionTest2()318   public void getIndexEndpointExceptionTest2() throws Exception {
319     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
320     mockIndexEndpointService.addException(exception);
321 
322     try {
323       String name = "name3373707";
324       client.getIndexEndpoint(name);
325       Assert.fail("No exception raised");
326     } catch (InvalidArgumentException e) {
327       // Expected exception.
328     }
329   }
330 
331   @Test
listIndexEndpointsTest()332   public void listIndexEndpointsTest() throws Exception {
333     IndexEndpoint responsesElement = IndexEndpoint.newBuilder().build();
334     ListIndexEndpointsResponse expectedResponse =
335         ListIndexEndpointsResponse.newBuilder()
336             .setNextPageToken("")
337             .addAllIndexEndpoints(Arrays.asList(responsesElement))
338             .build();
339     mockIndexEndpointService.addResponse(expectedResponse);
340 
341     LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
342 
343     ListIndexEndpointsPagedResponse pagedListResponse = client.listIndexEndpoints(parent);
344 
345     List<IndexEndpoint> resources = Lists.newArrayList(pagedListResponse.iterateAll());
346 
347     Assert.assertEquals(1, resources.size());
348     Assert.assertEquals(expectedResponse.getIndexEndpointsList().get(0), resources.get(0));
349 
350     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
351     Assert.assertEquals(1, actualRequests.size());
352     ListIndexEndpointsRequest actualRequest = ((ListIndexEndpointsRequest) actualRequests.get(0));
353 
354     Assert.assertEquals(parent.toString(), actualRequest.getParent());
355     Assert.assertTrue(
356         channelProvider.isHeaderSent(
357             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
358             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
359   }
360 
361   @Test
listIndexEndpointsExceptionTest()362   public void listIndexEndpointsExceptionTest() throws Exception {
363     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
364     mockIndexEndpointService.addException(exception);
365 
366     try {
367       LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
368       client.listIndexEndpoints(parent);
369       Assert.fail("No exception raised");
370     } catch (InvalidArgumentException e) {
371       // Expected exception.
372     }
373   }
374 
375   @Test
listIndexEndpointsTest2()376   public void listIndexEndpointsTest2() throws Exception {
377     IndexEndpoint responsesElement = IndexEndpoint.newBuilder().build();
378     ListIndexEndpointsResponse expectedResponse =
379         ListIndexEndpointsResponse.newBuilder()
380             .setNextPageToken("")
381             .addAllIndexEndpoints(Arrays.asList(responsesElement))
382             .build();
383     mockIndexEndpointService.addResponse(expectedResponse);
384 
385     String parent = "parent-995424086";
386 
387     ListIndexEndpointsPagedResponse pagedListResponse = client.listIndexEndpoints(parent);
388 
389     List<IndexEndpoint> resources = Lists.newArrayList(pagedListResponse.iterateAll());
390 
391     Assert.assertEquals(1, resources.size());
392     Assert.assertEquals(expectedResponse.getIndexEndpointsList().get(0), resources.get(0));
393 
394     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
395     Assert.assertEquals(1, actualRequests.size());
396     ListIndexEndpointsRequest actualRequest = ((ListIndexEndpointsRequest) actualRequests.get(0));
397 
398     Assert.assertEquals(parent, actualRequest.getParent());
399     Assert.assertTrue(
400         channelProvider.isHeaderSent(
401             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
402             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
403   }
404 
405   @Test
listIndexEndpointsExceptionTest2()406   public void listIndexEndpointsExceptionTest2() throws Exception {
407     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
408     mockIndexEndpointService.addException(exception);
409 
410     try {
411       String parent = "parent-995424086";
412       client.listIndexEndpoints(parent);
413       Assert.fail("No exception raised");
414     } catch (InvalidArgumentException e) {
415       // Expected exception.
416     }
417   }
418 
419   @Test
updateIndexEndpointTest()420   public void updateIndexEndpointTest() throws Exception {
421     IndexEndpoint expectedResponse =
422         IndexEndpoint.newBuilder()
423             .setName(IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]").toString())
424             .setDisplayName("displayName1714148973")
425             .setDescription("description-1724546052")
426             .addAllDeployedIndexes(new ArrayList<DeployedIndex>())
427             .setEtag("etag3123477")
428             .putAllLabels(new HashMap<String, String>())
429             .setCreateTime(Timestamp.newBuilder().build())
430             .setUpdateTime(Timestamp.newBuilder().build())
431             .setNetwork("network1843485230")
432             .setEnablePrivateServiceConnect(true)
433             .setPrivateServiceConnectConfig(PrivateServiceConnectConfig.newBuilder().build())
434             .setPublicEndpointEnabled(true)
435             .setPublicEndpointDomainName("publicEndpointDomainName1244171053")
436             .build();
437     mockIndexEndpointService.addResponse(expectedResponse);
438 
439     IndexEndpoint indexEndpoint = IndexEndpoint.newBuilder().build();
440     FieldMask updateMask = FieldMask.newBuilder().build();
441 
442     IndexEndpoint actualResponse = client.updateIndexEndpoint(indexEndpoint, updateMask);
443     Assert.assertEquals(expectedResponse, actualResponse);
444 
445     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
446     Assert.assertEquals(1, actualRequests.size());
447     UpdateIndexEndpointRequest actualRequest = ((UpdateIndexEndpointRequest) actualRequests.get(0));
448 
449     Assert.assertEquals(indexEndpoint, actualRequest.getIndexEndpoint());
450     Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
451     Assert.assertTrue(
452         channelProvider.isHeaderSent(
453             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
454             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
455   }
456 
457   @Test
updateIndexEndpointExceptionTest()458   public void updateIndexEndpointExceptionTest() throws Exception {
459     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
460     mockIndexEndpointService.addException(exception);
461 
462     try {
463       IndexEndpoint indexEndpoint = IndexEndpoint.newBuilder().build();
464       FieldMask updateMask = FieldMask.newBuilder().build();
465       client.updateIndexEndpoint(indexEndpoint, updateMask);
466       Assert.fail("No exception raised");
467     } catch (InvalidArgumentException e) {
468       // Expected exception.
469     }
470   }
471 
472   @Test
deleteIndexEndpointTest()473   public void deleteIndexEndpointTest() throws Exception {
474     Empty expectedResponse = Empty.newBuilder().build();
475     Operation resultOperation =
476         Operation.newBuilder()
477             .setName("deleteIndexEndpointTest")
478             .setDone(true)
479             .setResponse(Any.pack(expectedResponse))
480             .build();
481     mockIndexEndpointService.addResponse(resultOperation);
482 
483     IndexEndpointName name = IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]");
484 
485     client.deleteIndexEndpointAsync(name).get();
486 
487     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
488     Assert.assertEquals(1, actualRequests.size());
489     DeleteIndexEndpointRequest actualRequest = ((DeleteIndexEndpointRequest) actualRequests.get(0));
490 
491     Assert.assertEquals(name.toString(), actualRequest.getName());
492     Assert.assertTrue(
493         channelProvider.isHeaderSent(
494             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
495             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
496   }
497 
498   @Test
deleteIndexEndpointExceptionTest()499   public void deleteIndexEndpointExceptionTest() throws Exception {
500     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
501     mockIndexEndpointService.addException(exception);
502 
503     try {
504       IndexEndpointName name = IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]");
505       client.deleteIndexEndpointAsync(name).get();
506       Assert.fail("No exception raised");
507     } catch (ExecutionException e) {
508       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
509       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
510       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
511     }
512   }
513 
514   @Test
deleteIndexEndpointTest2()515   public void deleteIndexEndpointTest2() throws Exception {
516     Empty expectedResponse = Empty.newBuilder().build();
517     Operation resultOperation =
518         Operation.newBuilder()
519             .setName("deleteIndexEndpointTest")
520             .setDone(true)
521             .setResponse(Any.pack(expectedResponse))
522             .build();
523     mockIndexEndpointService.addResponse(resultOperation);
524 
525     String name = "name3373707";
526 
527     client.deleteIndexEndpointAsync(name).get();
528 
529     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
530     Assert.assertEquals(1, actualRequests.size());
531     DeleteIndexEndpointRequest actualRequest = ((DeleteIndexEndpointRequest) actualRequests.get(0));
532 
533     Assert.assertEquals(name, actualRequest.getName());
534     Assert.assertTrue(
535         channelProvider.isHeaderSent(
536             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
537             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
538   }
539 
540   @Test
deleteIndexEndpointExceptionTest2()541   public void deleteIndexEndpointExceptionTest2() throws Exception {
542     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
543     mockIndexEndpointService.addException(exception);
544 
545     try {
546       String name = "name3373707";
547       client.deleteIndexEndpointAsync(name).get();
548       Assert.fail("No exception raised");
549     } catch (ExecutionException e) {
550       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
551       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
552       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
553     }
554   }
555 
556   @Test
deployIndexTest()557   public void deployIndexTest() throws Exception {
558     DeployIndexResponse expectedResponse =
559         DeployIndexResponse.newBuilder()
560             .setDeployedIndex(DeployedIndex.newBuilder().build())
561             .build();
562     Operation resultOperation =
563         Operation.newBuilder()
564             .setName("deployIndexTest")
565             .setDone(true)
566             .setResponse(Any.pack(expectedResponse))
567             .build();
568     mockIndexEndpointService.addResponse(resultOperation);
569 
570     IndexEndpointName indexEndpoint =
571         IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]");
572     DeployedIndex deployedIndex = DeployedIndex.newBuilder().build();
573 
574     DeployIndexResponse actualResponse =
575         client.deployIndexAsync(indexEndpoint, deployedIndex).get();
576     Assert.assertEquals(expectedResponse, actualResponse);
577 
578     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
579     Assert.assertEquals(1, actualRequests.size());
580     DeployIndexRequest actualRequest = ((DeployIndexRequest) actualRequests.get(0));
581 
582     Assert.assertEquals(indexEndpoint.toString(), actualRequest.getIndexEndpoint());
583     Assert.assertEquals(deployedIndex, actualRequest.getDeployedIndex());
584     Assert.assertTrue(
585         channelProvider.isHeaderSent(
586             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
587             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
588   }
589 
590   @Test
deployIndexExceptionTest()591   public void deployIndexExceptionTest() throws Exception {
592     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
593     mockIndexEndpointService.addException(exception);
594 
595     try {
596       IndexEndpointName indexEndpoint =
597           IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]");
598       DeployedIndex deployedIndex = DeployedIndex.newBuilder().build();
599       client.deployIndexAsync(indexEndpoint, deployedIndex).get();
600       Assert.fail("No exception raised");
601     } catch (ExecutionException e) {
602       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
603       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
604       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
605     }
606   }
607 
608   @Test
deployIndexTest2()609   public void deployIndexTest2() throws Exception {
610     DeployIndexResponse expectedResponse =
611         DeployIndexResponse.newBuilder()
612             .setDeployedIndex(DeployedIndex.newBuilder().build())
613             .build();
614     Operation resultOperation =
615         Operation.newBuilder()
616             .setName("deployIndexTest")
617             .setDone(true)
618             .setResponse(Any.pack(expectedResponse))
619             .build();
620     mockIndexEndpointService.addResponse(resultOperation);
621 
622     String indexEndpoint = "indexEndpoint-1743275897";
623     DeployedIndex deployedIndex = DeployedIndex.newBuilder().build();
624 
625     DeployIndexResponse actualResponse =
626         client.deployIndexAsync(indexEndpoint, deployedIndex).get();
627     Assert.assertEquals(expectedResponse, actualResponse);
628 
629     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
630     Assert.assertEquals(1, actualRequests.size());
631     DeployIndexRequest actualRequest = ((DeployIndexRequest) actualRequests.get(0));
632 
633     Assert.assertEquals(indexEndpoint, actualRequest.getIndexEndpoint());
634     Assert.assertEquals(deployedIndex, actualRequest.getDeployedIndex());
635     Assert.assertTrue(
636         channelProvider.isHeaderSent(
637             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
638             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
639   }
640 
641   @Test
deployIndexExceptionTest2()642   public void deployIndexExceptionTest2() throws Exception {
643     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
644     mockIndexEndpointService.addException(exception);
645 
646     try {
647       String indexEndpoint = "indexEndpoint-1743275897";
648       DeployedIndex deployedIndex = DeployedIndex.newBuilder().build();
649       client.deployIndexAsync(indexEndpoint, deployedIndex).get();
650       Assert.fail("No exception raised");
651     } catch (ExecutionException e) {
652       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
653       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
654       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
655     }
656   }
657 
658   @Test
undeployIndexTest()659   public void undeployIndexTest() throws Exception {
660     UndeployIndexResponse expectedResponse = UndeployIndexResponse.newBuilder().build();
661     Operation resultOperation =
662         Operation.newBuilder()
663             .setName("undeployIndexTest")
664             .setDone(true)
665             .setResponse(Any.pack(expectedResponse))
666             .build();
667     mockIndexEndpointService.addResponse(resultOperation);
668 
669     IndexEndpointName indexEndpoint =
670         IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]");
671     String deployedIndexId = "deployedIndexId-1101212953";
672 
673     UndeployIndexResponse actualResponse =
674         client.undeployIndexAsync(indexEndpoint, deployedIndexId).get();
675     Assert.assertEquals(expectedResponse, actualResponse);
676 
677     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
678     Assert.assertEquals(1, actualRequests.size());
679     UndeployIndexRequest actualRequest = ((UndeployIndexRequest) actualRequests.get(0));
680 
681     Assert.assertEquals(indexEndpoint.toString(), actualRequest.getIndexEndpoint());
682     Assert.assertEquals(deployedIndexId, actualRequest.getDeployedIndexId());
683     Assert.assertTrue(
684         channelProvider.isHeaderSent(
685             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
686             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
687   }
688 
689   @Test
undeployIndexExceptionTest()690   public void undeployIndexExceptionTest() throws Exception {
691     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
692     mockIndexEndpointService.addException(exception);
693 
694     try {
695       IndexEndpointName indexEndpoint =
696           IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]");
697       String deployedIndexId = "deployedIndexId-1101212953";
698       client.undeployIndexAsync(indexEndpoint, deployedIndexId).get();
699       Assert.fail("No exception raised");
700     } catch (ExecutionException e) {
701       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
702       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
703       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
704     }
705   }
706 
707   @Test
undeployIndexTest2()708   public void undeployIndexTest2() throws Exception {
709     UndeployIndexResponse expectedResponse = UndeployIndexResponse.newBuilder().build();
710     Operation resultOperation =
711         Operation.newBuilder()
712             .setName("undeployIndexTest")
713             .setDone(true)
714             .setResponse(Any.pack(expectedResponse))
715             .build();
716     mockIndexEndpointService.addResponse(resultOperation);
717 
718     String indexEndpoint = "indexEndpoint-1743275897";
719     String deployedIndexId = "deployedIndexId-1101212953";
720 
721     UndeployIndexResponse actualResponse =
722         client.undeployIndexAsync(indexEndpoint, deployedIndexId).get();
723     Assert.assertEquals(expectedResponse, actualResponse);
724 
725     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
726     Assert.assertEquals(1, actualRequests.size());
727     UndeployIndexRequest actualRequest = ((UndeployIndexRequest) actualRequests.get(0));
728 
729     Assert.assertEquals(indexEndpoint, actualRequest.getIndexEndpoint());
730     Assert.assertEquals(deployedIndexId, actualRequest.getDeployedIndexId());
731     Assert.assertTrue(
732         channelProvider.isHeaderSent(
733             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
734             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
735   }
736 
737   @Test
undeployIndexExceptionTest2()738   public void undeployIndexExceptionTest2() throws Exception {
739     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
740     mockIndexEndpointService.addException(exception);
741 
742     try {
743       String indexEndpoint = "indexEndpoint-1743275897";
744       String deployedIndexId = "deployedIndexId-1101212953";
745       client.undeployIndexAsync(indexEndpoint, deployedIndexId).get();
746       Assert.fail("No exception raised");
747     } catch (ExecutionException e) {
748       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
749       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
750       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
751     }
752   }
753 
754   @Test
mutateDeployedIndexTest()755   public void mutateDeployedIndexTest() throws Exception {
756     MutateDeployedIndexResponse expectedResponse =
757         MutateDeployedIndexResponse.newBuilder()
758             .setDeployedIndex(DeployedIndex.newBuilder().build())
759             .build();
760     Operation resultOperation =
761         Operation.newBuilder()
762             .setName("mutateDeployedIndexTest")
763             .setDone(true)
764             .setResponse(Any.pack(expectedResponse))
765             .build();
766     mockIndexEndpointService.addResponse(resultOperation);
767 
768     IndexEndpointName indexEndpoint =
769         IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]");
770     DeployedIndex deployedIndex = DeployedIndex.newBuilder().build();
771 
772     MutateDeployedIndexResponse actualResponse =
773         client.mutateDeployedIndexAsync(indexEndpoint, deployedIndex).get();
774     Assert.assertEquals(expectedResponse, actualResponse);
775 
776     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
777     Assert.assertEquals(1, actualRequests.size());
778     MutateDeployedIndexRequest actualRequest = ((MutateDeployedIndexRequest) actualRequests.get(0));
779 
780     Assert.assertEquals(indexEndpoint.toString(), actualRequest.getIndexEndpoint());
781     Assert.assertEquals(deployedIndex, actualRequest.getDeployedIndex());
782     Assert.assertTrue(
783         channelProvider.isHeaderSent(
784             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
785             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
786   }
787 
788   @Test
mutateDeployedIndexExceptionTest()789   public void mutateDeployedIndexExceptionTest() throws Exception {
790     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
791     mockIndexEndpointService.addException(exception);
792 
793     try {
794       IndexEndpointName indexEndpoint =
795           IndexEndpointName.of("[PROJECT]", "[LOCATION]", "[INDEX_ENDPOINT]");
796       DeployedIndex deployedIndex = DeployedIndex.newBuilder().build();
797       client.mutateDeployedIndexAsync(indexEndpoint, deployedIndex).get();
798       Assert.fail("No exception raised");
799     } catch (ExecutionException e) {
800       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
801       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
802       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
803     }
804   }
805 
806   @Test
mutateDeployedIndexTest2()807   public void mutateDeployedIndexTest2() throws Exception {
808     MutateDeployedIndexResponse expectedResponse =
809         MutateDeployedIndexResponse.newBuilder()
810             .setDeployedIndex(DeployedIndex.newBuilder().build())
811             .build();
812     Operation resultOperation =
813         Operation.newBuilder()
814             .setName("mutateDeployedIndexTest")
815             .setDone(true)
816             .setResponse(Any.pack(expectedResponse))
817             .build();
818     mockIndexEndpointService.addResponse(resultOperation);
819 
820     String indexEndpoint = "indexEndpoint-1743275897";
821     DeployedIndex deployedIndex = DeployedIndex.newBuilder().build();
822 
823     MutateDeployedIndexResponse actualResponse =
824         client.mutateDeployedIndexAsync(indexEndpoint, deployedIndex).get();
825     Assert.assertEquals(expectedResponse, actualResponse);
826 
827     List<AbstractMessage> actualRequests = mockIndexEndpointService.getRequests();
828     Assert.assertEquals(1, actualRequests.size());
829     MutateDeployedIndexRequest actualRequest = ((MutateDeployedIndexRequest) actualRequests.get(0));
830 
831     Assert.assertEquals(indexEndpoint, actualRequest.getIndexEndpoint());
832     Assert.assertEquals(deployedIndex, actualRequest.getDeployedIndex());
833     Assert.assertTrue(
834         channelProvider.isHeaderSent(
835             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
836             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
837   }
838 
839   @Test
mutateDeployedIndexExceptionTest2()840   public void mutateDeployedIndexExceptionTest2() throws Exception {
841     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
842     mockIndexEndpointService.addException(exception);
843 
844     try {
845       String indexEndpoint = "indexEndpoint-1743275897";
846       DeployedIndex deployedIndex = DeployedIndex.newBuilder().build();
847       client.mutateDeployedIndexAsync(indexEndpoint, deployedIndex).get();
848       Assert.fail("No exception raised");
849     } catch (ExecutionException e) {
850       Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
851       InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
852       Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
853     }
854   }
855 
856   @Test
listLocationsTest()857   public void listLocationsTest() throws Exception {
858     Location responsesElement = Location.newBuilder().build();
859     ListLocationsResponse expectedResponse =
860         ListLocationsResponse.newBuilder()
861             .setNextPageToken("")
862             .addAllLocations(Arrays.asList(responsesElement))
863             .build();
864     mockLocations.addResponse(expectedResponse);
865 
866     ListLocationsRequest request =
867         ListLocationsRequest.newBuilder()
868             .setName("name3373707")
869             .setFilter("filter-1274492040")
870             .setPageSize(883849137)
871             .setPageToken("pageToken873572522")
872             .build();
873 
874     ListLocationsPagedResponse pagedListResponse = client.listLocations(request);
875 
876     List<Location> resources = Lists.newArrayList(pagedListResponse.iterateAll());
877 
878     Assert.assertEquals(1, resources.size());
879     Assert.assertEquals(expectedResponse.getLocationsList().get(0), resources.get(0));
880 
881     List<AbstractMessage> actualRequests = mockLocations.getRequests();
882     Assert.assertEquals(1, actualRequests.size());
883     ListLocationsRequest actualRequest = ((ListLocationsRequest) actualRequests.get(0));
884 
885     Assert.assertEquals(request.getName(), actualRequest.getName());
886     Assert.assertEquals(request.getFilter(), actualRequest.getFilter());
887     Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize());
888     Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken());
889     Assert.assertTrue(
890         channelProvider.isHeaderSent(
891             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
892             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
893   }
894 
895   @Test
listLocationsExceptionTest()896   public void listLocationsExceptionTest() throws Exception {
897     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
898     mockLocations.addException(exception);
899 
900     try {
901       ListLocationsRequest request =
902           ListLocationsRequest.newBuilder()
903               .setName("name3373707")
904               .setFilter("filter-1274492040")
905               .setPageSize(883849137)
906               .setPageToken("pageToken873572522")
907               .build();
908       client.listLocations(request);
909       Assert.fail("No exception raised");
910     } catch (InvalidArgumentException e) {
911       // Expected exception.
912     }
913   }
914 
915   @Test
getLocationTest()916   public void getLocationTest() throws Exception {
917     Location expectedResponse =
918         Location.newBuilder()
919             .setName("name3373707")
920             .setLocationId("locationId1541836720")
921             .setDisplayName("displayName1714148973")
922             .putAllLabels(new HashMap<String, String>())
923             .setMetadata(Any.newBuilder().build())
924             .build();
925     mockLocations.addResponse(expectedResponse);
926 
927     GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
928 
929     Location actualResponse = client.getLocation(request);
930     Assert.assertEquals(expectedResponse, actualResponse);
931 
932     List<AbstractMessage> actualRequests = mockLocations.getRequests();
933     Assert.assertEquals(1, actualRequests.size());
934     GetLocationRequest actualRequest = ((GetLocationRequest) actualRequests.get(0));
935 
936     Assert.assertEquals(request.getName(), actualRequest.getName());
937     Assert.assertTrue(
938         channelProvider.isHeaderSent(
939             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
940             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
941   }
942 
943   @Test
getLocationExceptionTest()944   public void getLocationExceptionTest() throws Exception {
945     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
946     mockLocations.addException(exception);
947 
948     try {
949       GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
950       client.getLocation(request);
951       Assert.fail("No exception raised");
952     } catch (InvalidArgumentException e) {
953       // Expected exception.
954     }
955   }
956 
957   @Test
setIamPolicyTest()958   public void setIamPolicyTest() throws Exception {
959     Policy expectedResponse =
960         Policy.newBuilder()
961             .setVersion(351608024)
962             .addAllBindings(new ArrayList<Binding>())
963             .addAllAuditConfigs(new ArrayList<AuditConfig>())
964             .setEtag(ByteString.EMPTY)
965             .build();
966     mockIAMPolicy.addResponse(expectedResponse);
967 
968     SetIamPolicyRequest request =
969         SetIamPolicyRequest.newBuilder()
970             .setResource(
971                 EndpointName.ofProjectLocationEndpointName("[PROJECT]", "[LOCATION]", "[ENDPOINT]")
972                     .toString())
973             .setPolicy(Policy.newBuilder().build())
974             .setUpdateMask(FieldMask.newBuilder().build())
975             .build();
976 
977     Policy actualResponse = client.setIamPolicy(request);
978     Assert.assertEquals(expectedResponse, actualResponse);
979 
980     List<AbstractMessage> actualRequests = mockIAMPolicy.getRequests();
981     Assert.assertEquals(1, actualRequests.size());
982     SetIamPolicyRequest actualRequest = ((SetIamPolicyRequest) actualRequests.get(0));
983 
984     Assert.assertEquals(request.getResource(), actualRequest.getResource());
985     Assert.assertEquals(request.getPolicy(), actualRequest.getPolicy());
986     Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask());
987     Assert.assertTrue(
988         channelProvider.isHeaderSent(
989             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
990             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
991   }
992 
993   @Test
setIamPolicyExceptionTest()994   public void setIamPolicyExceptionTest() throws Exception {
995     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
996     mockIAMPolicy.addException(exception);
997 
998     try {
999       SetIamPolicyRequest request =
1000           SetIamPolicyRequest.newBuilder()
1001               .setResource(
1002                   EndpointName.ofProjectLocationEndpointName(
1003                           "[PROJECT]", "[LOCATION]", "[ENDPOINT]")
1004                       .toString())
1005               .setPolicy(Policy.newBuilder().build())
1006               .setUpdateMask(FieldMask.newBuilder().build())
1007               .build();
1008       client.setIamPolicy(request);
1009       Assert.fail("No exception raised");
1010     } catch (InvalidArgumentException e) {
1011       // Expected exception.
1012     }
1013   }
1014 
1015   @Test
getIamPolicyTest()1016   public void getIamPolicyTest() throws Exception {
1017     Policy expectedResponse =
1018         Policy.newBuilder()
1019             .setVersion(351608024)
1020             .addAllBindings(new ArrayList<Binding>())
1021             .addAllAuditConfigs(new ArrayList<AuditConfig>())
1022             .setEtag(ByteString.EMPTY)
1023             .build();
1024     mockIAMPolicy.addResponse(expectedResponse);
1025 
1026     GetIamPolicyRequest request =
1027         GetIamPolicyRequest.newBuilder()
1028             .setResource(
1029                 EndpointName.ofProjectLocationEndpointName("[PROJECT]", "[LOCATION]", "[ENDPOINT]")
1030                     .toString())
1031             .setOptions(GetPolicyOptions.newBuilder().build())
1032             .build();
1033 
1034     Policy actualResponse = client.getIamPolicy(request);
1035     Assert.assertEquals(expectedResponse, actualResponse);
1036 
1037     List<AbstractMessage> actualRequests = mockIAMPolicy.getRequests();
1038     Assert.assertEquals(1, actualRequests.size());
1039     GetIamPolicyRequest actualRequest = ((GetIamPolicyRequest) actualRequests.get(0));
1040 
1041     Assert.assertEquals(request.getResource(), actualRequest.getResource());
1042     Assert.assertEquals(request.getOptions(), actualRequest.getOptions());
1043     Assert.assertTrue(
1044         channelProvider.isHeaderSent(
1045             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1046             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1047   }
1048 
1049   @Test
getIamPolicyExceptionTest()1050   public void getIamPolicyExceptionTest() throws Exception {
1051     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1052     mockIAMPolicy.addException(exception);
1053 
1054     try {
1055       GetIamPolicyRequest request =
1056           GetIamPolicyRequest.newBuilder()
1057               .setResource(
1058                   EndpointName.ofProjectLocationEndpointName(
1059                           "[PROJECT]", "[LOCATION]", "[ENDPOINT]")
1060                       .toString())
1061               .setOptions(GetPolicyOptions.newBuilder().build())
1062               .build();
1063       client.getIamPolicy(request);
1064       Assert.fail("No exception raised");
1065     } catch (InvalidArgumentException e) {
1066       // Expected exception.
1067     }
1068   }
1069 
1070   @Test
testIamPermissionsTest()1071   public void testIamPermissionsTest() throws Exception {
1072     TestIamPermissionsResponse expectedResponse =
1073         TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList<String>()).build();
1074     mockIAMPolicy.addResponse(expectedResponse);
1075 
1076     TestIamPermissionsRequest request =
1077         TestIamPermissionsRequest.newBuilder()
1078             .setResource(
1079                 EndpointName.ofProjectLocationEndpointName("[PROJECT]", "[LOCATION]", "[ENDPOINT]")
1080                     .toString())
1081             .addAllPermissions(new ArrayList<String>())
1082             .build();
1083 
1084     TestIamPermissionsResponse actualResponse = client.testIamPermissions(request);
1085     Assert.assertEquals(expectedResponse, actualResponse);
1086 
1087     List<AbstractMessage> actualRequests = mockIAMPolicy.getRequests();
1088     Assert.assertEquals(1, actualRequests.size());
1089     TestIamPermissionsRequest actualRequest = ((TestIamPermissionsRequest) actualRequests.get(0));
1090 
1091     Assert.assertEquals(request.getResource(), actualRequest.getResource());
1092     Assert.assertEquals(request.getPermissionsList(), actualRequest.getPermissionsList());
1093     Assert.assertTrue(
1094         channelProvider.isHeaderSent(
1095             ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
1096             GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
1097   }
1098 
1099   @Test
testIamPermissionsExceptionTest()1100   public void testIamPermissionsExceptionTest() throws Exception {
1101     StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
1102     mockIAMPolicy.addException(exception);
1103 
1104     try {
1105       TestIamPermissionsRequest request =
1106           TestIamPermissionsRequest.newBuilder()
1107               .setResource(
1108                   EndpointName.ofProjectLocationEndpointName(
1109                           "[PROJECT]", "[LOCATION]", "[ENDPOINT]")
1110                       .toString())
1111               .addAllPermissions(new ArrayList<String>())
1112               .build();
1113       client.testIamPermissions(request);
1114       Assert.fail("No exception raised");
1115     } catch (InvalidArgumentException e) {
1116       // Expected exception.
1117     }
1118   }
1119 }
1120